jparise/vim-graphql

Referencing a variable in template literal breaks syntax highlighting for rest of file

jesstelford opened this issue · 4 comments

For example, with this code:

return gql`
  {
    _get${name} {
      id
    }
  }
`;

I get:

screen shot 2018-06-08 at 9 46 47 am

However, removing the ${name} variable, I get the correct behaviour:

screen shot 2018-06-08 at 9 47 02 am

Some quick debugging:

For the buggy behaviour, the function keyword has the following syntax highlighting group:

hi<graphqlName> trans<graphqlName> lo<GruvboxBlue>

On the working example, that same function keyword has:

hi<jsFunction> trans<jsFunction> lo<GruvboxAqua>

On the

Vim Version

$ nvim --version
NVIM v0.2.3-dev
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -I/tmp/neovim-20180320-42675-1qez91d/build/config -I/tmp/neovim-20180320-42675-1qez91d/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim-20180320-42675-1qez91d/build/src/nvim/auto -I/tmp/neovim-20180320-42675-1qez91d/build/include
Compiled by jess@Jesss-MBP.lan
Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"
   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-739fb93_1/share/nvim"
Run :checkhealth for more info

It looks like it's treating the ${...} as a query block, then encountering the next { and blowing up, because it's expecting a name to be there.

For example, this highlights correctly (but is invalid syntax):

return gql`
  {
    _get${name} foo {
      id
    }
  }
`;

Note also: this used to work. I pulled the latest changes today, and that's when I noticed things not working. Unfortunately, I don't know what commit I was on previously.

I'm pretty sure this is now fixed, but I also noticed that the embedded expression (e.g. ${...}) isn't highlighted as JavaScript syntax. Instead, it renders as a graphqlName. That's not wrong, but it would be nice if the syntaxes "nested" correctly here, which is the intention.

I spent a little time looking into that but couldn't find a solution. I'll try to revisit it soon.

I just pushed a35e0da, which I believe addresses that one outstanding issue: expression interpolation within template strings is now correctly highlighted as JavaScript (or TypeScript) syntax.