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

Add support for b:graphql_javascript_tags #100

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const query = gql`
```

The list of recognized tag names is defined by the `g:graphql_javascript_tags`
variable, which defaults to `["gql", "graphql", "Relay.QL"]`.
variable, which defaults to `["gql", "graphql", "Relay.QL"]`. This can also
be set on a per-buffer basis using `b:graphql_javascript_tags`.

You can also add a `# gql` or `# graphql` comment at the start of a template
string to indicate that its contents should be considered GraphQL syntax.
Expand Down
8 changes: 7 additions & 1 deletion autoload/graphql.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
" Language: GraphQL
" Maintainer: Jon Parise <[email protected]>

" Look up the named variable in buffer scope and then in global scope.
" Returns default if the named variable can't be found in either.
function! graphql#var(name, default) abort
return get(b:, a:name, get(g:, a:name, a:default))
endfunction

function! graphql#has_syntax_group(group) abort
try
silent execute 'silent highlight ' . a:group
Expand All @@ -31,5 +37,5 @@ function! graphql#has_syntax_group(group) abort
endfunction

function! graphql#javascript_tags() abort
return get(g:, 'graphql_javascript_tags', ['gql', 'graphql', 'Relay.QL'])
return graphql#var('graphql_javascript_tags', ['gql', 'graphql', 'Relay.QL'])
endfunction
1 change: 1 addition & 0 deletions doc/graphql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ supported.
*graphql-javascript-options*

*g:graphql_javascript_tags*
*b:graphql_javascript_tags*
|g:graphql_javascript_tags| list of strings

Default: `["gql", "graphql", "Relay.QL"]`
Expand Down
17 changes: 17 additions & 0 deletions test/var.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Before:
let g:graphql_some_variable = 'abc'

After:
unlet! g:graphql_some_variable
unlet! b:undefined_variable_name

Execute(graphql#var should return global variables):
AssertEqual 'abc', graphql#var('graphql_some_variable', '')

Execute(graphql#var should return buffer overrides):
let b:graphql_some_variable = 'def'

AssertEqual 'def', graphql#var('graphql_some_variable', '')

Execute(graphql#var should return default value for undefined variables):
AssertEqual 'default', graphql#var('undefined_variable_name', 'default')