From bc9e661633b3a96c5879b698d17afc1683721d08 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Fri, 17 May 2024 17:37:15 +0200 Subject: [PATCH 1/7] css scope migration --- packages/cursorless-engine/src/languages/scss.ts | 7 ------- queries/css.scm | 12 ++++++++++++ queries/scss.scm | 9 +++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/cursorless-engine/src/languages/scss.ts b/packages/cursorless-engine/src/languages/scss.ts index ee9180c9a9..b0f2032281 100644 --- a/packages/cursorless-engine/src/languages/scss.ts +++ b/packages/cursorless-engine/src/languages/scss.ts @@ -108,7 +108,6 @@ function unitMatcher( const nodeMatchers: Partial< Record > = { - ifStatement: "if_statement", condition: conditionMatcher("condition"), statement: cascadingMatcher( patternMatcher(...STATEMENT_TYPES), @@ -117,10 +116,6 @@ const nodeMatchers: Partial< childRangeSelector([], ["attribute_name", "string_value"]), ), ), - functionCall: "call_expression", - functionCallee: "call_expression.function_name!", - namedFunction: ["mixin_statement", "function_statement"], - functionName: ["mixin_statement.name!", "function_statement.name!"], argumentOrParameter: cascadingMatcher( matcher( patternFinder("arguments.*!", "parameters.*!"), @@ -140,7 +135,6 @@ const nodeMatchers: Partial< "attribute_selector.attribute_name!", "parameter.variable_name!", ], - selector: ["rule_set.selectors!"], collectionKey: trailingMatcher(["declaration.property_name!"], [":"]), value: cascadingMatcher( matcher( @@ -160,7 +154,6 @@ const nodeMatchers: Partial< ), ), unit: cascadingMatcher(patternMatcher("integer_value.unit!"), unitMatcher), - collectionItem: "declaration", }; export const patternMatchers = createPatternMatchers(nodeMatchers); diff --git a/queries/css.scm b/queries/css.scm index 6516c91ad5..f560ee3adb 100644 --- a/queries/css.scm +++ b/queries/css.scm @@ -1,3 +1,15 @@ (string_value) @string @textFragment (comment) @comment @textFragment + +(call_expression) @functionCall + +(declaration) @collectionItem + +(call_expression + (function_name) @functionCallee +) @_.domain + +(rule_set + (selectors) @selector +) @_.domain diff --git a/queries/scss.scm b/queries/scss.scm index 38d5be1727..583c828f22 100644 --- a/queries/scss.scm +++ b/queries/scss.scm @@ -1,3 +1,12 @@ ;; import css.scm (single_line_comment) @comment @textFragment + +(if_statement) @ifStatement + +(mixin_statement + (name) @functionName +) @namedFunction @functionName.domain +(function_statement + (name) @functionName +) @namedFunction @functionName.domain From b1bc38c24e7168e078d9b31b791c708a3fadf80d Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 18 May 2024 12:46:03 +0200 Subject: [PATCH 2/7] migrate name --- .../recorded/languages/scss/changeName2.yml | 4 ++-- packages/cursorless-engine/src/languages/scss.ts | 8 -------- queries/css.scm | 11 ++++++++--- queries/scss.scm | 16 ++++++++++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/data/fixtures/recorded/languages/scss/changeName2.yml b/data/fixtures/recorded/languages/scss/changeName2.yml index 95ea3be125..a3275ab265 100644 --- a/data/fixtures/recorded/languages/scss/changeName2.yml +++ b/data/fixtures/recorded/languages/scss/changeName2.yml @@ -16,8 +16,8 @@ initialState: @return $result; } selections: - - anchor: {line: 1, character: 13} - active: {line: 1, character: 13} + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} marks: {} finalState: documentContents: |- diff --git a/packages/cursorless-engine/src/languages/scss.ts b/packages/cursorless-engine/src/languages/scss.ts index b0f2032281..549fa89788 100644 --- a/packages/cursorless-engine/src/languages/scss.ts +++ b/packages/cursorless-engine/src/languages/scss.ts @@ -127,14 +127,6 @@ const nodeMatchers: Partial< ), ), ), - name: [ - "function_statement.name!", - "declaration.property_name!", - "declaration.variable_name!", - "mixin_statement.name!", - "attribute_selector.attribute_name!", - "parameter.variable_name!", - ], collectionKey: trailingMatcher(["declaration.property_name!"], [":"]), value: cascadingMatcher( matcher( diff --git a/queries/css.scm b/queries/css.scm index f560ee3adb..196d08c17c 100644 --- a/queries/css.scm +++ b/queries/css.scm @@ -2,14 +2,19 @@ (comment) @comment @textFragment -(call_expression) @functionCall - (declaration) @collectionItem (call_expression (function_name) @functionCallee -) @_.domain +) @_.domain @functionCall (rule_set (selectors) @selector ) @_.domain + +(declaration + (property_name) @name +) @_.domain +(attribute_selector + (attribute_name) @name +) @_.domain diff --git a/queries/scss.scm b/queries/scss.scm index 583c828f22..72eb4ea200 100644 --- a/queries/scss.scm +++ b/queries/scss.scm @@ -5,8 +5,16 @@ (if_statement) @ifStatement (mixin_statement - (name) @functionName -) @namedFunction @functionName.domain + (name) @functionName @name +) @namedFunction @_.domain + (function_statement - (name) @functionName -) @namedFunction @functionName.domain + (name) @functionName @name +) @namedFunction @_.domain + +(declaration + (variable_name) @name +) @_.domain +(parameter + (variable_name) @name +) @_.domain From f8f987be767266f3e2a9e0267582499beb7abce8 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sun, 19 May 2024 19:57:40 +0200 Subject: [PATCH 3/7] Cleanup --- queries/css.scm | 2 +- queries/scss.scm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/queries/css.scm b/queries/css.scm index 196d08c17c..71a8dd1f58 100644 --- a/queries/css.scm +++ b/queries/css.scm @@ -6,7 +6,7 @@ (call_expression (function_name) @functionCallee -) @_.domain @functionCall +) @functionCall @functionCallee.domain (rule_set (selectors) @selector diff --git a/queries/scss.scm b/queries/scss.scm index 72eb4ea200..257f0dd2ae 100644 --- a/queries/scss.scm +++ b/queries/scss.scm @@ -6,11 +6,11 @@ (mixin_statement (name) @functionName @name -) @namedFunction @_.domain +) @namedFunction @functionName.domain @name.domain (function_statement (name) @functionName @name -) @namedFunction @_.domain +) @namedFunction @functionName.domain @name.domain (declaration (variable_name) @name From 56a1bf176b228a65d8d83ce95dee6063b3d551ee Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 30 May 2024 20:01:52 +0100 Subject: [PATCH 4/7] Add iteration scopes --- .../scopes/css/name.iteration.block.scope | 13 ++++++ .../scopes/css/name.iteration.document.scope | 7 ++++ .../functionName.iteration.document.scope | 7 ++++ .../scopes/scss/functionName.iteration.scope | 13 ++++++ data/fixtures/scopes/scss/index.json | 3 ++ .../namedFunction.iteration.document.scope | 7 ++++ .../scopes/scss/namedFunction.iteration.scope | 13 ++++++ packages/common/src/scopeSupportFacets/css.ts | 2 + .../scopeSupportFacetInfos.ts | 41 +++++++++++++++++++ .../scopeSupportFacets.types.ts | 8 ++++ .../common/src/scopeSupportFacets/scss.ts | 5 +++ queries/css.scm | 8 ++++ queries/scss.scm | 8 ++++ 13 files changed, 135 insertions(+) create mode 100644 data/fixtures/scopes/css/name.iteration.block.scope create mode 100644 data/fixtures/scopes/css/name.iteration.document.scope create mode 100644 data/fixtures/scopes/scss/functionName.iteration.document.scope create mode 100644 data/fixtures/scopes/scss/functionName.iteration.scope create mode 100644 data/fixtures/scopes/scss/index.json create mode 100644 data/fixtures/scopes/scss/namedFunction.iteration.document.scope create mode 100644 data/fixtures/scopes/scss/namedFunction.iteration.scope diff --git a/data/fixtures/scopes/css/name.iteration.block.scope b/data/fixtures/scopes/css/name.iteration.block.scope new file mode 100644 index 0000000000..5b469d872a --- /dev/null +++ b/data/fixtures/scopes/css/name.iteration.block.scope @@ -0,0 +1,13 @@ +a { color: red; } +--- + +[#1 Range] = +[#1 Domain] = 0:0-0:17 + >-----------------< +0| a { color: red; } + + +[#2 Range] = +[#2 Domain] = 0:3-0:16 + >-------------< +0| a { color: red; } diff --git a/data/fixtures/scopes/css/name.iteration.document.scope b/data/fixtures/scopes/css/name.iteration.document.scope new file mode 100644 index 0000000000..2d3bdd8815 --- /dev/null +++ b/data/fixtures/scopes/css/name.iteration.document.scope @@ -0,0 +1,7 @@ +/* hello */ +--- + +[Range] = +[Domain] = 0:0-0:11 + >-----------< +0| /* hello */ diff --git a/data/fixtures/scopes/scss/functionName.iteration.document.scope b/data/fixtures/scopes/scss/functionName.iteration.document.scope new file mode 100644 index 0000000000..2d3bdd8815 --- /dev/null +++ b/data/fixtures/scopes/scss/functionName.iteration.document.scope @@ -0,0 +1,7 @@ +/* hello */ +--- + +[Range] = +[Domain] = 0:0-0:11 + >-----------< +0| /* hello */ diff --git a/data/fixtures/scopes/scss/functionName.iteration.scope b/data/fixtures/scopes/scss/functionName.iteration.scope new file mode 100644 index 0000000000..5b469d872a --- /dev/null +++ b/data/fixtures/scopes/scss/functionName.iteration.scope @@ -0,0 +1,13 @@ +a { color: red; } +--- + +[#1 Range] = +[#1 Domain] = 0:0-0:17 + >-----------------< +0| a { color: red; } + + +[#2 Range] = +[#2 Domain] = 0:3-0:16 + >-------------< +0| a { color: red; } diff --git a/data/fixtures/scopes/scss/index.json b/data/fixtures/scopes/scss/index.json new file mode 100644 index 0000000000..6d73147f10 --- /dev/null +++ b/data/fixtures/scopes/scss/index.json @@ -0,0 +1,3 @@ +{ + "imports": ["css"] +} diff --git a/data/fixtures/scopes/scss/namedFunction.iteration.document.scope b/data/fixtures/scopes/scss/namedFunction.iteration.document.scope new file mode 100644 index 0000000000..2d3bdd8815 --- /dev/null +++ b/data/fixtures/scopes/scss/namedFunction.iteration.document.scope @@ -0,0 +1,7 @@ +/* hello */ +--- + +[Range] = +[Domain] = 0:0-0:11 + >-----------< +0| /* hello */ diff --git a/data/fixtures/scopes/scss/namedFunction.iteration.scope b/data/fixtures/scopes/scss/namedFunction.iteration.scope new file mode 100644 index 0000000000..5b469d872a --- /dev/null +++ b/data/fixtures/scopes/scss/namedFunction.iteration.scope @@ -0,0 +1,13 @@ +a { color: red; } +--- + +[#1 Range] = +[#1 Domain] = 0:0-0:17 + >-----------------< +0| a { color: red; } + + +[#2 Range] = +[#2 Domain] = 0:3-0:16 + >-------------< +0| a { color: red; } diff --git a/packages/common/src/scopeSupportFacets/css.ts b/packages/common/src/scopeSupportFacets/css.ts index e30b82cc4a..52159d887a 100644 --- a/packages/common/src/scopeSupportFacets/css.ts +++ b/packages/common/src/scopeSupportFacets/css.ts @@ -12,4 +12,6 @@ export const cssScopeSupport: LanguageScopeSupportFacetMap = { "comment.line": supported, "comment.block": supported, "string.singleLine": supported, + "name.iteration.block": supported, + "name.iteration.document": supported, }; diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index a2e6291382..5bde727b89 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -124,6 +124,21 @@ export const scopeSupportFacetInfos: Record< description: "A named method declaration in a class", scopeType: "namedFunction", }, + "namedFunction.iteration": { + description: "Iteration scope for named functions", + scopeType: "namedFunction", + isIteration: true, + }, + "namedFunction.iteration.class": { + description: "Iteration scope for named functions: class methods", + scopeType: "namedFunction", + isIteration: true, + }, + "namedFunction.iteration.document": { + description: "Iteration scope for named functions: class methods", + scopeType: "namedFunction", + isIteration: true, + }, anonymousFunction: { description: "An anonymous function, eg a lambda function, an arrow function, etc", @@ -133,6 +148,21 @@ export const scopeSupportFacetInfos: Record< description: "The name of a function", scopeType: "functionName", }, + "functionName.iteration": { + description: "Iteration scope for function names", + scopeType: "functionName", + isIteration: true, + }, + "functionName.iteration.class": { + description: "Iteration scope for function names: class methods", + scopeType: "functionName", + isIteration: true, + }, + "functionName.iteration.document": { + description: "Iteration scope for function names: class methods", + scopeType: "functionName", + isIteration: true, + }, functionCall: { description: "A function call", @@ -299,6 +329,17 @@ export const scopeSupportFacetInfos: Record< scopeType: "name", isIteration: true, }, + "name.iteration.block": { + description: + "Iteration scope for names: statement blocks (body of functions/if classes/for loops/etc).", + scopeType: "name", + isIteration: true, + }, + "name.iteration.document": { + description: "Iteration scope for names: the entire document", + scopeType: "name", + isIteration: true, + }, "key.attribute": { description: "Key (LHS) of an attribute eg in an xml element", scopeType: "collectionKey", diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 96d1ef9c2f..3e72b529db 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -31,8 +31,14 @@ const scopeSupportFacets = [ "className.iteration.block", "namedFunction", "namedFunction.method", + "namedFunction.iteration", + "namedFunction.iteration.document", + "namedFunction.iteration.class", "anonymousFunction", "functionName", + "functionName.iteration", + "functionName.iteration.document", + "functionName.iteration.class", "functionCall", "functionCall.constructor", @@ -76,6 +82,8 @@ const scopeSupportFacets = [ "name.resource.iteration", "name.argument.formal", "name.argument.formal.iteration", + "name.iteration.block", + "name.iteration.document", "key.attribute", "key.mapPair", diff --git a/packages/common/src/scopeSupportFacets/scss.ts b/packages/common/src/scopeSupportFacets/scss.ts index 197e257ded..ebdd32d6e3 100644 --- a/packages/common/src/scopeSupportFacets/scss.ts +++ b/packages/common/src/scopeSupportFacets/scss.ts @@ -11,4 +11,9 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const scssScopeSupport: LanguageScopeSupportFacetMap = { ...cssScopeSupport, + + "namedFunction.iteration": supported, + "namedFunction.iteration.document": supported, + "functionName.iteration": supported, + "functionName.iteration.document": supported, }; diff --git a/queries/css.scm b/queries/css.scm index 71a8dd1f58..331583c920 100644 --- a/queries/css.scm +++ b/queries/css.scm @@ -18,3 +18,11 @@ (attribute_selector (attribute_name) @name ) @_.domain + +(stylesheet) @name.iteration +(block + . + "{" @name.iteration.start.endOf + "}" @name.iteration.end.startOf + . +) diff --git a/queries/scss.scm b/queries/scss.scm index 257f0dd2ae..6f76a4091f 100644 --- a/queries/scss.scm +++ b/queries/scss.scm @@ -18,3 +18,11 @@ (parameter (variable_name) @name ) @_.domain + +(stylesheet) @namedFunction.iteration @functionName.iteration +(block + . + "{" @namedFunction.iteration.start.endOf @functionName.iteration.start.endOf + "}" @namedFunction.iteration.end.startOf @functionName.iteration.end.startOf + . +) From e4a89dec56da50c3ba4aab2bf9de6b772e01e437 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 30 May 2024 20:12:57 +0100 Subject: [PATCH 5/7] Tweaks --- .../common/src/scopeSupportFacets/scopeSupportFacetInfos.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 5bde727b89..d6665d06c8 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -135,7 +135,7 @@ export const scopeSupportFacetInfos: Record< isIteration: true, }, "namedFunction.iteration.document": { - description: "Iteration scope for named functions: class methods", + description: "Iteration scope for named functions: the entire document", scopeType: "namedFunction", isIteration: true, }, @@ -159,7 +159,7 @@ export const scopeSupportFacetInfos: Record< isIteration: true, }, "functionName.iteration.document": { - description: "Iteration scope for function names: class methods", + description: "Iteration scope for function names: the entire document", scopeType: "functionName", isIteration: true, }, From d377e30f030147884da7a6daf1c4b1fddcd6d01c Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 30 May 2024 20:17:32 +0100 Subject: [PATCH 6/7] tweaks --- .../scopeSupportFacetInfos.ts | 20 +++++++++++-------- .../scopeSupportFacets.types.ts | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index d6665d06c8..82ccf73396 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -124,13 +124,13 @@ export const scopeSupportFacetInfos: Record< description: "A named method declaration in a class", scopeType: "namedFunction", }, - "namedFunction.iteration": { - description: "Iteration scope for named functions", + "namedFunction.method.iteration.class": { + description: "Iteration scope for named functions: class methods", scopeType: "namedFunction", isIteration: true, }, - "namedFunction.iteration.class": { - description: "Iteration scope for named functions: class methods", + "namedFunction.iteration": { + description: "Iteration scope for named functions", scopeType: "namedFunction", isIteration: true, }, @@ -148,16 +148,20 @@ export const scopeSupportFacetInfos: Record< description: "The name of a function", scopeType: "functionName", }, - "functionName.iteration": { - description: "Iteration scope for function names", + "functionName.method": { + description: "The name of a method in a class", scopeType: "functionName", - isIteration: true, }, - "functionName.iteration.class": { + "functionName.method.iteration.class": { description: "Iteration scope for function names: class methods", scopeType: "functionName", isIteration: true, }, + "functionName.iteration": { + description: "Iteration scope for function names", + scopeType: "functionName", + isIteration: true, + }, "functionName.iteration.document": { description: "Iteration scope for function names: the entire document", scopeType: "functionName", diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 3e72b529db..f5eb4c48e4 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -31,14 +31,15 @@ const scopeSupportFacets = [ "className.iteration.block", "namedFunction", "namedFunction.method", + "namedFunction.method.iteration.class", "namedFunction.iteration", "namedFunction.iteration.document", - "namedFunction.iteration.class", "anonymousFunction", "functionName", + "functionName.method", + "functionName.method.iteration.class", "functionName.iteration", "functionName.iteration.document", - "functionName.iteration.class", "functionCall", "functionCall.constructor", From 9496ae08a6f2dc5456e8a15ffca676affd52dc70 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 30 May 2024 20:18:25 +0100 Subject: [PATCH 7/7] tweak --- .../common/src/scopeSupportFacets/scopeSupportFacetInfos.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 82ccf73396..ee38772221 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -125,7 +125,7 @@ export const scopeSupportFacetInfos: Record< scopeType: "namedFunction", }, "namedFunction.method.iteration.class": { - description: "Iteration scope for named functions: class methods", + description: "Iteration scope for named functions: class bodies", scopeType: "namedFunction", isIteration: true, }, @@ -153,7 +153,7 @@ export const scopeSupportFacetInfos: Record< scopeType: "functionName", }, "functionName.method.iteration.class": { - description: "Iteration scope for function names: class methods", + description: "Iteration scope for function names: class bodies", scopeType: "functionName", isIteration: true, },