Skip to content

Commit 5b5584c

Browse files
author
fidgetingbits
committed
Add key/value support and fix some edge interpolation edge cases
1 parent 69aad89 commit 5b5584c

File tree

9 files changed

+179
-28
lines changed

9 files changed

+179
-28
lines changed

data/playground/shellscript/shellscript.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/bin/bash
22

3+
34
# Variable declaration
45
var="Hello, World"
5-
number=42
66
array=("apple" "banana" "cherry")
77

88
# Output variables
99
echo "String variable: $var"
1010
echo "Number variable: $number"
1111
echo "Array variable: ${array[*]}"
12-
12+
echo A B C
1313
# If statement
1414
if [ "$number" -eq 42 ]; then
1515
echo "The number is 42"
@@ -36,6 +36,9 @@ my_function() {
3636
echo "$local_var from function"
3737
}
3838

39+
sub_function() (foo)
40+
sub_function() ((foo++))
41+
3942
my_function "Function Argument"
4043

4144
# Case statement
@@ -163,3 +166,7 @@ echo "Incremented value: $value"
163166
numbers=(1 2 3 4 5)
164167
sliced_numbers=("${numbers[@]:1:3}")
165168
echo "Sliced array: ${sliced_numbers[*]}"
169+
170+
declare -A arr
171+
arr["key1"]=val1
172+
arr+=(["key2"]=val2 ["key3"]=val3)

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/containingScope/changeGrandState.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
languageId: javascript
22
command:
33
version: 6
4-
spokenForm: change grand state
4+
spokenForm: change state
55
action:
66
name: clearAndSetSelection
77
target:

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/containingScope/changeGrandState2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
languageId: python
22
command:
33
version: 6
4-
spokenForm: change grand state
4+
spokenForm: change state
55
action:
66
name: clearAndSetSelection
77
target:

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/containingScope/changeGrandState3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
languageId: javascript
22
command:
33
version: 6
4-
spokenForm: change grand state
4+
spokenForm: change state
55
action:
66
name: clearAndSetSelection
77
target:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change every arg inside trap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
10+
modifiers:
11+
- type: everyScope
12+
scopeType: {type: argumentOrParameter}
13+
- {type: interiorOnly}
14+
usePrePhraseSnapshot: true
15+
initialState:
16+
documentContents: |
17+
echo "Test ${foo} ${bar}"
18+
selections:
19+
- anchor: {line: 0, character: 13}
20+
active: {line: 0, character: 13}
21+
marks:
22+
default.t:
23+
start: {line: 0, character: 6}
24+
end: {line: 0, character: 10}
25+
finalState:
26+
documentContents: |
27+
echo "Test "
28+
selections:
29+
- anchor: {line: 0, character: 11}
30+
active: {line: 0, character: 11}
31+
- anchor: {line: 0, character: 12}
32+
active: {line: 0, character: 12}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change every arg inside trap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
10+
modifiers:
11+
- type: everyScope
12+
scopeType: {type: argumentOrParameter}
13+
- {type: interiorOnly}
14+
usePrePhraseSnapshot: true
15+
initialState:
16+
documentContents: |
17+
echo "Test $foo $bar"
18+
selections:
19+
- anchor: {line: 0, character: 14}
20+
active: {line: 0, character: 14}
21+
marks:
22+
default.t:
23+
start: {line: 0, character: 6}
24+
end: {line: 0, character: 10}
25+
finalState:
26+
documentContents: |
27+
echo "Test "
28+
selections:
29+
- anchor: {line: 0, character: 11}
30+
active: {line: 0, character: 11}
31+
- anchor: {line: 0, character: 12}
32+
active: {line: 0, character: 12}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change key crunch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: k}
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: collectionKey}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |-
16+
declare -A arr
17+
arr["key1"]=val1
18+
arr+=([key2]=val2 ["key3"]=val3)
19+
selections:
20+
- anchor: {line: 2, character: 17}
21+
active: {line: 2, character: 17}
22+
marks:
23+
default.k:
24+
start: {line: 2, character: 7}
25+
end: {line: 2, character: 11}
26+
finalState:
27+
documentContents: |-
28+
declare -A arr
29+
arr["key1"]=val1
30+
arr+=([]=val2 ["key3"]=val3)
31+
selections:
32+
- anchor: {line: 2, character: 7}
33+
active: {line: 2, character: 7}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change value vest
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: v}
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: value}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |-
16+
declare -A arr
17+
arr["key1"]=val1
18+
arr+=([key2]=val2 ["key3"]=val3)
19+
selections:
20+
- anchor: {line: 2, character: 17}
21+
active: {line: 2, character: 17}
22+
marks:
23+
default.v:
24+
start: {line: 2, character: 13}
25+
end: {line: 2, character: 17}
26+
finalState:
27+
documentContents: |-
28+
declare -A arr
29+
arr["key1"]=val1
30+
arr+=([key2]= ["key3"]=val3)
31+
selections:
32+
- anchor: {line: 2, character: 13}
33+
active: {line: 2, character: 13}

