Skip to content

Implement external scanner for raw_text #15

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 3 commits into from
Mar 20, 2025

Conversation

mogstad
Copy link
Contributor

@mogstad mogstad commented Mar 20, 2025

Same as ember-tooling/tree-sitter-glimmer-typescript#10, but moved the upstream parser into src/tree-sitter-javascript/scanner.h to make it easier to keep up with changes upstream. This partly matches what’s already in place for tree-sitter-glimmer-typescript.

//
// To Update:
// - delete everything under the comment block
// - find and replace "tree_sitter_javascript" with "tree_sitter_javascript"
Copy link
Member

Choose a reason for hiding this comment

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

seems like something went wrong here 🙃 haha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure did! Will update.

JSX_TEXT,
};

void *tree_sitter_javascript_external_scanner_create() { return NULL; }
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't these be tree_sitter_glimmer_javascript?

Copy link
Member

Choose a reason for hiding this comment

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

maybe it doesn't matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment these aren’t in use, and duplicated version with glimmer_javascript are in scanner.c.

I see three options; leave them, call them, or remove them.

I thought it would be nice to have the ability to just copy paste scanner.c from GitHub into scanner.h. So maybe best to just call them from scanner.c?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are now called from scanner.c

Copy link
Member

Choose a reason for hiding this comment

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

yea, copy-paste ability is very nice

mogstad added 3 commits March 20, 2025 16:53
To simplify having a custom external scanner, I've moved JS scanner into
`tree-sitter-javascript/scanner.h`. This will allow us to have custom
scanner implementation and still allow us to easily update the upstream
scanner.
It allows greater control and allows us to expose more of the template.
External scanner seems to be the way if we want to expose more than just
the `<template>` token.

This obviously makes it more tedious to update the upstream TypeScript
grammar. Especially the `GlimmerTokenType` which must continue the
sequence of the parent's TokenType.
Some editor features requires the abillity to capture the brackets
independent from the tag name. e.g. Zed captures `<` as brackets and
highlight them different from the tag name. It uses it to highlight the
opposite opening/closing pair when the cursor is on one of the brackets.
@mogstad mogstad force-pushed the push-nrwrmwwzrtvk branch from 07f27d5 to 7688609 Compare March 20, 2025 15:54
@NullVoxPopuli
Copy link
Member

thank you!!!

@NullVoxPopuli NullVoxPopuli merged commit babba3f into ember-tooling:main Mar 20, 2025
7 checks passed
@github-actions github-actions bot mentioned this pull request Mar 20, 2025
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