-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use main_syntax variable to detect embedded syntax (#108)
Our syntax file can be loaded in two ways: as a top-level syntax (e.g. when we're in a 'graphql' buffer) and embedded within an outer ("main") syntax (e.g. within a 'javascript' buffer). The syntax file has some conditional behavior when it's embedded (such as _not_ setting `syn sync`), to avoid infecting the outer context. We were previously using a custom b:graphql_nested_syntax variable to differentiate these cases. There is a more "standard" convention for this that uses a main_syntax global variable, so this change switches the code to use that approach instead. This adds some additional housekeeping steps to our embedding procedure, so this change also introduces a graphql#embed_syntax() helper function that we now use in all of our filetype-specific syntax extension files.
- Loading branch information
Showing
13 changed files
with
53 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,7 @@ | |
" Language: GraphQL | ||
" Maintainer: Jon Parise <[email protected]> | ||
|
||
if exists('b:current_syntax') | ||
let s:current_syntax = b:current_syntax | ||
unlet b:current_syntax | ||
endif | ||
|
||
let b:graphql_nested_syntax = 1 | ||
syn include @GraphQLSyntax syntax/graphql.vim | ||
unlet b:graphql_nested_syntax | ||
|
||
if exists('s:current_syntax') | ||
let b:current_syntax = s:current_syntax | ||
endif | ||
call graphql#embed_syntax('GraphQLSyntax') | ||
|
||
let s:tags = '\%(' . join(graphql#javascript_tags(), '\|') . '\)' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,7 @@ | |
" Language: GraphQL | ||
" Maintainer: Jon Parise <[email protected]> | ||
|
||
if exists('b:current_syntax') | ||
let s:current_syntax = b:current_syntax | ||
unlet b:current_syntax | ||
endif | ||
|
||
let b:graphql_nested_syntax = 1 | ||
syn include @GraphQLSyntax syntax/graphql.vim | ||
unlet b:graphql_nested_syntax | ||
|
||
if exists('s:current_syntax') | ||
let b:current_syntax = s:current_syntax | ||
endif | ||
call graphql#embed_syntax('GraphQLSyntax') | ||
|
||
syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)\@<=\(\"\=\)\z(\(\I\i*\)\=\(gql\)\c\(\i*\)\)\2$" end="^\s*\z1\>" contained contains=@GraphQLSyntax,phpIdentifier,phpIdentifierSimply,phpIdentifierComplex,phpBackslashSequences,phpMethodsVar,@Spell keepend extend | ||
syntax region phpNowDoc matchgroup=Delimiter start="\(<<<\)\@<='\z(\(\I\i*\)\=\(gql\)\c\(\i*\)\)'$" end="^\s*\z1\>" contained contains=@GraphQLSyntax,@Spell keepend extend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,7 @@ | |
" Language: GraphQL | ||
" Maintainer: Jon Parise <[email protected]> | ||
|
||
if exists('b:current_syntax') | ||
let s:current_syntax = b:current_syntax | ||
unlet b:current_syntax | ||
endif | ||
|
||
let b:graphql_nested_syntax = 1 | ||
syn include @GraphQLSyntax syntax/graphql.vim | ||
unlet b:graphql_nested_syntax | ||
|
||
if exists('s:current_syntax') | ||
let b:current_syntax = s:current_syntax | ||
endif | ||
call graphql#embed_syntax('GraphQLSyntax') | ||
|
||
syntax region graphqlExtensionPoint start=+\[%\(graphql\|relay\)+ end=+\]+ contains=graphqlExtensionPointS | ||
syntax region graphqlExtensionPointS matchgroup=String start=+{|+ end=+|}+ contains=@GraphQLSyntax contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,7 @@ | |
" Language: GraphQL | ||
" Maintainer: Jon Parise <[email protected]> | ||
|
||
if exists('b:current_syntax') | ||
let s:current_syntax = b:current_syntax | ||
unlet b:current_syntax | ||
endif | ||
|
||
let b:graphql_nested_syntax = 1 | ||
syn include @GraphQLSyntax syntax/graphql.vim | ||
unlet b:graphql_nested_syntax | ||
|
||
if exists('s:current_syntax') | ||
let b:current_syntax = s:current_syntax | ||
endif | ||
call graphql#embed_syntax('GraphQLSyntax') | ||
|
||
syntax region graphqlExtensionPoint start=+%\(graphql\|relay\)(+ end=+)+ contains=graphqlExtensionPointS | ||
syntax region graphqlExtensionPointS matchgroup=String start=+`+ end=+`+ contains=@GraphQLSyntax contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,18 +21,7 @@ | |
" Language: GraphQL | ||
" Maintainer: Jon Parise <[email protected]> | ||
|
||
if exists('b:current_syntax') | ||
let s:current_syntax = b:current_syntax | ||
unlet b:current_syntax | ||
endif | ||
|
||
let b:graphql_nested_syntax = 1 | ||
syn include @GraphQLSyntax syntax/graphql.vim | ||
unlet b:graphql_nested_syntax | ||
|
||
if exists('s:current_syntax') | ||
let b:current_syntax = s:current_syntax | ||
endif | ||
call graphql#embed_syntax('GraphQLSyntax') | ||
|
||
let s:tags = '\%(' . join(graphql#javascript_tags(), '\|') . '\)' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,11 @@ | |
" Language: GraphQL | ||
" Maintainer: Jon Parise <[email protected]> | ||
|
||
if exists('b:current_syntax') | ||
finish | ||
if !exists('main_syntax') | ||
if exists('b:current_syntax') | ||
finish | ||
endif | ||
let main_syntax = 'graphql' | ||
endif | ||
|
||
syn case match | ||
|
@@ -72,6 +75,10 @@ syn keyword graphqlMetaFields __schema __type __typename | |
syn region graphqlFold matchgroup=graphqlBraces start="{" end="}" transparent fold contains=ALLBUT,graphqlStructure | ||
syn region graphqlList matchgroup=graphqlBraces start="\[" end="]" transparent contains=ALLBUT,graphqlDirective,graphqlStructure | ||
|
||
if main_syntax ==# 'graphql' | ||
syn sync minlines=500 | ||
endif | ||
|
||
hi def link graphqlComment Comment | ||
hi def link graphqlOperator Operator | ||
|
||
|
@@ -91,8 +98,8 @@ hi def link graphqlStructure Structure | |
hi def link graphqlType Type | ||
hi def link graphqlVariable Identifier | ||
|
||
if !get(b:, 'graphql_nested_syntax') | ||
syn sync minlines=500 | ||
endif | ||
|
||
let b:current_syntax = 'graphql' | ||
|
||
if main_syntax ==# 'graphql' | ||
unlet main_syntax | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters