Skip to content

Commit

Permalink
Support interpolated string args, add assert condition/branch, fix if…
Browse files Browse the repository at this point in the history
… branch
  • Loading branch information
fidgetingbits committed Nov 1, 2023
1 parent c9a7f97 commit df12b92
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 168 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ command:
scopeType: {type: branch}
usePrePhraseSnapshot: true
initialState:
documentContents: |
documentContents: |-
{
key = if a then b else c;
foo = if a then b else c;
}
selections:
- anchor: {line: 1, character: 9}
active: {line: 1, character: 9}
marks: {}
finalState:
documentContents: |
documentContents: |-
{
key = then b else c;
foo = else c;
}
selections:
- anchor: {line: 1, character: 8}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: nix
command:
version: 6
spokenForm: chuck arg
action:
name: remove
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: argumentOrParameter}
usePrePhraseSnapshot: true
initialState:
documentContents: |
{
d = "Interpolated ${value1} string ${value2}";
}
selections:
- anchor: {line: 1, character: 26}
active: {line: 1, character: 26}
marks: {}
finalState:
documentContents: |
{
d = "Interpolated string ${value2}";
}
selections:
- anchor: {line: 1, character: 20}
active: {line: 1, character: 20}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: nix
command:
version: 6
spokenForm: chuck key
action:
name: remove
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionKey}
usePrePhraseSnapshot: true
initialState:
documentContents: |
{
d = "Interpolated ${value1} string ${value2}";
}
selections:
- anchor: {line: 1, character: 6}
active: {line: 1, character: 6}
marks: {}
finalState:
documentContents: |
{
"Interpolated ${value1} string ${value2}";
}
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
36 changes: 24 additions & 12 deletions queries/nix.scm
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
(
(assert_expression
"assert" @statement.start
condition: (_) @condition
condition: (_)
";" @statement.end
body: (_)
) @_.domain
(#not-parent-type? @_.domain binding)
)
(assert_expression
"assert" @functionCallee @functionCall.start
condition: (_) @condition
body: (_) @branch @functionCall.end.startOf
) @_.domain

(
(with_expression) @statement
Expand All @@ -52,19 +57,17 @@
;;! ^^^^^^^^^^^^^^^^^^
(if_expression) @ifStatement @branch.iteration @condition.iteration
;;!! key = if a then b else c;
;;! ^^^^
;;! ^^^^^^^^^^^
;;! xxxxxxxxxxxx
(if_expression
"if" @branch.start
condition: (_) @branch.end
)
;;!! key = if a then b else c;
;;! ^^^^^^
(if_expression
"then" @branch.start
condition: (_)
"then"
consequence: (_) @branch.end
)
;;!! key = if a then b else c;
;;! ^^^^^^
;;! xxxxxxx
(if_expression
"else" @branch.start
alternative: (_) @branch.end
Expand Down Expand Up @@ -93,9 +96,11 @@

;;!! foo = { x = 1; y = 2; };
;;! ^
;;! xxxx
;;! -----
(binding
attrpath: (_) @collectionKey
attrpath: (_) @collectionKey @_.trailing.start.endOf
expression: (_) @_.trailing.end.startOf
) @_.domain

;; Strings
Expand All @@ -110,6 +115,13 @@
] @string
(string_fragment) @textFragment

;;!! d = "foo ${bar} baz"
;;! ^^^^^^
;;! <**************>
(string_expression
(interpolation) @argumentOrParameter
) @_.iteration

;; Functions

;; Note for this part of the function, we identify is as lambda only
Expand Down Expand Up @@ -166,10 +178,10 @@

;;!! a = 25;
;;! ^
;;! xx
;;! xxxx
;;! -------
(binding
(_) @name @_.leading.end.startOf
(_) @name @_.leading.end.startOf @_.trailing.start.endOf
.
expression: (_)
expression: (_) @_.trailing.end.startOf
) @_.domain

0 comments on commit df12b92

Please sign in to comment.