about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-29 07:44:29 +0000
committerbors <bors@rust-lang.org>2024-08-29 07:44:29 +0000
commite0625d5c0837e3abbb191dff9ed6ef948575884b (patch)
treeea7b151cef9fc8739bc951ca87049433ca8ad588
parentb195ff3ac06092ff659c64aa07695760706b76f0 (diff)
parentc2c1bd0c137cf50e578d8749142c21eaf0946f3d (diff)
downloadrust-e0625d5c0837e3abbb191dff9ed6ef948575884b.tar.gz
rust-e0625d5c0837e3abbb191dff9ed6ef948575884b.zip
Auto merge of #17988 - darichey:fix-scip-def, r=Veykril
Fix incorrect symbol definitions in SCIP output

The SCIP output incorrectly marks some symbols as definitions because it doesn't account for the file ID when comparing the token's range to its definition's range.

This means that if a symbol is referenced in a file at the same position at which it is defined in another file, that reference will be marked as a definition. I was quite surprised by how common this is. For example, `PartialEq` is defined [here](https://github.com/rust-lang/rust/blob/1.80.1/library/core/src/cmp.rs#L273) and `uuid` references it [here](https://github.com/uuid-rs/uuid/blob/1.8.0/src/lib.rs#L329). And what do you know, they're both at offset 10083! In our large monorepo, this happens for basically every common stdlib type!
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs
index a8a02712fe2..ceb8534fdf5 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs
@@ -142,7 +142,9 @@ impl flags::Scip {
                 let mut symbol_roles = Default::default();
 
                 if let Some(def) = token.definition {
-                    if def.range == text_range {
+                    // if the the range of the def and the range of the token are the same, this must be the definition.
+                    // they also must be in the same file. See https://github.com/rust-lang/rust-analyzer/pull/17988
+                    if def.file_id == file_id && def.range == text_range {
                         symbol_roles |= scip_types::SymbolRole::Definition as i32;
                     }