Skip to content

SCIP: Exclude leading/trailing trivia in definition ranges#22595

Open
Wilfred wants to merge 1 commit into
rust-lang:masterfrom
Wilfred:scip_ranges
Open

SCIP: Exclude leading/trailing trivia in definition ranges#22595
Wilfred wants to merge 1 commit into
rust-lang:masterfrom
Wilfred:scip_ranges

Conversation

@Wilfred

@Wilfred Wilfred commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Previously, the navigation position (which we compute SCIP positions from) would include the full CST node position, including trivia. This generally isn't what we want in SCIP: we just want the definition itself.

This is particularly noticeable when looking at consts:

const FOO_ONE: i32 = 123; // one
const FOO_TWO: i32 = 124; // two

The // one comment was included in the position of FOO_TWO, which is confusing.

I noticed this when working on dead code deletion tools that use SCIP data, because they'd delete the // one comment if FOO_TWO was unused.

Instead, trim trivia from the beginning and end of the range when considering navigation.

AI disclosure: Written with help by Codex and GPT-5.5.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 16, 2026
Previously, the navigation position (which we compute SCIP positions
from) would include the full CST node position, including trivia. This
generally isn't what we want in SCIP: we just want the definition
itself.

This is particularly noticeable when looking at consts:

```
const FOO_ONE: i32 = 123; // one
const FOO_TWO: i32 = 124; // two
```

The `// one` comment was included in the position of `FOO_TWO`, which
is confusing.

I noticed this when working on dead code deletion tools that use SCIP
data, because they'd delete the `// one` comment if `FOO_TWO` was
unused.

Instead, trim trivia from the beginning and end of the range when
considering navigation.

AI disclosure: Written with help by Codex and GPT-5.5.
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

//- /main.rs crate:main deps:core
// we don't use minicore here so that this test doesn't randomly fail
// when someone edits minicore
struct S;

@Wilfred Wilfred Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The hover position for S now no longer includes the comment, which seems correct. The comment doesn't actually relate to S.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants