Skip to content

Commit 04b6bd2

Browse files
authored
Recurse into special constructs to find document symbols (#892)
* Add tests for sections in bare braces * Recurse into special constructs * Remove dangling `current_level` logic
1 parent 455152a commit 04b6bd2

8 files changed

+1191
-66
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
source: crates/ark/src/lsp/symbols.rs
3+
expression: "test_symbol(\"\n for (i in 1:10) {\n # section in for ----\n x <- i\n }\n \")"
4+
---
5+
[
6+
DocumentSymbol {
7+
name: "section in for",
8+
detail: None,
9+
kind: String,
10+
tags: None,
11+
deprecated: None,
12+
range: Range {
13+
start: Position {
14+
line: 2,
15+
character: 14,
16+
},
17+
end: Position {
18+
line: 3,
19+
character: 20,
20+
},
21+
},
22+
selection_range: Range {
23+
start: Position {
24+
line: 2,
25+
character: 14,
26+
},
27+
end: Position {
28+
line: 3,
29+
character: 20,
30+
},
31+
},
32+
children: Some(
33+
[
34+
DocumentSymbol {
35+
name: "x",
36+
detail: None,
37+
kind: Variable,
38+
tags: None,
39+
deprecated: None,
40+
range: Range {
41+
start: Position {
42+
line: 3,
43+
character: 14,
44+
},
45+
end: Position {
46+
line: 3,
47+
character: 20,
48+
},
49+
},
50+
selection_range: Range {
51+
start: Position {
52+
line: 3,
53+
character: 14,
54+
},
55+
end: Position {
56+
line: 3,
57+
character: 20,
58+
},
59+
},
60+
children: Some(
61+
[],
62+
),
63+
},
64+
],
65+
),
66+
},
67+
]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
source: crates/ark/src/lsp/symbols.rs
3+
expression: "test_symbol(\"\nfunction(\n X,\n # Section in parameters ----\n y\n) {\n # Section in body ----\n x <- 1\n}\n\")"
4+
---
5+
[
6+
DocumentSymbol {
7+
name: "Section in parameters",
8+
detail: None,
9+
kind: String,
10+
tags: None,
11+
deprecated: None,
12+
range: Range {
13+
start: Position {
14+
line: 3,
15+
character: 2,
16+
},
17+
end: Position {
18+
line: 4,
19+
character: 3,
20+
},
21+
},
22+
selection_range: Range {
23+
start: Position {
24+
line: 3,
25+
character: 2,
26+
},
27+
end: Position {
28+
line: 4,
29+
character: 3,
30+
},
31+
},
32+
children: Some(
33+
[],
34+
),
35+
},
36+
DocumentSymbol {
37+
name: "Section in body",
38+
detail: None,
39+
kind: String,
40+
tags: None,
41+
deprecated: None,
42+
range: Range {
43+
start: Position {
44+
line: 6,
45+
character: 2,
46+
},
47+
end: Position {
48+
line: 7,
49+
character: 8,
50+
},
51+
},
52+
selection_range: Range {
53+
start: Position {
54+
line: 6,
55+
character: 2,
56+
},
57+
end: Position {
58+
line: 7,
59+
character: 8,
60+
},
61+
},
62+
children: Some(
63+
[],
64+
),
65+
},
66+
]
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
source: crates/ark/src/lsp/symbols.rs
3+
expression: "test_symbol(\"\n if (TRUE) {\n # section in if ----\n x <- 1\n } else {\n # section in else ----\n y <- 2\n }\n \")"
4+
---
5+
[
6+
DocumentSymbol {
7+
name: "section in if",
8+
detail: None,
9+
kind: String,
10+
tags: None,
11+
deprecated: None,
12+
range: Range {
13+
start: Position {
14+
line: 2,
15+
character: 14,
16+
},
17+
end: Position {
18+
line: 3,
19+
character: 20,
20+
},
21+
},
22+
selection_range: Range {
23+
start: Position {
24+
line: 2,
25+
character: 14,
26+
},
27+
end: Position {
28+
line: 3,
29+
character: 20,
30+
},
31+
},
32+
children: Some(
33+
[
34+
DocumentSymbol {
35+
name: "x",
36+
detail: None,
37+
kind: Variable,
38+
tags: None,
39+
deprecated: None,
40+
range: Range {
41+
start: Position {
42+
line: 3,
43+
character: 14,
44+
},
45+
end: Position {
46+
line: 3,
47+
character: 20,
48+
},
49+
},
50+
selection_range: Range {
51+
start: Position {
52+
line: 3,
53+
character: 14,
54+
},
55+
end: Position {
56+
line: 3,
57+
character: 20,
58+
},
59+
},
60+
children: Some(
61+
[],
62+
),
63+
},
64+
],
65+
),
66+
},
67+
DocumentSymbol {
68+
name: "section in else",
69+
detail: None,
70+
kind: String,
71+
tags: None,
72+
deprecated: None,
73+
range: Range {
74+
start: Position {
75+
line: 5,
76+
character: 14,
77+
},
78+
end: Position {
79+
line: 6,
80+
character: 20,
81+
},
82+
},
83+
selection_range: Range {
84+
start: Position {
85+
line: 5,
86+
character: 14,
87+
},
88+
end: Position {
89+
line: 6,
90+
character: 20,
91+
},
92+
},
93+
children: Some(
94+
[
95+
DocumentSymbol {
96+
name: "y",
97+
detail: None,
98+
kind: Variable,
99+
tags: None,
100+
deprecated: None,
101+
range: Range {
102+
start: Position {
103+
line: 6,
104+
character: 14,
105+
},
106+
end: Position {
107+
line: 6,
108+
character: 20,
109+
},
110+
},
111+
selection_range: Range {
112+
start: Position {
113+
line: 6,
114+
character: 14,
115+
},
116+
end: Position {
117+
line: 6,
118+
character: 20,
119+
},
120+
},
121+
children: Some(
122+
[],
123+
),
124+
},
125+
],
126+
),
127+
},
128+
]

0 commit comments

Comments
 (0)