-
-
Notifications
You must be signed in to change notification settings - Fork 84
Refactor transformations and add name transformation #56
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
12ba0df
Add name field transformation
brxck 79ed944
Add AST debug logging
brxck 0a96484
Add basic name transformation
brxck 89e0c85
Refactor matchers to add function name transform
brxck cd7c36a
Add missing function name
pokey b1061eb
Clean up transformations refactor
brxck c77d9f0
Refactor branch debug logging
brxck 9c3b2f1
Fix purple color setting name
brxck 3a79d5d
Add function and class name scopes
brxck 8365b2c
Fixed name matching for exported/decorated nodes
brxck 91f4ade
Clean up transformations refactor (again)
brxck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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) { | ||
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}"`); | ||
}; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
NodeMatcher
above 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