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

Highlight within javascript tagged template strings #6

Closed
sj26 opened this issue Jul 21, 2017 · 2 comments
Closed

Highlight within javascript tagged template strings #6

sj26 opened this issue Jul 21, 2017 · 2 comments
Labels

Comments

@sj26
Copy link

sj26 commented Jul 21, 2017

I've been using something like this in after/syntax/javascript/graphql.vim attempting to highlight graphql as tagged template literals within javascript files using @pangloss' vim-javascript:

if exists('b:current_syntax')
  let s:current_syntax=b:current_syntax
  unlet b:current_syntax
endif
syn include @jsGraphql syntax/graphql.vim
if exists('s:current_syntax')
  let b:current_syntax=s:current_syntax
endif

syntax match   jsTaggedTemplateGraphql "\(graphql\|Relay\.QL\)\%(`\)\@=" nextgroup=jsTemplateStringGraphql
syntax region  jsTemplateStringGraphql start="`" end="`" contains=jsTemplateExpression,jsSpecial,@jsGraphql extend contained
syntax cluster jsExpression add=jsTaggedTemplateGraphql

hi def link jsTaggedTemplateGraphql jsTaggedTemplate
hi def link jsTemplateStringGraphql jsTemplateString

It works for Relay.QL or graphql tagged template strings:

export default Relay.createContainer(MyComponent, {
  fragments: {
    root: => Relay.QL`
      fragment on MyType {
        field
        anotherField
        connection {
          moreFields
        }
      }
    `
  }
})

This sort-of works. It doesn't recognise javascript template expressions correctly, i.e. in graphql`foo ${bar} baz` bar isn't parsed as javascript, it just continues to parse them as graphql varables/constants, and I can't figure that out.

It might be nice if there were support built-in here!

@jparise
Copy link
Owner

jparise commented Jul 21, 2017

This is similar to #1, yes?

@sj26
Copy link
Author

sj26 commented Jul 21, 2017

Yes, sorry, I didn't see the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants