Skip to content

Commit 0f3d5a8

Browse files
authored
Merge pull request #858 from posit-dev/feature/method-symbols
Emit functions passed as named arguments as document symbols
2 parents 3c6437a + 323baa2 commit 0f3d5a8

7 files changed

+834
-19
lines changed

.github/copilot-instructions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ _below_ the calling function. A general goal is to be able to read linearly from
1919
top to bottom with the relevant context and main logic first. The code should be
2020
organised like a call stack. Of course that's not always possible, use best
2121
judgement to produce the clearest code organization.
22+
23+
Keep the main logic as unnested as possible. Favour Rust's `let ... else`
24+
syntax to return early or continue a loop in the `else` clause, over `if let`.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
source: crates/ark/src/lsp/symbols.rs
3+
expression: "test_symbol(\"\n# section ----\nlocal({\n a <- function() {\n 1\n }\n})\n\")"
4+
---
5+
[
6+
DocumentSymbol {
7+
name: "section",
8+
detail: None,
9+
kind: String,
10+
tags: None,
11+
deprecated: None,
12+
range: Range {
13+
start: Position {
14+
line: 1,
15+
character: 0,
16+
},
17+
end: Position {
18+
line: 6,
19+
character: 2,
20+
},
21+
},
22+
selection_range: Range {
23+
start: Position {
24+
line: 1,
25+
character: 0,
26+
},
27+
end: Position {
28+
line: 6,
29+
character: 2,
30+
},
31+
},
32+
children: Some(
33+
[
34+
DocumentSymbol {
35+
name: "a",
36+
detail: Some(
37+
"function()",
38+
),
39+
kind: Function,
40+
tags: None,
41+
deprecated: None,
42+
range: Range {
43+
start: Position {
44+
line: 3,
45+
character: 4,
46+
},
47+
end: Position {
48+
line: 5,
49+
character: 5,
50+
},
51+
},
52+
selection_range: Range {
53+
start: Position {
54+
line: 3,
55+
character: 4,
56+
},
57+
end: Position {
58+
line: 5,
59+
character: 5,
60+
},
61+
},
62+
children: Some(
63+
[],
64+
),
65+
},
66+
],
67+
),
68+
},
69+
]
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
---
2+
source: crates/ark/src/lsp/symbols.rs
3+
expression: "test_symbol(\"\n# section ----\nlist(\n foo = function() {\n 1\n # nested section ----\n nested <- function() {}\n }, # matched\n function() {\n 2\n # `nested` is a symbol even if the unnamed method is not\n nested <- function () {\n }\n }, # not matched\n bar = function() {\n 3\n }, # matched\n baz = (function() {\n 4\n }) # not matched\n)\n\")"
4+
---
5+
[
6+
DocumentSymbol {
7+
name: "section",
8+
detail: None,
9+
kind: String,
10+
tags: None,
11+
deprecated: None,
12+
range: Range {
13+
start: Position {
14+
line: 1,
15+
character: 0,
16+
},
17+
end: Position {
18+
line: 20,
19+
character: 1,
20+
},
21+
},
22+
selection_range: Range {
23+
start: Position {
24+
line: 1,
25+
character: 0,
26+
},
27+
end: Position {
28+
line: 20,
29+
character: 1,
30+
},
31+
},
32+
children: Some(
33+
[
34+
DocumentSymbol {
35+
name: "foo",
36+
detail: Some(
37+
"function()",
38+
),
39+
kind: Method,
40+
tags: None,
41+
deprecated: None,
42+
range: Range {
43+
start: Position {
44+
line: 3,
45+
character: 10,
46+
},
47+
end: Position {
48+
line: 7,
49+
character: 5,
50+
},
51+
},
52+
selection_range: Range {
53+
start: Position {
54+
line: 3,
55+
character: 10,
56+
},
57+
end: Position {
58+
line: 7,
59+
character: 5,
60+
},
61+
},
62+
children: Some(
63+
[
64+
DocumentSymbol {
65+
name: "nested section",
66+
detail: None,
67+
kind: String,
68+
tags: None,
69+
deprecated: None,
70+
range: Range {
71+
start: Position {
72+
line: 5,
73+
character: 8,
74+
},
75+
end: Position {
76+
line: 6,
77+
character: 31,
78+
},
79+
},
80+
selection_range: Range {
81+
start: Position {
82+
line: 5,
83+
character: 8,
84+
},
85+
end: Position {
86+
line: 6,
87+
character: 31,
88+
},
89+
},
90+
children: Some(
91+
[
92+
DocumentSymbol {
93+
name: "nested",
94+
detail: Some(
95+
"function()",
96+
),
97+
kind: Function,
98+
tags: None,
99+
deprecated: None,
100+
range: Range {
101+
start: Position {
102+
line: 6,
103+
character: 8,
104+
},
105+
end: Position {
106+
line: 6,
107+
character: 31,
108+
},
109+
},
110+
selection_range: Range {
111+
start: Position {
112+
line: 6,
113+
character: 8,
114+
},
115+
end: Position {
116+
line: 6,
117+
character: 31,
118+
},
119+
},
120+
children: Some(
121+
[],
122+
),
123+
},
124+
],
125+
),
126+
},
127+
],
128+
),
129+
},
130+
DocumentSymbol {
131+
name: "nested",
132+
detail: Some(
133+
"function()",
134+
),
135+
kind: Function,
136+
tags: None,
137+
deprecated: None,
138+
range: Range {
139+
start: Position {
140+
line: 11,
141+
character: 8,
142+
},
143+
end: Position {
144+
line: 12,
145+
character: 5,
146+
},
147+
},
148+
selection_range: Range {
149+
start: Position {
150+
line: 11,
151+
character: 8,
152+
},
153+
end: Position {
154+
line: 12,
155+
character: 5,
156+
},
157+
},
158+
children: Some(
159+
[],
160+
),
161+
},
162+
DocumentSymbol {
163+
name: "bar",
164+
detail: Some(
165+
"function()",
166+
),
167+
kind: Method,
168+
tags: None,
169+
deprecated: None,
170+
range: Range {
171+
start: Position {
172+
line: 14,
173+
character: 10,
174+
},
175+
end: Position {
176+
line: 16,
177+
character: 5,
178+
},
179+
},
180+
selection_range: Range {
181+
start: Position {
182+
line: 14,
183+
character: 10,
184+
},
185+
end: Position {
186+
line: 16,
187+
character: 5,
188+
},
189+
},
190+
children: Some(
191+
[],
192+
),
193+
},
194+
],
195+
),
196+
},
197+
]

0 commit comments

Comments
 (0)