Skip to content

Commit 4b4c03c

Browse files
Clean up scss.ts and scss.scm
1 parent 60975db commit 4b4c03c

File tree

2 files changed

+33
-83
lines changed

2 files changed

+33
-83
lines changed
Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,13 @@
1-
import type { SyntaxNode } from "web-tree-sitter";
21
import 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";
84
import { patternFinder } from "../util/nodeFinders";
95
import {
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

5112
function 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-
10855
const 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

15171
export const patternMatchers = createPatternMatchers(nodeMatchers);

queries/scss.scm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,40 @@
22

33
;; https://github.com/serenadeai/tree-sitter-scss/blob/master/src/grammar.json
44

5+
;; curl https://raw.githubusercontent.com/serenadeai/tree-sitter-scss/c478c6868648eff49eb04a4df90d703dc45b312a/src/node-types.json \
6+
;; | jq '[.[] | select(.type =="stylesheet") | .children.types[] | select(.type !="declaration") | .type ]'
7+
8+
[
9+
(apply_statement)
10+
(at_rule)
11+
(charset_statement)
12+
(debug_statement)
13+
(each_statement)
14+
(error_statement)
15+
(for_statement)
16+
(forward_statement)
17+
(function_statement)
18+
(if_statement)
19+
(import_statement)
20+
(include_statement)
21+
(keyframes_statement)
22+
(media_statement)
23+
(mixin_statement)
24+
(namespace_statement)
25+
(placeholder)
26+
(rule_set)
27+
(supports_statement)
28+
(use_statement)
29+
(warn_statement)
30+
(while_statement)
31+
] @statement
32+
533
(single_line_comment) @comment @textFragment
634

735
(if_statement) @ifStatement
836

37+
(condition) @condition
38+
939
(mixin_statement
1040
(name) @functionName @name
1141
) @namedFunction @functionName.domain @name.domain

0 commit comments

Comments
 (0)