Skip to content

Commit

Permalink
Update closuje
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Nov 19, 2024
1 parent 99aa3d0 commit 0004e98
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 39 deletions.
6 changes: 2 additions & 4 deletions data/fixtures/recorded/languages/clojure/chuckItemZip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ finalState:
documentContents: |-
{
:foo "bar",
;; hello
,
}
selections:
- anchor: {line: 4, character: 1}
active: {line: 4, character: 1}
- anchor: {line: 2, character: 1}
active: {line: 2, character: 1}
5 changes: 2 additions & 3 deletions data/fixtures/recorded/languages/clojure/clearEveryItem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ finalState:
{
,
;; hello
,
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
- anchor: {line: 4, character: 4}
active: {line: 4, character: 4}
- anchor: {line: 3, character: 4}
active: {line: 3, character: 4}
9 changes: 6 additions & 3 deletions data/fixtures/recorded/languages/clojure/clearItem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ initialState:
finalState:
documentContents: |-
{
:bongo {
:foo "bar",
,
}
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
- anchor: {line: 3, character: 8}
active: {line: 3, character: 8}
2 changes: 1 addition & 1 deletion data/fixtures/recorded/languages/clojure/clearItemFine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ initialState:
start: {line: 0, character: 2}
end: {line: 0, character: 5}
finalState:
documentContents: "{ :baz \"whatever\"}"
documentContents: "{}"
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
32 changes: 4 additions & 28 deletions packages/cursorless-engine/src/languages/clojure.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import type { SimpleScopeTypeType } from "@cursorless/common";
import type { SyntaxNode } from "web-tree-sitter";
import type { NodeFinder, NodeMatcherAlternative } from "../typings/Types";
import { patternFinder } from "../util/nodeFinders";
import {
cascadingMatcher,
chainedMatcher,
createPatternMatchers,
matcher,
patternMatcher,
} from "../util/nodeMatchers";
import type { NodeMatcherAlternative, NodeFinder } from "../typings/Types";
import type { SimpleScopeTypeType } from "@cursorless/common";
import type { SyntaxNode } from "web-tree-sitter";
import { delimitedSelector } from "../util/nodeSelectors";
import { identity } from "lodash-es";
import { getChildNodesForFieldName } from "../util/treeSitterUtils";
import { patternFinder } from "../util/nodeFinders";

/**
* Picks a node by rounding down and using the given parity. This function is
Expand Down Expand Up @@ -73,13 +71,6 @@ function indexNodeFinder(
};
}

function itemFinder() {
return indexNodeFinder(
(node) => node,
(nodeIndex: number) => nodeIndex,
);
}

/**
* Return the "value" node children of a given node. These are the items in a list
* @param node The node whose children to get
Expand Down Expand Up @@ -134,21 +125,6 @@ const nodeMatchers: Partial<
Record<SimpleScopeTypeType, NodeMatcherAlternative>
> = {
collectionKey: matcher(mapParityNodeFinder(0)),
collectionItem: cascadingMatcher(
// Treat each key value pair as a single item if we're in a map
matcher(
mapParityNodeFinder(0),
delimitedSelector(
(node) => node.type === "{" || node.type === "}",
", ",
identity,
mapParityNodeFinder(1) as (node: SyntaxNode) => SyntaxNode,
),
),

// Otherwise just treat every item within a list as an item
matcher(itemFinder()),
),
value: matcher(mapParityNodeFinder(1)),

// FIXME: Handle formal parameters
Expand Down
30 changes: 30 additions & 0 deletions queries/clojure.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,33 @@
(quoting_lit
(list_lit)
) @list

;;!! '(foo bar)
;;! ^^^ ^^^
(list_lit
(_)? @_.leading.endOf
.
(_) @collectionItem.start
.
(_)? @_.trailing.startOf
)

(list_lit
open: "(" @collectionItem.iteration.start.startOf
close: ")" @collectionItem.iteration.end.endOf
) @collectionItem.iteration.domain

;;!! [foo bar]
;;! ^^^ ^^^
(vec_lit
(_)? @_.leading.endOf
.
(_) @collectionItem.start
.
(_)? @_.trailing.startOf
)

(vec_lit
open: "[" @collectionItem.iteration.start.startOf
close: "]" @collectionItem.iteration.end.endOf
) @collectionItem.iteration.domain

0 comments on commit 0004e98

Please sign in to comment.