Skip to content

Commit 62b0f85

Browse files
Added argument list scope
1 parent e5e9929 commit 62b0f85

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

cursorless-talon/src/spoken_forms.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"modifier_scope_types.csv": {
126126
"scope_type": {
127127
"arg": "argumentOrParameter",
128+
"arg list": "argumentList",
128129
"attribute": "attribute",
129130
"call": "functionCall",
130131
"callee": "functionCallee",

packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export const scopeSupportFacets = [
7070
"argument.formal.constructor",
7171
"argument.formal.constructor.iteration",
7272

73+
"argumentList.formal",
74+
7375
"comment.line",
7476
"comment.block",
7577

packages/common/src/types/command/PartialTargetDescriptor.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export type SurroundingPairName =
141141

142142
export const simpleScopeTypeTypes = [
143143
"argumentOrParameter",
144+
"argumentList",
144145
"anonymousFunction",
145146
"attribute",
146147
"branch",

packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,39 @@ class SingleOrMultilineDelimiter extends QueryPredicateOperator<SingleOrMultilin
318318
}
319319
}
320320

321+
/**
322+
* A predicate operator that sets the insertion delimiter of {@link nodeInfo} to
323+
* either {@link insertionDelimiterConsequence} or
324+
* {@link insertionDelimiterAlternative} depending on whether
325+
* {@link conditionNodeInfo} has children or not, respectively. For example,
326+
*
327+
* ```scm
328+
* (#has-children-or-not-delimiter! @foo @bar ", " "")
329+
* ```
330+
*
331+
* will set the insertion delimiter of the `@foo` capture to `", "` if the
332+
* `@bar` capture is a single line and `",\n"` otherwise.
333+
*/
334+
class HasChildrenOrNotDelimiter extends QueryPredicateOperator<HasChildrenOrNotDelimiter> {
335+
name = "has-children-or-not-delimiter!" as const;
336+
schema = z.tuple([q.node, q.node, q.string, q.string]);
337+
338+
run(
339+
nodeInfo: MutableQueryCapture,
340+
conditionNodeInfo: MutableQueryCapture,
341+
insertionDelimiterConsequence: string,
342+
insertionDelimiterAlternative: string,
343+
) {
344+
nodeInfo.insertionDelimiter = conditionNodeInfo.node.children.some(
345+
(child) => child.isNamed,
346+
)
347+
? insertionDelimiterConsequence
348+
: insertionDelimiterAlternative;
349+
350+
return true;
351+
}
352+
}
353+
321354
export const queryPredicateOperators = [
322355
new Log(),
323356
new NotType(),
@@ -331,5 +364,6 @@ export const queryPredicateOperators = [
331364
new AllowMultiple(),
332365
new InsertionDelimiter(),
333366
new SingleOrMultilineDelimiter(),
367+
new HasChildrenOrNotDelimiter(),
334368
new HasMultipleChildrenOfType(),
335369
];

packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function isLanguageSpecific(scopeType: ScopeType): boolean {
111111
switch (scopeType.type) {
112112
case "string":
113113
case "argumentOrParameter":
114+
case "argumentList":
114115
case "anonymousFunction":
115116
case "attribute":
116117
case "branch":

packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
4040

4141
simpleScopeTypeType: {
4242
argumentOrParameter: "arg",
43+
argumentList: "arg list",
4344
attribute: "attribute",
4445
functionCall: "call",
4546
functionCallee: "callee",

queries/javascript.core.scm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,16 @@
748748
(#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n")
749749
)
750750

751+
;;!! foo(name) {}
752+
;;! ^^^^
753+
(_
754+
(formal_parameters
755+
"(" @argumentList.start.endOf
756+
")" @argumentList.end.startOf
757+
) @_dummy
758+
(#has-children-or-not-delimiter! @argumentList.start.endOf @_dummy ", " "")
759+
) @argumentList.domain
760+
751761
;;!! foo("bar")
752762
;;! ^^^^^
753763
(

0 commit comments

Comments
 (0)