Skip to content

Commit

Permalink
Merge pull request #18312 from LastExceed/symbolkind-variable
Browse files Browse the repository at this point in the history
Report document symbols of kind `variable` for let statements
  • Loading branch information
Veykril authored Oct 28, 2024
2 parents 80e9d01 + 167fe5f commit 68e2d84
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions crates/ide/src/file_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
};
Some(node)
},
ast::LetStmt(it) => {
let pat = it.pat()?;

let mut label = String::new();
collapse_ws(pat.syntax(), &mut label);

let node = StructureNode {
parent: None,
label,
navigation_range: pat.syntax().text_range(),
node_range: it.syntax().text_range(),
kind: StructureNodeKind::SymbolKind(SymbolKind::Local),
detail: it.ty().map(|ty| ty.to_string()),
deprecated: false,
};

Some(node)
},
ast::Macro(it) => decl(it, StructureNodeKind::SymbolKind(SymbolKind::Macro)),
_ => None,
}
Expand Down Expand Up @@ -308,6 +326,17 @@ fn f() {}
// endregion
fn g() {}
}
fn let_statements() {
let x = 42;
let mut y = x;
let Foo {
..
} = Foo { x };
if let None = Some(x) {}
_ = ();
let _ = g();
}
"#,
expect![[r#"
[
Expand Down Expand Up @@ -633,6 +662,71 @@ fn g() {}
),
deprecated: false,
},
StructureNode {
parent: None,
label: "let_statements",
navigation_range: 641..655,
node_range: 638..798,
kind: SymbolKind(
Function,
),
detail: Some(
"fn()",
),
deprecated: false,
},
StructureNode {
parent: Some(
26,
),
label: "x",
navigation_range: 668..669,
node_range: 664..675,
kind: SymbolKind(
Local,
),
detail: None,
deprecated: false,
},
StructureNode {
parent: Some(
26,
),
label: "mut y",
navigation_range: 684..689,
node_range: 680..694,
kind: SymbolKind(
Local,
),
detail: None,
deprecated: false,
},
StructureNode {
parent: Some(
26,
),
label: "Foo { .. }",
navigation_range: 703..725,
node_range: 699..738,
kind: SymbolKind(
Local,
),
detail: None,
deprecated: false,
},
StructureNode {
parent: Some(
26,
),
label: "_",
navigation_range: 788..789,
node_range: 784..796,
kind: SymbolKind(
Local,
),
detail: None,
deprecated: false,
},
]
"#]],
);
Expand Down

0 comments on commit 68e2d84

Please sign in to comment.