Skip to content

Add language support for GYB #1515

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

fpseverino
Copy link

Add syntax highlighting and language configuration for Swift GYB (.swift.gyb) files.

Motivation:

Resolves #1455

Language support for GYB can't be implemented via sourcekit-lsp, as GYB can contain arbitrary Python.

The TextMate grammar can't be an injection grammar because GYB files have a different file extension from normal Swift files, and also because sourcekit-lsp would activate and throw a lot of errors.

Additions:

  • New swift-gyb language in package.json
  • Language configuration for Swift GYB with code folding, brackets definition and autoclosing
  • TextMate grammar for Swift GYB
  • Icons for .swift.gyb files

Known issues:

  • GYB code blocks (%{...}%) and control statements (% keyword: ... % end) are not always highlighted when they are inside Swift bodies (structs, extensions and funcs, in other words when not in the top level of the file)
  • Swift keywords are not always correctly highlighted when the preceding structure, function or variable name starts with a GYB block

Copy link
Member

@matthewbastien matthewbastien left a comment

Choose a reason for hiding this comment

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

Thank you for putting this together, it's a great start! Unfortunately, I'm no expert when it comes to the language grammars in VS Code. Is there any way we could add tests for this at all?

CI is failing due to formatting issues. You'll want to run the following and push the changes:

npx prettier . --write

The unacceptable language filter also doesn't like the use of the word master in the tmLanguage file. However, since there's no way to get around using that schema, you can add syntaxes/swift-gyb.tmLanguage.json to the .unacceptablelanguageignore file.

@fpseverino
Copy link
Author

Is there any way we could add tests for this at all?

Microsoft recommends using this package to test the grammar.
I will take a closer look at it and try to add tests ASAP.

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.

Language support for GYB
2 participants