Skip to content

Ability to customize tags #3

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Ability to customize tags
  • Loading branch information
trsdln committed Nov 10, 2020
commit 698ad18c3aba2dc753b173344340bf63065ffb1e
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ This plugin uses the generic SQL syntax by default. If you want to use a differe
```vim
let g:javascript_sql_dialect = 'pgsql'
```

List of tags can be overridden using:

```vim
let g:javascript_sql_tags = ['sql', 'customSql']
" default is ['SQL']
```
8 changes: 7 additions & 1 deletion after/syntax/javascript/sql.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ if exists('b:current_syntax')
unlet b:current_syntax
endif

if !exists('g:javascript_sql_tags')
let g:javascript_sql_tags = ['SQL']
endif

exec 'syntax include @SQLSyntax syntax/' . g:javascript_sql_dialect . '.vim'
if exists('s:current_syntax')
let b:current_syntax = s:current_syntax
endif

let s:tags_regex = join(g:javascript_sql_tags, '\|')

syntax region sqlTemplateString start=+`+ skip=+\\\(`\|$\)+ end=+`+ contains=@SQLSyntax,jsTemplateExpression,jsSpecial extend
exec 'syntax match sqlTaggedTemplate +\%(SQL\)\%(`\)\@=+ nextgroup=sqlTemplateString'
exec 'syntax match sqlTaggedTemplate +\%(' . s:tags_regex . '\)\%(`\)\@=+ nextgroup=sqlTemplateString'

hi def link sqlTemplateString jsTemplateString
hi def link sqlTaggedTemplate jsTaggedTemplate
Expand Down