Skip to content

Commit 6ca47d8

Browse files
author
fidgetingbits
committed
Add keys, lists, lambda, better statements
1 parent 6fea7e8 commit 6ca47d8

File tree

9 files changed

+340
-8
lines changed

9 files changed

+340
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change key
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: collectionKey}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
local person = {
16+
name = "John",
17+
age = 30,
18+
hobbies = {"reading", "gaming", "programming"},
19+
address = {
20+
street = "123 Main St",
21+
city = "Example City"
22+
}
23+
}
24+
selections:
25+
- anchor: {line: 2, character: 6}
26+
active: {line: 2, character: 6}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
local person = {
31+
name = "John",
32+
= 30,
33+
hobbies = {"reading", "gaming", "programming"},
34+
address = {
35+
street = "123 Main St",
36+
city = "Example City"
37+
}
38+
}
39+
selections:
40+
- anchor: {line: 2, character: 4}
41+
active: {line: 2, character: 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change lambda
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: anonymousFunction}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
function makeCounter()
16+
local count = 0
17+
return function()
18+
count = count + 1
19+
return count
20+
end
21+
end
22+
selections:
23+
- anchor: {line: 3, character: 12}
24+
active: {line: 3, character: 12}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
function makeCounter()
29+
local count = 0
30+
return
31+
end
32+
selections:
33+
- anchor: {line: 2, character: 11}
34+
active: {line: 2, character: 11}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change list
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
local person = {
16+
name = "John",
17+
age = 30,
18+
hobbies = {"reading", "gaming", "programming"},
19+
address = {
20+
street = "123 Main St",
21+
city = "Example City"
22+
}
23+
}
24+
selections:
25+
- anchor: {line: 3, character: 17}
26+
active: {line: 3, character: 17}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
local person = {
31+
name = "John",
32+
age = 30,
33+
hobbies = ,
34+
address = {
35+
street = "123 Main St",
36+
city = "Example City"
37+
}
38+
}
39+
selections:
40+
- anchor: {line: 3, character: 14}
41+
active: {line: 3, character: 14}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change state
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: statement}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
function makeCounter()
16+
local count = 0
17+
return function()
18+
count = count + 1
19+
return count
20+
end
21+
end
22+
selections:
23+
- anchor: {line: 1, character: 12}
24+
active: {line: 1, character: 12}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
function makeCounter()
29+
30+
return function()
31+
count = count + 1
32+
return count
33+
end
34+
end
35+
selections:
36+
- anchor: {line: 1, character: 4}
37+
active: {line: 1, character: 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change state
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: statement}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
function makeCounter()
16+
local count = 0
17+
return function()
18+
count = count + 1
19+
return count
20+
end
21+
end
22+
selections:
23+
- anchor: {line: 2, character: 8}
24+
active: {line: 2, character: 8}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
function makeCounter()
29+
local count = 0
30+
31+
end
32+
selections:
33+
- anchor: {line: 2, character: 4}
34+
active: {line: 2, character: 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change state
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: statement}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
function makeCounter()
16+
local count = 0
17+
return function()
18+
count = count + 1
19+
return count
20+
end
21+
end
22+
selections:
23+
- anchor: {line: 3, character: 11}
24+
active: {line: 3, character: 11}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
function makeCounter()
29+
local count = 0
30+
return function()
31+
32+
return count
33+
end
34+
end
35+
selections:
36+
- anchor: {line: 3, character: 8}
37+
active: {line: 3, character: 8}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: value}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
local person = {
16+
name = "John",
17+
age = 30,
18+
hobbies = {"reading", "gaming", "programming"},
19+
address = {
20+
street = "123 Main St",
21+
city = "Example City"
22+
}
23+
}
24+
selections:
25+
- anchor: {line: 4, character: 10}
26+
active: {line: 4, character: 10}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
local person = {
31+
name = "John",
32+
age = 30,
33+
hobbies = {"reading", "gaming", "programming"},
34+
address =
35+
}
36+
selections:
37+
- anchor: {line: 4, character: 14}
38+
active: {line: 4, character: 14}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: value}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
local person = {
16+
name = "John",
17+
age = 30,
18+
hobbies = {"reading", "gaming", "programming"},
19+
address = {
20+
street = "123 Main St",
21+
city = "Example City"
22+
}
23+
}
24+
selections:
25+
- anchor: {line: 5, character: 11}
26+
active: {line: 5, character: 11}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
local person = {
31+
name = "John",
32+
age = 30,
33+
hobbies = {"reading", "gaming", "programming"},
34+
address = {
35+
street = ,
36+
city = "Example City"
37+
}
38+
}
39+
selections:
40+
- anchor: {line: 5, character: 17}
41+
active: {line: 5, character: 17}

queries/lua.scm

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
;; Statements
22
[
3+
(variable_declaration)
34
(break_statement)
45
(do_statement)
56
(elseif_statement)
@@ -12,14 +13,29 @@
1213
(repeat_statement)
1314
(return_statement)
1415
(while_statement)
15-
(variable_declaration)
16-
;; TODO: These will be too aggressive in assignments, need to check parent node isn't
17-
;; a variable declaration, etc
18-
(function_declaration)
19-
(function_call)
20-
;; Missing call
2116
] @statement
22-
(chunk) @statement.iteration
17+
18+
;; Only treat function declarions and calls as statements if they
19+
;; aren't part of assignments, etc
20+
(
21+
[
22+
(function_declaration)
23+
(function_call)
24+
] @statement
25+
(#not-parent-type? @statement expression_list)
26+
)
27+
[
28+
(block)
29+
(chunk)
30+
] @statement.iteration
31+
32+
;; Capture assignment only if without variable prefix
33+
;;!! count = count + 1
34+
;;! ^^^^^^^^^^^^^^^^^
35+
(
36+
(assignment_statement) @statement
37+
(#not-parent-type? @statement variable_declaration)
38+
)
2339

2440
;; Conditionals
2541
(
@@ -37,7 +53,20 @@
3753
] @branch
3854

3955
;; Lists and maps
40-
(table_constructor) @map
56+
(table_constructor) @map @collectionKey.iteration
57+
(field
58+
name: (_) @collectionKey
59+
) @_.domain
60+
(field
61+
value: (_) @value
62+
) @_.domain
63+
;; In lua everything is a map, but a map that omits keys for entries
64+
;; is similar enough to a list to warrant having that scope.
65+
(table_constructor
66+
(field
67+
!name
68+
)
69+
) @list
4170

4271
;; Strings
4372

0 commit comments

Comments
 (0)