Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 62663e6

Browse files
scip: Refactor token_to_symbol to moniker_to_symbol
This is meant to implement SymbolInformation::enclosing_symbol, so we can build the enclosing symbol from the enclosing moniker without having the full enclosing token's TokenStaticData.
1 parent 375f1cc commit 62663e6

File tree

1 file changed

+11
-13
lines changed
  • crates/rust-analyzer/src/cli

1 file changed

+11
-13
lines changed

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::{
77
};
88

99
use ide::{
10-
LineCol, MonikerDescriptorKind, StaticIndex, StaticIndexedFile, TextRange, TokenId,
11-
TokenStaticData,
10+
LineCol, MonikerDescriptorKind, MonikerResult, StaticIndex, StaticIndexedFile, TextRange,
11+
TokenId,
1212
};
1313
use ide_db::LineIndexDatabase;
1414
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
@@ -109,7 +109,11 @@ impl flags::Scip {
109109
let symbol = tokens_to_symbol
110110
.entry(id)
111111
.or_insert_with(|| {
112-
let symbol = token_to_symbol(token).unwrap_or_else(&mut new_local_symbol);
112+
let symbol = token
113+
.moniker
114+
.as_ref()
115+
.map(moniker_to_symbol)
116+
.unwrap_or_else(&mut new_local_symbol);
113117
scip::symbol::format_symbol(symbol)
114118
})
115119
.clone();
@@ -228,15 +232,9 @@ fn new_descriptor(name: &str, suffix: scip_types::descriptor::Suffix) -> scip_ty
228232
}
229233
}
230234

231-
/// Loosely based on `def_to_moniker`
232-
///
233-
/// Only returns a Symbol when it's a non-local symbol.
234-
/// So if the visibility isn't outside of a document, then it will return None
235-
fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
235+
fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
236236
use scip_types::descriptor::Suffix::*;
237237

238-
let moniker = token.moniker.as_ref()?;
239-
240238
let package_name = moniker.package_information.name.clone();
241239
let version = moniker.package_information.version.clone();
242240
let descriptors = moniker
@@ -260,7 +258,7 @@ fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
260258
})
261259
.collect();
262260

263-
Some(scip_types::Symbol {
261+
scip_types::Symbol {
264262
scheme: "rust-analyzer".into(),
265263
package: Some(scip_types::Package {
266264
manager: "cargo".to_string(),
@@ -271,7 +269,7 @@ fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
271269
.into(),
272270
descriptors,
273271
special_fields: Default::default(),
274-
})
272+
}
275273
}
276274

277275
#[cfg(test)]
@@ -309,7 +307,7 @@ mod test {
309307
for &(range, id) in &file.tokens {
310308
if range.contains(offset - TextSize::from(1)) {
311309
let token = si.tokens.get(id).unwrap();
312-
found_symbol = token_to_symbol(token);
310+
found_symbol = token.moniker.as_ref().map(moniker_to_symbol);
313311
break;
314312
}
315313
}

0 commit comments

Comments
 (0)