Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scip output doesn't include implicit field references during struct initialization #19393

Closed
jrmuizel opened this issue Mar 18, 2025 · 1 comment · Fixed by #19515
Closed
Labels
A-lsif/scip LSIF/SCIP conformance and features C-bug Category: bug

Comments

@jrmuizel
Copy link
Contributor

rust-analyzer version: rust-analyzer 1.85.0 (4d91de4e 2025-02-17)

code snippet to reproduce:

struct Point {
    x: f64,
    y: f64,
}

fn main() {
    let x = 5.;
    let y = 10.;


    let mut p = Point {x, y };


    p.x = 9.;
    p.y = 10.;
    println!("Hello, world! {} {}", p.x, p.y);  
}

scip print index.scip gives:

        &scip.Occurrence{
          Range: []int32{
            10,
            12,
            13,
          },
          Symbol:                "local 3",
          SymbolRoles:           1,
          OverrideDocumentation: []string(nil),
          SyntaxKind:            0,
          Diagnostics:           []*scip.Diagnostic(nil),
          EnclosingRange:        []int32(nil),
        },
        &scip.Occurrence{
          Range: []int32{
            10,
            16,
            21,
          },
          Symbol:                "rust-analyzer cargo ra-test 0.1.0 Point#",
          SymbolRoles:           0,
          OverrideDocumentation: []string(nil),
          SyntaxKind:            0,
          Diagnostics:           []*scip.Diagnostic(nil),
          EnclosingRange:        []int32(nil),
        },

for the line let mut p = Point {x, y };

We should include field references for Point#x and Point#y like is done if it was Point{x:x, y:y}

@jrmuizel jrmuizel added the C-bug Category: bug label Mar 18, 2025
@Veykril Veykril added the A-lsif/scip LSIF/SCIP conformance and features label Mar 19, 2025
@jrmuizel
Copy link
Contributor Author

jrmuizel commented Apr 1, 2025

Seems like the bug is around here:

// FIXME: This is a weird function
pub fn get_definition(
    sema: &Semantics<'_, RootDatabase>,
    token: SyntaxToken,
) -> Option<Definition> {
    for token in sema.descend_into_macros_exact(token) {
        let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
        if let Some(&[x]) = def.as_deref() {
            return Some(x);
        }
    }
    None
}

jrmuizel added a commit to jrmuizel/rust-analyzer that referenced this issue Apr 4, 2025
Implicit field references during struct initialization were
being dropped because get_definition was returning None because
there were multiple definitions.

This adds a new helper, `get_defintions`, that supports returning
more than one definition for a given token and hooks it up.

Fixes rust-lang#19393
jrmuizel added a commit to jrmuizel/rust-analyzer that referenced this issue Apr 4, 2025
Implicit field references during struct initialization were
being dropped because get_definition was returning None because
there were multiple definitions.

This adds a new helper, `get_defintions`, that supports returning
more than one definition for a given token and hooks it up.

Fixes rust-lang#19393
jrmuizel added a commit to jrmuizel/rust-analyzer that referenced this issue Apr 4, 2025
Implicit field references during struct initialization were
being dropped because get_definition was returning None because
there were multiple definitions.

This adds a new helper, `get_defintions`, that supports returning
more than one definition for a given token and hooks it up.

Fixes rust-lang#19393
jrmuizel added a commit to jrmuizel/rust-analyzer that referenced this issue Apr 4, 2025
Implicit field references during struct initialization were
being dropped because get_definition was returning None because
there were multiple definitions.

This adds a new helper, `get_defintions`, that supports returning
more than one definition for a given token and hooks it up.

Fixes rust-lang#19393
jrmuizel added a commit to jrmuizel/rust-analyzer that referenced this issue Apr 4, 2025
Implicit field references during struct initialization were
being dropped because get_definition was returning None because
there were multiple definitions.

This adds a new helper, `get_defintions`, that supports returning
more than one definition for a given token and hooks it up.

Fixes rust-lang#19393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lsif/scip LSIF/SCIP conformance and features C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants