diff --git a/CHANGELOG.md b/CHANGELOG.md index c99e577..458fb21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Updated vendored rescript-vscode server to `1.1.2` (see changes [here](https://github.com/rescript-lang/rescript-vscode/blob/master/CHANGELOG.md#112)) - Rename support for let-binding, types, record labels, module names etc - **Important:** If you are using coc.nvim, make sure to upgrade to the latest `release` version first, otherwise renaming will not work across files! +- Improved syntax highlighting for string interpolation ([#44](https://github.com/rescript-lang/vim-rescript/pull/44)) ## 2.0.1 diff --git a/examples/rescript-project/src/interpolationSyntax.res b/examples/rescript-project/src/interpolationSyntax.res new file mode 100644 index 0000000..4691fe4 --- /dev/null +++ b/examples/rescript-project/src/interpolationSyntax.res @@ -0,0 +1,11 @@ +let name = "Amirali" + +let var = `hello ${name} how you doin?` + +let var2 = j`hello ${name} how you doin?` + +let var3 = j`hello $name how you doin?` + +let varInvalid = `hello $name how you doin?` + +let expr = `2 + 2 is ${Int.toString(2 + 2)}` diff --git a/syntax/rescript.vim b/syntax/rescript.vim index bf11b29..ca2ac6c 100644 --- a/syntax/rescript.vim +++ b/syntax/rescript.vim @@ -82,9 +82,11 @@ syntax match resUnicodeChar "\v\\u[A-Fa-f0-9]\{4}" contained syntax match resEscapedChar "\v\\[\\"'ntbrf]" contained syntax region resString start="\v\"" end="\v\"" contains=resEscapedQuote,resEscapedChar,resUnicodeChar +" Interpolation syntax match resInterpolationVariable "\v\$[a-z_][A-Za-z0-0_'$]*" contained -syntax region resString start="\v`" end="\v`" contains=resInterpolationVariable -syntax region resString start="\v[a-z]`" end="\v`" contains=resInterpolationVariable +syntax region resInterpolationBlock matchgroup=resInterpolationDelimiters start="\v\$\{" end="\v\}" contained contains=TOP +syntax region resString start="\v`" end="\v`" contains=resInterpolationBlock +syntax region resString start="\v[a-z]`" end="\v`" contains=resInterpolationBlock,resInterpolationVariable " Polymorphic variants syntax match resPolyVariant "\v#[A-za-z][A-Za-z0-9_'$]*" @@ -109,6 +111,7 @@ highlight default link resModuleChain Macro highlight default link resUnicodeChar Character highlight default link resEscapedChar Character highlight default link resString String +highlight default link resInterpolationDelimiters Macro highlight default link resInterpolationVariable Macro highlight default link resAttribute PreProc