Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions bindings/rust/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,15 @@ fn new_descriptor_with_disambiguator(
#[derive(Debug)]
struct SymbolParser {
sym: String,
sym_len: usize,
index: usize,
}

impl SymbolParser {
fn new(sym: &str) -> Self {
Self {
sym: sym.to_string(),
sym_len: sym.chars().count(),
index: 0,
}
}
Expand Down Expand Up @@ -273,8 +275,7 @@ impl SymbolParser {
escape_char: char,
) -> Result<String, SymbolError> {
let mut chars = vec![];
let len = self.sym.len();
while self.index < len {
while self.index < self.sym_len {
let ch = self.current()?;
if ch == escape_char {
self.index += 1;
Expand Down Expand Up @@ -345,7 +346,7 @@ impl SymbolParser {

fn accept_descriptors(&mut self) -> Result<Vec<Descriptor>, SymbolError> {
let mut v = Vec::new();
while self.index < self.sym.len() {
while self.index < self.sym_len {
v.push(self.accept_one_descriptor()?)
}

Expand Down Expand Up @@ -374,7 +375,7 @@ impl SymbolParser {
}
_ => {
let name = self.accept_identifier(
format!("descriptor name: {:?} / {}", self, self.sym.len()).as_str(),
format!("descriptor name: {:?} / {}", self, self.sym_len).as_str(),
)?;

let suffix = self.current()?;
Expand Down Expand Up @@ -639,4 +640,20 @@ mod test {
assert!(parse_symbol(test_case).is_err());
}
}

#[test]
fn parses_non_ascii() {
assert_eq!(
parse_symbol("rust-analyzer cargo files 0.1.0 `Α`#").expect("to parse local"),
Symbol {
scheme: "rust-analyzer".to_string(),
package: Package::new_with_values("cargo", "files", "0.1.0"),
descriptors: vec![new_descriptor(
"Α".to_string(),
descriptor::Suffix::Type
),],
special_fields: SpecialFields::default(),
}
);
}
}