-
-
Couldn't load subscription status.
- Fork 91
Refactor transformations and add name transformation #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
12ba0df
79ed944
0a96484
89e0c85
cd7c36a
b1061eb
c77d9f0
9c3b2f1
3a79d5d
8365b2c
91f4ade
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import * as vscode from "vscode"; | ||
| import { SyntaxNode } from "web-tree-sitter"; | ||
|
|
||
| export function logBranchTypes(getNodeAtLocation: any) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally try to avoid Also, I'd probably opt for a class here rather than returning a function, but let's leave for now as it's just for debugging |
||
| return (event: vscode.TextEditorSelectionChangeEvent) => { | ||
| const location = new vscode.Location( | ||
| vscode.window.activeTextEditor!.document.uri, | ||
| event.selections[0] | ||
| ); | ||
|
|
||
| const ancestors: SyntaxNode[] = []; | ||
| let node: SyntaxNode = getNodeAtLocation(location); | ||
| while (node.parent != null) { | ||
| ancestors.unshift(node.parent); | ||
| node = node.parent; | ||
| } | ||
|
|
||
| ancestors.forEach((node, i) => console.debug(">".repeat(i + 1), node.type)); | ||
| const leafText = ancestors[ancestors.length - 1].text | ||
| .replace(/\s+/g, " ") | ||
| .substring(0, 100); | ||
| console.debug(">".repeat(ancestors.length), `"${leafText}"`); | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,41 @@ | ||
| import { SyntaxNode } from "web-tree-sitter"; | ||
| import { TextEditor } from "vscode"; | ||
| import { | ||
| delimitedMatcher, | ||
| hasType, | ||
| simpleSelectionExtractor, | ||
| makeRange, | ||
| childNodeMatcher, | ||
| getNodeWithLeadingDelimiter, | ||
| } from "../nodeMatchers"; | ||
| import { getKeyNode, getValueNode } from "../treeSitterUtils"; | ||
| import { | ||
| delimitedSelector, | ||
| selectWithLeadingDelimiter, | ||
| } from "../nodeSelectors"; | ||
| import { composedMatcher, matcher, typeMatcher } from "../nodeMatchers"; | ||
| import { nodeFinder, typedNodeFinder } from "../nodeFinders"; | ||
|
|
||
| // Matchers for "plain old javascript objects", like those found in JSON | ||
| export function getPojoMatchers( | ||
| dictionaryTypes: string[], | ||
| listTypes: string[], | ||
| listElementMatcher: (node: SyntaxNode) => boolean | ||
| ) { | ||
| return { | ||
| dictionary: hasType(...dictionaryTypes), | ||
| pair: delimitedMatcher( | ||
| (node) => node.type === "pair", | ||
| (node) => node.type === "," || node.type === "}" || node.type === "{", | ||
| ", " | ||
| dictionary: typeMatcher(...dictionaryTypes), | ||
| pair: matcher( | ||
| nodeFinder((node) => node.type === "pair"), | ||
| delimitedSelector( | ||
| (node) => node.type === "," || node.type === "}" || node.type === "{", | ||
| ", " | ||
| ) | ||
| ), | ||
| pairKey(editor: TextEditor, node: SyntaxNode) { | ||
| if (node.type !== "pair") { | ||
| return null; | ||
| } | ||
|
|
||
| return simpleSelectionExtractor(getKeyNode(node)!); | ||
| }, | ||
| value: childNodeMatcher(getValueNode, getNodeWithLeadingDelimiter), | ||
| list: hasType(...listTypes), | ||
| listElement: delimitedMatcher( | ||
| (node) => | ||
| listTypes.includes(node.parent?.type ?? "") && listElementMatcher(node), | ||
| (node) => node.type === "," || node.type === "[" || node.type === "]", | ||
| ", " | ||
| pairKey: composedMatcher([typedNodeFinder("pair"), getKeyNode]), | ||
| value: matcher(getValueNode, selectWithLeadingDelimiter), | ||
| list: typeMatcher(...listTypes), | ||
| listElement: matcher( | ||
| nodeFinder( | ||
| (node) => | ||
| listTypes.includes(node.parent?.type ?? "") && | ||
| listElementMatcher(node) | ||
| ), | ||
| delimitedSelector( | ||
| (node) => node.type === "," || node.type === "[" || node.type === "]", | ||
| ", " | ||
| ) | ||
| ), | ||
| string: hasType("string"), | ||
| string: typeMatcher("string"), | ||
| }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might move the
NodeMatcherabove down to right above this one; it got separated in the rebaseI also might add a docstring for this type and the next one as they're important abstractions