Skip to content

Commit 120be9b

Browse files
Merge pull request #21187 from nicolas-guichard/push-orysqtulnxww
Include operator overload occurrences in SCIP index
2 parents 533fac5 + 4e1e17e commit 120be9b

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/tools/rust-analyzer/crates/ide/src/static_index.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ide_db::{
1010
documentation::Documentation,
1111
famous_defs::FamousDefs,
1212
};
13-
use syntax::{AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, T, TextRange};
13+
use syntax::{AstNode, SyntaxNode, SyntaxToken, TextRange};
1414

1515
use crate::navigation_target::UpmappingResult;
1616
use crate::{
@@ -136,12 +136,12 @@ fn documentation_for_definition(
136136
}
137137

138138
// FIXME: This is a weird function
139-
fn get_definitions(
140-
sema: &Semantics<'_, RootDatabase>,
139+
fn get_definitions<'db>(
140+
sema: &Semantics<'db, RootDatabase>,
141141
token: SyntaxToken,
142-
) -> Option<ArrayVec<Definition, 2>> {
142+
) -> Option<ArrayVec<(Definition, Option<hir::GenericSubstitution<'db>>), 2>> {
143143
for token in sema.descend_into_macros_exact(token) {
144-
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
144+
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions);
145145
if let Some(defs) = def
146146
&& !defs.is_empty()
147147
{
@@ -226,12 +226,6 @@ impl StaticIndex<'_> {
226226
show_drop_glue: true,
227227
minicore: MiniCore::default(),
228228
};
229-
let tokens = tokens.filter(|token| {
230-
matches!(
231-
token.kind(),
232-
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] | T![Self]
233-
)
234-
});
235229
let mut result = StaticIndexedFile { file_id, inlay_hints, folds, tokens: vec![] };
236230

237231
let mut add_token = |def: Definition, range: TextRange, scope_node: &SyntaxNode| {
@@ -291,9 +285,9 @@ impl StaticIndex<'_> {
291285
let range = token.text_range();
292286
let node = token.parent().unwrap();
293287
match hir::attach_db(self.db, || get_definitions(&sema, token.clone())) {
294-
Some(it) => {
295-
for i in it {
296-
add_token(i, range, &node);
288+
Some(defs) => {
289+
for (def, _) in defs {
290+
add_token(def, range, &node);
297291
}
298292
}
299293
None => continue,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,29 @@ pub mod example_mod {
603603
);
604604
}
605605

606+
#[test]
607+
fn operator_overload() {
608+
check_symbol(
609+
r#"
610+
//- minicore: add
611+
//- /workspace/lib.rs crate:main
612+
use core::ops::AddAssign;
613+
614+
struct S;
615+
616+
impl AddAssign for S {
617+
fn add_assign(&mut self, _rhs: Self) {}
618+
}
619+
620+
fn main() {
621+
let mut s = S;
622+
s +=$0 S;
623+
}
624+
"#,
625+
"rust-analyzer cargo main . impl#[S][`AddAssign<Self>`]add_assign().",
626+
);
627+
}
628+
606629
#[test]
607630
fn symbol_for_trait() {
608631
check_symbol(

0 commit comments

Comments
 (0)