Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 8 additions & 14 deletions crates/ide/src/static_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ide_db::{
documentation::Documentation,
famous_defs::FamousDefs,
};
use syntax::{AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, T, TextRange};
use syntax::{AstNode, SyntaxNode, SyntaxToken, TextRange};

use crate::navigation_target::UpmappingResult;
use crate::{
Expand Down Expand Up @@ -136,12 +136,12 @@ fn documentation_for_definition(
}

// FIXME: This is a weird function
fn get_definitions(
sema: &Semantics<'_, RootDatabase>,
fn get_definitions<'db>(
sema: &Semantics<'db, RootDatabase>,
token: SyntaxToken,
) -> Option<ArrayVec<Definition, 2>> {
) -> Option<ArrayVec<(Definition, Option<hir::GenericSubstitution<'db>>), 2>> {
for token in sema.descend_into_macros_exact(token) {
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions);
if let Some(defs) = def
&& !defs.is_empty()
{
Expand Down Expand Up @@ -225,12 +225,6 @@ impl StaticIndex<'_> {
show_drop_glue: true,
minicore: MiniCore::default(),
};
let tokens = tokens.filter(|token| {
matches!(
token.kind(),
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] | T![Self]
)
});
Comment on lines -228 to -233
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I removed the SyntaxKind-based filtering here because I didn't want to explicitly list all overloadable operators and get_definitions already filters out tokens that don't map to a definition, but I can add it back (with a proper SyntaxKind::is_overloadable_operator) if that's an issue.

let mut result = StaticIndexedFile { file_id, inlay_hints, folds, tokens: vec![] };

let mut add_token = |def: Definition, range: TextRange, scope_node: &SyntaxNode| {
Expand Down Expand Up @@ -290,9 +284,9 @@ impl StaticIndex<'_> {
let range = token.text_range();
let node = token.parent().unwrap();
match hir::attach_db(self.db, || get_definitions(&sema, token.clone())) {
Some(it) => {
for i in it {
add_token(i, range, &node);
Some(defs) => {
for (def, _) in defs {
add_token(def, range, &node);
}
}
None => continue,
Expand Down
23 changes: 23 additions & 0 deletions crates/rust-analyzer/src/cli/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,29 @@ pub mod example_mod {
);
}

#[test]
fn operator_overload() {
check_symbol(
r#"
//- minicore: add
//- /workspace/lib.rs crate:main
use core::ops::AddAssign;

struct S;

impl AddAssign for S {
fn add_assign(&mut self, _rhs: Self) {}
}

fn main() {
let mut s = S;
s +=$0 S;
}
"#,
"rust-analyzer cargo main . impl#[S][`AddAssign<Self>`]add_assign().",
);
}

#[test]
fn symbol_for_trait() {
check_symbol(
Expand Down