Skip to content

Language support for GYB #1455

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

Open
fpseverino opened this issue Mar 21, 2025 · 6 comments · May be fixed by #1515
Open

Language support for GYB #1455

fpseverino opened this issue Mar 21, 2025 · 6 comments · May be fixed by #1515
Labels
enhancement New feature or request

Comments

@fpseverino
Copy link

Is your feature request related to a problem? Please describe.
When working with .swift.gyb files you need to choose whether to view them as basic text files with no syntax highlighting, or as Swift files, with reasonable syntax highlighting but with many SourceKit-LSP errors.

Describe the solution you'd like
Even just basic TextMate syntax highlighting that extends Swift's and clearly highlights GYB blocks, without any LSP functionality, would be helpful. Also, it would be really nice to add a file icon for GYB that is slightly different than the normal Swift one.

Describe alternatives you've considered
Viewing GYB as basic text files with no syntax highlighting, or as Swift files, with reasonable syntax highlighting but with many SourceKit-LSP errors.

@award999
Copy link
Contributor

We could add the extension to known extensions in package.json, but sourcekit-lsp would need to support the highlighting ideally

@award999 award999 moved this from Backlog to Todo in Swift Extension for Visual Studio Code Mar 21, 2025
@fpseverino
Copy link
Author

Do you think it's worth adding it as a TextMate grammar in the meantime?
Also, would adding GYB support in SourceKit-LSP be accepted or would it be out of scope?

@matthewbastien
Copy link
Member

Do you think it's worth adding it as a TextMate grammar in the meantime?

That would work for the syntax highlighting in the meantime, yeah. Not sure how difficult it would be to extend the existing Swift textmate grammar.

Also, would adding GYB support in SourceKit-LSP be accepted or would it be out of scope?

@ahoppen is this something you'd consider adding to SourceKit-LSP?

@fpseverino
Copy link
Author

Not sure how difficult it would be to extend the existing Swift textmate grammar.

I recently wrote an extension that extends the HTML grammar to support Vapor's templating language Leaf, it's just a matter of writing good regular expressions, and given the structure of GYB I don't think it would be too difficult.

@ahoppen
Copy link
Member

ahoppen commented Mar 21, 2025

We are not planning to add gyb support to SourceKit-LSP. GYB can contain arbitrary Python, which can be nearly impossible to process for semantic information.

Not sure if it’s possible, but maybe a middle ground cold be to allow VS Code to use it’s grammar-based syntax highlighting for gyb files but not open them in SourceKit-LSP? That way you get at least some syntax coloring and we don’t try to provide semantic functionality that would only fail.

@fpseverino fpseverino linked a pull request Apr 22, 2025 that will close this issue
4 tasks
@fpseverino
Copy link
Author

I opened a draft PR that adds syntax highlighting for GYB.

There are still known issues (which I mention in the PR).
I will continue to work on it, and would greatly appreciate an outside look.

If you want to know the reason behind the choices I made please ask me here or in the PR comments!

P.S. I would love to give GYB files a customised icon, I was thinking of Swift's icon but greyed out, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

4 participants