1- import type { SyntaxNode } from "web-tree-sitter" ;
21import type { SimpleScopeTypeType } from "@cursorless/common" ;
3- import type {
4- NodeMatcherAlternative ,
5- NodeMatcherValue ,
6- SelectionWithEditor ,
7- } from "../typings/Types" ;
2+ import type { SyntaxNode } from "web-tree-sitter" ;
3+ import type { NodeMatcherAlternative } from "../typings/Types" ;
84import { patternFinder } from "../util/nodeFinders" ;
95import {
106 cascadingMatcher ,
11- conditionMatcher ,
127 createPatternMatchers ,
138 matcher ,
14- patternMatcher ,
15- trailingMatcher ,
169} from "../util/nodeMatchers" ;
17- import {
18- childRangeSelector ,
19- delimitedSelector ,
20- simpleSelectionExtractor ,
21- } from "../util/nodeSelectors" ;
22-
23- // curl https://raw.githubusercontent.com/serenadeai/tree-sitter-scss/c478c6868648eff49eb04a4df90d703dc45b312a/src/node-types.json \
24- // | jq '[.[] | select(.type =="stylesheet") | .children.types[] | select(.type !="declaration") | .type ]'
25-
26- const STATEMENT_TYPES = [
27- "apply_statement" ,
28- "at_rule" ,
29- "charset_statement" ,
30- "debug_statement" ,
31- "each_statement" ,
32- "error_statement" ,
33- "for_statement" ,
34- "forward_statement" ,
35- "function_statement" ,
36- "if_statement" ,
37- "import_statement" ,
38- "include_statement" ,
39- "keyframes_statement" ,
40- "media_statement" ,
41- "mixin_statement" ,
42- "namespace_statement" ,
43- "placeholder" ,
44- "rule_set" ,
45- "supports_statement" ,
46- "use_statement" ,
47- "warn_statement" ,
48- "while_statement" ,
49- ] ;
10+ import { delimitedSelector } from "../util/nodeSelectors" ;
5011
5112function isArgumentListDelimiter ( node : SyntaxNode ) {
5213 return [ "," , "(" , ")" ] . includes ( node . type ) || isAtDelimiter ( node ) ;
@@ -91,31 +52,9 @@ function findAdjacentArgValues(
9152 } ;
9253}
9354
94- function unitMatcher (
95- selection : SelectionWithEditor ,
96- node : SyntaxNode ,
97- ) : NodeMatcherValue [ ] | null {
98- if ( node . type !== "declaration" ) {
99- return null ;
100- }
101-
102- return node . descendantsOfType ( "unit" ) . map ( ( n ) => ( {
103- node : n ,
104- selection : simpleSelectionExtractor ( selection . editor , n ) ,
105- } ) ) ;
106- }
107-
10855const nodeMatchers : Partial <
10956 Record < SimpleScopeTypeType , NodeMatcherAlternative >
11057> = {
111- condition : conditionMatcher ( "condition" ) ,
112- statement : cascadingMatcher (
113- patternMatcher ( ...STATEMENT_TYPES ) ,
114- matcher (
115- patternFinder ( "attribute_selector" ) ,
116- childRangeSelector ( [ ] , [ "attribute_name" , "string_value" ] ) ,
117- ) ,
118- ) ,
11958 argumentOrParameter : cascadingMatcher (
12059 matcher (
12160 patternFinder ( "arguments.*!" , "parameters.*!" ) ,
@@ -127,25 +66,6 @@ const nodeMatchers: Partial<
12766 ) ,
12867 ) ,
12968 ) ,
130- collectionKey : trailingMatcher ( [ "declaration.property_name!" ] , [ ":" ] ) ,
131- value : cascadingMatcher (
132- matcher (
133- patternFinder ( "declaration" ) ,
134- childRangeSelector ( [ "property_name" , "variable_name" ] ) ,
135- ) ,
136- matcher (
137- patternFinder ( "include_statement" , "namespace_statement" ) ,
138- childRangeSelector ( ) ,
139- ) ,
140- patternMatcher (
141- "return_statement.*!" ,
142- "import_statement.*!" ,
143- "attribute_selector.plain_value!" ,
144- "attribute_selector.string_value!" ,
145- "parameter.default_value!" ,
146- ) ,
147- ) ,
148- unit : cascadingMatcher ( patternMatcher ( "integer_value.unit!" ) , unitMatcher ) ,
14969} ;
15070
15171export const patternMatchers = createPatternMatchers ( nodeMatchers ) ;
0 commit comments