Skip to content

Attempt to be fancy #2

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

Merged
merged 1 commit into from
Jun 29, 2021
Merged

Conversation

pokey
Copy link

@pokey pokey commented Jun 29, 2021

I haven't quite gotten this one working, but any chance you could try this direction? Then we could reuse some of this stuff easily for "name" transformation as well

@@ -3,6 +3,9 @@ import { SyntaxNode } from "web-tree-sitter";
export const getValueNode = (node: SyntaxNode) =>
node.childForFieldName("value");

export const getTypeAnnotationNode = (node: SyntaxNode) =>
node.childForFieldName("type_annotation");
Copy link
Owner

@brxck brxck Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it drove me nuts to figure out, but my understanding is that this won't work.

type_annotation is a named node, but it generally isn't assigned a field name. I don't believe there's an API for accessing nodes by their names.

There are sometimes type fields [1] but unfortunately not in most cases.

export function getNodeWithLeadingDelimiter(
node: SyntaxNode
): SelectionWithContext {
const leadingDelimiterToken = node.previousSibling!;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that the leading delimiter node : is actually a child of the type_annotation node. We can select the correct delimiter node by passing the last child node of type_annotation (which would be predefined_type or type_identifier) to this matcher.

@brxck brxck merged commit 2b23322 into brxck:type-transform Jun 29, 2021
@pokey pokey deleted the type-transform branch August 6, 2021 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants