Skip to content

Commit 17d46ab

Browse files
[rust bindings] Allow zero-length method disambiguation. (#132)
* Allow zero-length method disambiguation. parse_symbol was failing on a bunch of rust symbols that look like "rust-analyzer cargo test_rust_dependency 0.1.0 MyType#new()." with `Err(InvalidIdentifier("method disambiguator"))`. The problem is that the method descriptor was attempting to use peek to look for the character after the opening "(" to see if it was a ")", but the index had already been incremented, so peek would see the "." closing character instead of the ")". I also have a change in this patch to disable automatic doctests because `cargo test` is failing for me locally without this because it seems to view the inlined protobuf schema as a doctest and reasonably has trouble parsing the schema as valid rust code. I am not able to delve into the general machinery around the "generated" directory at this time, but it seems nice for the tests to pass, so this seems like a reasonable band-aid. --------- Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
1 parent 6c3465b commit 17d46ab

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

bindings/rust/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ pretty_assertions = "1.2.1"
2424
[lib]
2525
name = "scip"
2626
path = "src/mod.rs"
27+
# disable doctests because generated/scip.rs has a perceived doctest.
28+
doctest = false

bindings/rust/src/symbol.rs

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,11 @@ impl SymbolParser {
315315
self.index += 1;
316316
match suffix {
317317
'(' => {
318-
let disambiguator = match self.peek_next() {
319-
Some(c) => match c {
320-
')' => "".to_string(),
321-
_ => self.accept_identifier("method disambiguator")?,
322-
},
323-
None => "".to_string(),
318+
// We are not peeking here because we already advanced
319+
// past suffix.
320+
let disambiguator = match self.current()? {
321+
')' => "".to_string(),
322+
_ => self.accept_identifier("method disambiguator")?,
324323
};
325324

326325
self.accept_character(')', "closing method")?;
@@ -430,4 +429,58 @@ mod test {
430429
format_symbol(parse_symbol(input_symbol).expect("java symbol"))
431430
)
432431
}
432+
433+
#[test]
434+
fn parses_rust_method_no_disambiguator() {
435+
let input_symbol = "rust-analyzer cargo test_rust_dependency 0.1.0 MyType#new().";
436+
437+
assert_eq!(
438+
parse_symbol(input_symbol).expect("rust symbol"),
439+
Symbol {
440+
scheme: "rust-analyzer".to_string(),
441+
package: Package::new_with_values("cargo", "test_rust_dependency", "0.1.0"),
442+
descriptors: vec![
443+
new_descriptor("MyType".to_string(), descriptor::Suffix::Type),
444+
new_descriptor_with_disambiguator(
445+
"new".to_string(),
446+
descriptor::Suffix::Method,
447+
"".to_string(),
448+
),
449+
],
450+
special_fields: SpecialFields::default(),
451+
}
452+
);
453+
454+
assert_eq!(
455+
input_symbol,
456+
format_symbol(parse_symbol(input_symbol).expect("rust symbol"))
457+
)
458+
}
459+
460+
#[test]
461+
fn parses_rust_method_with_disambiguator() {
462+
let input_symbol = "rust-analyzer cargo test_rust_dependency 0.1.0 MyType#new(test).";
463+
464+
assert_eq!(
465+
parse_symbol(input_symbol).expect("rust symbol"),
466+
Symbol {
467+
scheme: "rust-analyzer".to_string(),
468+
package: Package::new_with_values("cargo", "test_rust_dependency", "0.1.0"),
469+
descriptors: vec![
470+
new_descriptor("MyType".to_string(), descriptor::Suffix::Type),
471+
new_descriptor_with_disambiguator(
472+
"new".to_string(),
473+
descriptor::Suffix::Method,
474+
"test".to_string(),
475+
),
476+
],
477+
special_fields: SpecialFields::default(),
478+
}
479+
);
480+
481+
assert_eq!(
482+
input_symbol,
483+
format_symbol(parse_symbol(input_symbol).expect("rust symbol"))
484+
)
485+
}
433486
}

0 commit comments

Comments
 (0)