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

fix: Fix vscode-graphql-syntax’s grammar to support string literals on separate lines [Reapply & Fix] #3545

Merged
merged 4 commits into from Mar 16, 2024

Conversation

kitten
Copy link
Contributor

@kitten kitten commented Mar 2, 2024

Resolves #3542
Reapplies: #3518
Related: #3543

The previous implementation for GraphQL template string literals inside function expression caused a subtle error in syntax highlighting.

Because it used a positive lookbehind that contained whitespace matches, this caused an issue with syntax matching, which breaks subsequent TS/JS rules from matching. In other words, it caused a conflict between built-in highlighting and the embedded GraphQL highlighting.

Instead of this, we now match the function expressions explicitly, and include JS/TS rules inside the match to also fix arguments that live alongside the GraphQL template string.

Fixed syntax highlighting with this PR applied

Copy link

changeset-bot bot commented Mar 2, 2024

🦋 Changeset detected

Latest commit: 1bd052b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
vscode-graphql-syntax Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten changed the title Fix/graphql syntax newlines reapply fix: Fix vscode-graphql-syntax’s grammar to support string literals on separate lines [Reapply & Fix] Mar 2, 2024
@kitten
Copy link
Contributor Author

kitten commented Mar 2, 2024

Zip containing a vsix file for testing these changes: vscode-graphql-syntax-1.3.4.vsix.zip

@acao
Copy link
Member

acao commented Mar 3, 2024

thank you @kitten !!! looks awesome!

…n separate lines (graphql#3518)

* Allow newlines after `graphql(` before start of query string
* Fix mistaken reverse order of optional `(` and generic `<.*>`
* Replace `(` in second match with newline one
* Match graphql calls separately for string literals inside calls
* Add missing endCaptures to new rule
Using a positive lookbehind can subtly break Textmate/VSCode’s syntax
highlighting. The positive lookbehind (according to some online sources)
can fail unexpectedly when they contain whitespace matches.

This means that we should instead match explicitly, like the other
patterns do. This means however, that we might match too much and
I noticed that arguments to the function aren't highlighted correctly.

According to the interpolation rule in `graphql.json` we now include
patterns for JS/TS/etc as a fallback pattern.

This fixes the issue and prevents the case where the rule was
conflicting with normal JS/TS patterns in a different tmLanguage
grammar.
@kitten kitten force-pushed the fix/graphql-syntax-newlines-reapply branch from 562499c to 1bd052b Compare March 11, 2024 10:05
@kitten
Copy link
Contributor Author

kitten commented Mar 11, 2024

Rebased & reverted changes to tests/__fixtures/test-js.md

Copy link
Member

@acao acao left a comment

Choose a reason for hiding this comment

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

Ok let's do this again!

If there are any more edge case bugs this time, instead of reverting we will create new tests and solve the issues as they arise

@acao acao merged commit e9fc21a into graphql:main Mar 16, 2024
14 checks passed
@acao acao mentioned this pull request Mar 16, 2024
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.

[lsp-server] 🐞 regression: syntax highlighting messed up
2 participants