queries/shellscript.scm

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@
171171
")" @_.interior.end.startOf
172172
) @list @collectionItem.iteration
173173

174+
;;!! FIXME: I will file an issue in tree-sitter-bash as I think the grammar is
175+
;;!! bad. But the below does work for now
176+
;;!! arr+=(["key2"]=val2 ["key3"]=val3)
177+
(array
178+
(
179+
(concatenation
180+
;; This matches the [ which is (word) for some reason
181+
(_) @collectionKey.leading.start
182+
(_) @collectionKey
183+
;; This matches the ] which is also (word) for some reason
184+
(_) @collectionKey.trailing.end
185+
(_) @value
186+
) @collectionItem
187+
(#shrink-to-match! @value "\=(?<keep>.*)")
188+
)
189+
)
190+
174191
;;
175192
;; Strings
176193
;;
@@ -183,27 +200,20 @@
183200
;;! ^^^^^
184201
(string) @string @textFragment
185202

186-
;; TODO: These two cases are broken as they are a single (expression), and the " " isn't recognized
187-
;; echo "Foo ${BAR} ${BAZ}"
188-
;; echo "Foo $BAR $BAZ"
189203
;;!! var="foo ${bar}"
190204
;;! ^^^^^^
191205
;;! xxxxxx
192206
(string
193-
(expansion
194-
"${" @argumentOrParameter.start.startOf
195-
.
196-
(_)
197-
.
198-
"}" @argumentOrParameter.end.endOf
207+
(
208+
(expansion) @argumentOrParameter
209+
;; FIXME: This is due to a tree-sitter-bash bug (imo) where given: "Foo ${BAR} ${BAZ}"
210+
;; ${BAZ} incorrectly includes preceding space
211+
(#shrink-to-match! @argumentOrParameter "\\s*(?<keep>.*)")
199212
)
200213
)
201214
(string
202-
(simple_expansion
203-
"$" @argumentOrParameter.start.startOf
204-
.
205-
(_) @argumentOrParameter.end.endOf
206-
)
215+
(simple_expansion) @argumentOrParameter
216+
(#shrink-to-match! @argumentOrParameter "\\s*(?<keep>.*)")
207217
)
208218

209219
;;
@@ -307,6 +317,19 @@
307317
(#not-parent-type? @dummy declaration_command)
308318
)
309319

320+
;;!! local foo="bar"
321+
;;! ^^^^^
322+
;;! xxxxxx
323+
;;! ---------------
324+
(declaration_command
325+
"local" @_.domain.start.startOf
326+
(variable_assignment
327+
"=" @value.leading.start.startOf
328+
.
329+
value: (_) @value @value.leading.end.endOf
330+
) @_.domain.end.endOf
331+
)
332+
310333
;;!! for ((i = 1; i <= 5; i++)); do
311334
;;! ^
312335
;;! xxxx
@@ -322,13 +345,4 @@
322345
) @_.domain
323346
)
324347

325-
(declaration_command
326-
"local" @_.domain.start.startOf
327-
(variable_assignment
328-
"=" @value.leading.start.startOf
329-
.
330-
value: (_) @value @value.leading.end.endOf
331-
) @_.domain.end.endOf
332-
)
333-
334348
(regex) @regularExpression @textFragment

0 commit comments

Comments
 (0)