Skip to content
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

Semantic Tokenizer #615

Merged
merged 16 commits into from
Jul 19, 2023
Merged

Semantic Tokenizer #615

merged 16 commits into from
Jul 19, 2023

Conversation

gdotdesign
Copy link
Member

@gdotdesign gdotdesign commented Jun 13, 2023

This PR adds support for semantic tokenizer for the language server and also for other uses.

Features:

  • Language Server - syntax highlighting for code editors
  • highlight command - syntax highlight specific files in the terminal or as HTML files
  • @highlight language feature - same as @format but also highlights the given code as HTML

Fixes:

  • Parsed nodes are kept in the ast.nodes array when parsing a parent node fails.

Future work:

This can be used to provide syntax highlighted error messages 🎉

@gdotdesign gdotdesign added language Language feature tooling Tooling related feature (formatter, documentation, production builder) labels Jun 13, 2023
@gdotdesign gdotdesign added this to the 0.19.0 milestone Jun 13, 2023
@gdotdesign gdotdesign self-assigned this Jun 13, 2023
src/commands/highlight.cr Outdated Show resolved Hide resolved
src/parser.cr Outdated Show resolved Hide resolved
src/parsers/type_id.cr Outdated Show resolved Hide resolved
src/parsers/type_id.cr Outdated Show resolved Hide resolved
src/commands/highlight.cr Outdated Show resolved Hide resolved
src/ast/html_component.cr Show resolved Hide resolved
src/ls/semantic_tokens.cr Outdated Show resolved Hide resolved
src/commands/highlight.cr Outdated Show resolved Hide resolved
src/ls/definition/type_id.cr Outdated Show resolved Hide resolved
src/commands/highlight.cr Outdated Show resolved Hide resolved
src/ls/definition/type_id.cr Outdated Show resolved Hide resolved
src/ls/initialize.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
@gdotdesign gdotdesign requested review from Sija and jansul July 18, 2023 15:28
@gdotdesign gdotdesign marked this pull request as ready for review July 18, 2023 15:28
src/lsp/protocol/semantic_tokens_client_capabilities.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
src/semantic_tokenizer.cr Outdated Show resolved Hide resolved
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
@gdotdesign gdotdesign requested a review from Sija July 19, 2023 07:25
Copy link
Member

@Sija Sija left a comment

Choose a reason for hiding this comment

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

@gdotdesign gdotdesign merged commit 1a9f3f4 into master Jul 19, 2023
4 checks passed
@gdotdesign gdotdesign deleted the semantic-tokens branch July 19, 2023 09:55
Copy link
Contributor

@jansul jansul left a comment

Choose a reason for hiding this comment

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

Looking forward to trying this out 😄

Only general comment is that it might be useful to have a couple of tests for the highlighter, formatter, new definition etc. But otherwise LGTM!

"[#{content}, _h(React.Fragment, {}, [#{mapped.join(",\n")}])]"
end

def escape_for_javascript(value : String)
Copy link
Contributor

Choose a reason for hiding this comment

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

May be worth adding this as a method on the JS renderer? js.string() or similar? (I'm assuming value here is the rendered HTML?)

Although if this the only use might be overkill 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know where would it be better 🤷 It's only used in the compiler but js is only used in the compiler as well 😄

@jansul
Copy link
Contributor

jansul commented Jul 19, 2023

Woops too slow 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Language feature tooling Tooling related feature (formatter, documentation, production builder)
Development

Successfully merging this pull request may close these issues.

3 participants