Re: [vim/vim] TypeScript syntax highlighting broken on template literals (Issue #9772)

77 views
Skip to first unread message

Konrad Höffner

unread,
Feb 14, 2022, 7:20:37 AM2/14/22
to vim/vim, Subscribed

vim-typescript-syntax-highlighting-bug


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1039021816@github.com>

Konrad Höffner

unread,
Feb 14, 2022, 7:28:53 AM2/14/22
to vim/vim, Subscribed

Steps to reproduce

  1. Save save the following file as test.ts and open it in Vim`:
const x =
{
    onClickFunction: (event) => {
    const body = `${x}`;
    thisFunctionIsShownAsLiteralButItIsntOne();
};

Expected behaviour

The line thisFunctionIsShownAsLiteralButItIsntOne(); should be highlighted as a function but it is shown as a literal.
The error happens in nvim as well so I assume this is an bug in the style file of TypeScript.
With :set syntax=javascript the highlighting is correct.

Version of Vim

8.2.4106

Environment

Operating System: Arch Linux
Terminal: GNOME Terminal 3.42.2 for GNOME 41
Value of $TERM: xterm-256color
Shell: zsh 5.8.
vim-typescript-syntax-highlighting-bug
1

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772@github.com>

lacygoill

unread,
Feb 14, 2022, 7:48:16 AM2/14/22
to vim/vim, Subscribed

I can't reproduce:

gif

Try to reproduce without config:

$ vim --clean test.ts

If you can still reproduce, try again on master. 8.2.4106 is quite recent, but there probably has been an update of the runtime files since then.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1039025621@github.com>

lacygoill

unread,
Feb 14, 2022, 8:04:34 AM2/14/22
to vim/vim, Subscribed

Although, the syntax file changes the value of the 'iskeyword' option. Instead, it should use the iskeyword syntax variant:

diff --git a/runtime/syntax/typescriptcommon.vim b/runtime/syntax/typescriptcommon.vim
index ef362fc72..aebdc4509 100644
--- a/runtime/syntax/typescriptcommon.vim
+++ b/runtime/syntax/typescriptcommon.vim
@@ -22,7 +22,7 @@ if main_syntax == 'typescript' || main_syntax == 'typescriptreact'
   " syntax cluster htmlJavaScript                 contains=TOP
 endif
 " For private field added from TypeScript 3.8
-setlocal iskeyword+=#
+execute 'syntax iskeyword ' .. &l:iskeyword .. ',#'
 
 " lowest priority on least used feature
 syntax match   typescriptLabel                /[a-zA-Z_$]\k*:/he=e-1 contains=typescriptReserved nextgroup=@typescriptStatement skipwhite skipempty


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1039028460@github.com>

Bram Moolenaar

unread,
Feb 14, 2022, 8:36:24 AM2/14/22
to vim/vim, Subscribed

You are not using the syntax file from the distribution. Notice that "const body" has "body" highlighted, for me it isn't.
You must have extra highlighting set at least.
Try starting with "vim --clean".


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1039056757@github.com>

Konrad Höffner

unread,
Feb 15, 2022, 4:04:56 AM2/15/22
to vim/vim, Subscribed

When using vim --clean, the error goes away. I will try to figure out what causes it.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1040024116@github.com>

lacygoill

unread,
Feb 15, 2022, 5:14:18 AM2/15/22
to vim/vim, Subscribed

Is it working as intended that this changes syntax highlighting?

I don't know. At least it's documented at :help 'iskeyword':

This option also influences syntax highlighting, unless the syntax
uses |:syn-iskeyword|.

FWIW, I think a syntax plugin should not change any option which could be set in a filetype plugin.

This patch would probably fix the issue:

diff --git a/runtime/syntax/typescriptcommon.vim b/runtime/syntax/typescriptcommon.vim
index ef362fc72..1cae4a443 100644
--- a/runtime/syntax/typescriptcommon.vim
+++ b/runtime/syntax/typescriptcommon.vim
@@ -15,14 +15,14 @@ endif
 " NOTE: this results in accurate highlighting, but can be slow.
 syntax sync fromstart
 
-"Dollar sign is permitted anywhere in an identifier
-setlocal iskeyword-=$
 if main_syntax == 'typescript' || main_syntax == 'typescriptreact'
-  setlocal iskeyword+=$
+  " Dollar sign is permitted anywhere in an identifier
+  " # for private field added from TypeScript 3.8
+  syntax iskeyword @,48-57,_,128-167,224-235,$,#
   " syntax cluster htmlJavaScript                 contains=TOP
+else
+  syntax iskeyword @,48-57,_,128-167,224-235,#
 endif
-" For private field added from TypeScript 3.8
-setlocal iskeyword+=#
 
 " lowest priority on least used feature
 syntax match   typescriptLabel                /[a-zA-Z_$]\k*:/he=e-1 contains=typescriptReserved nextgroup=@typescriptStatement skipwhite skipempty

Instead of adding characters to the current value of the buffer-local option 'iskeyword', it adds them to the the Vim default, and assign the result to the syntax-local option.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1040091005@github.com>

lacygoill

unread,
Feb 15, 2022, 6:04:02 AM2/15/22
to vim/vim, Subscribed

Ah, I wrongly copied the default value for Win32. We would need to test whether we are on a Windows system first. Otherwise, the default is:

@,48-57,_,192-255


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1040138446@github.com>

lacygoill

unread,
Feb 15, 2022, 6:08:01 AM2/15/22
to vim/vim, Subscribed

Here is a new try:

diff --git a/runtime/syntax/typescriptcommon.vim b/runtime/syntax/typescriptcommon.vim
index ef362fc72..4a8c91cdc 100644
--- a/runtime/syntax/typescriptcommon.vim
+++ b/runtime/syntax/typescriptcommon.vim
@@ -15,14 +15,22 @@ endif
 " NOTE: this results in accurate highlighting, but can be slow.
 syntax sync fromstart
 
-"Dollar sign is permitted anywhere in an identifier
-setlocal iskeyword-=$
 if main_syntax == 'typescript' || main_syntax == 'typescriptreact'
-  setlocal iskeyword+=$
+  " Dollar sign is permitted anywhere in an identifier
+  " # for private field added from TypeScript 3.8
+  if has('win32')
+    syntax iskeyword @,48-57,_,128-167,224-235,#,$
+  else
+    syntax iskeyword @,48-57,_,192-255,#,$
+  endif
   " syntax cluster htmlJavaScript                 contains=TOP
+else
+  if has('win32')
+    syntax iskeyword @,48-57,_,128-167,224-235,#
+  else
+    syntax iskeyword @,48-57,_,192-255,#
+  endif
 endif
-" For private field added from TypeScript 3.8
-setlocal iskeyword+=#
 
 " lowest priority on least used feature
 syntax match   typescriptLabel                /[a-zA-Z_$]\k*:/he=e-1 contains=typescriptReserved nextgroup=@typescriptStatement skipwhite skipempty


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1040142098@github.com>

Bram Moolenaar

unread,
Feb 15, 2022, 9:03:42 AM2/15/22
to vim/vim, Subscribed

Please suggest changes to the Typescript syntax at
https:github.com/HerringtonDarkholme/yats.vim


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9772/1040311154@github.com>

Bram Moolenaar

unread,
Feb 15, 2022, 9:03:44 AM2/15/22
to vim/vim, Subscribed

Closed #9772.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/9772/issue_event/6075192601@github.com>

Reply all
Reply to author
Forward
0 new messages