jparise / vim-graphql

A Vim plugin that provides GraphQL file detection, syntax highlighting, and indentation.
MIT License
487 stars 25 forks source link

Recognize GraphQL strings passed to JavaScript functions #109

Closed jparise closed 1 month ago

jparise commented 1 month ago

Some JavaScript GraphQL frameworks use well-known functions rather than tagged template literals. This change introduces basic support for these cases via a new g:graphql_javascript_functions variable (["graphql"]).

This is implemented as a bit of a hack on top of the existing tagged template support to avoid introducing new syntax regions:

Tagged template:    graphql`
Function call:      graphql(`
Syntax pattern:     (graphql|graphql\()`

This is a good-enough place to start, and the overall approach gives us room to iterate later if we want to revisit the implementation.

Resolves #96

vieira commented 2 days ago

@jparise, thanks for your work on this plugin! I was testing this specific feature and noticed that when using graphql(``) the closing parenthesis seems be highlighted as an error.

I then noticed that in the README and the tests you omit the closing parenthesis and use it like graphql(``; but this does not seem to be valid javascript?

Not sure if this is a bug or if I'm missing something.