Skip to content

Commit 4b13843

Browse files
authored
Restore top_level state on exit (#879)
1 parent fa6c7ab commit 4b13843

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

crates/ark/src/lsp/snapshots/ark__lsp__symbols__tests__symbol_nested_assignments.snap

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/ark/src/lsp/symbols.rs
3-
expression: "test_symbol(\"\nlocal({\n inner1 <- 1 # Not a symbol\n})\na <- function() {\n inner2 <- 2 # Not a symbol\n inner3 <- function() 3 # Symbol\n}\n\")"
3+
expression: "test_symbol(\"\nlocal({\n inner1 <- 1 # Not a symbol\n})\na <- function() {\n inner2 <- 2 # Not a symbol\n inner3 <- function() 3 # Symbol\n}\nouter <- 4\n\")"
44
---
55
[
66
DocumentSymbol {
@@ -68,4 +68,34 @@ expression: "test_symbol(\"\nlocal({\n inner1 <- 1 # Not a symbol\n}
6868
],
6969
),
7070
},
71+
DocumentSymbol {
72+
name: "outer",
73+
detail: None,
74+
kind: Variable,
75+
tags: None,
76+
deprecated: None,
77+
range: Range {
78+
start: Position {
79+
line: 8,
80+
character: 0,
81+
},
82+
end: Position {
83+
line: 8,
84+
character: 10,
85+
},
86+
},
87+
selection_range: Range {
88+
start: Position {
89+
line: 8,
90+
character: 0,
91+
},
92+
end: Position {
93+
line: 8,
94+
character: 10,
95+
},
96+
},
97+
children: Some(
98+
[],
99+
),
100+
},
71101
]

crates/ark/src/lsp/snapshots/ark__lsp__symbols__tests__symbol_nested_assignments_enabled.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,34 @@ expression: symbols
128128
],
129129
),
130130
},
131+
DocumentSymbol {
132+
name: "outer",
133+
detail: None,
134+
kind: Variable,
135+
tags: None,
136+
deprecated: None,
137+
range: Range {
138+
start: Position {
139+
line: 8,
140+
character: 0,
141+
},
142+
end: Position {
143+
line: 8,
144+
character: 10,
145+
},
146+
},
147+
selection_range: Range {
148+
start: Position {
149+
line: 8,
150+
character: 0,
151+
},
152+
end: Position {
153+
line: 8,
154+
character: 10,
155+
},
156+
},
157+
children: Some(
158+
[],
159+
),
160+
},
131161
]

crates/ark/src/lsp/symbols.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ fn collect_symbols(
195195
},
196196

197197
NodeType::BracedExpression => {
198+
let old = ctx.top_level;
198199
ctx.top_level = false;
199200
collect_list_sections(ctx, node, contents, current_level, symbols)?;
201+
ctx.top_level = old;
200202
},
201203

202204
NodeType::Call => {
@@ -940,6 +942,7 @@ a <- function() {
940942
inner2 <- 2 # Not a symbol
941943
inner3 <- function() 3 # Symbol
942944
}
945+
outer <- 4
943946
"
944947
));
945948
assert_eq!(test_symbol("{ foo <- 1 }"), vec![]);
@@ -956,6 +959,7 @@ a <- function() {
956959
inner2 <- 2
957960
inner3 <- function() 3
958961
}
962+
outer <- 4
959963
",
960964
None,
961965
);

0 commit comments

Comments
 (0)