-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor transformations and add name transformation (#56)
* Add name field transformation * Add AST debug logging * Add basic name transformation * Refactor matchers to add function name transform * Add missing function name * Clean up transformations refactor * Refactor branch debug logging * Fix purple color setting name * Add function and class name scopes * Fixed name matching for exported/decorated nodes * Clean up transformations refactor (again) Co-authored-by: Pokey Rule <[email protected]>
- Loading branch information
Showing
11 changed files
with
434 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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}"`); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.