MaxMEllon / vim-jsx-pretty

:flashlight: [Vim script] JSX and TSX syntax pretty highlighting for vim.
MIT License
966 stars 39 forks source link

Broken .tsx highlighting for arrow functions using generics #154

Open noahbrenner opened 2 years ago

noahbrenner commented 2 years ago

I'm running into inconsistencies in highlighting between ft=typescript and ft=typescriptreact.

I'm using yats.vim, vim-javascript, and of course vim-jsx-pretty, all just updated using vim-plug.

Some example code:

const doFoo = <K extends keyof Foo>(key: K, value: Foo[K], foos: Foo[]) => {
  foos[0][key] = value;
};

const doBar = (bar: string) => {
  return bar;
};

For simple generics, I can get away with just using T for now, but that's not always the best type variable to use, doesn't cover functions that need more than one generic parameter, and is still missing highlighting for the type parameters themselves.

wchargin commented 3 weeks ago

I'm also running into this.

Here's a hacky one-line patch to broaden it to at least accept [A-Z] instead of just T:

diff --git a/after/syntax/jsx_pretty.vim b/after/syntax/jsx_pretty.vim
index 74b200c..71e97d3 100644
--- a/after/syntax/jsx_pretty.vim
+++ b/after/syntax/jsx_pretty.vim
@@ -3,5 +3,5 @@ let s:highlight_close_tag = get(g:, 'vim_jsx_pretty_highlight_close_tag', 0)
 " detect jsx region
 syntax region jsxRegion
-      \ start=+\%(\%(\_[([,?:=+\-*/>{}]\|<\s\+\|&&\|||\|=>\|\<return\|\<default\|\<await\|\<yield\)\_s*\)\@<=<\_s*\%(>\|\z(\%(script\|\s*\<T\>\)\@!\<[_$A-Za-z][-:._$A-Za-z0-9]*\>\)\%(\_s*\%([-+*)\]}&|?,]\|/\%([/*]\|\_s*>\)\@!\)\)\@!\)+
+      \ start=+\%(\%(\_[([,?:=+\-*/>{}]\|<\s\+\|&&\|||\|=>\|\<return\|\<default\|\<await\|\<yield\)\_s*\)\@<=<\_s*\%(>\|\z(\%(script\|\s*\<[A-Z]\>\)\@!\<[_$A-Za-z][-:._$A-Za-z0-9]*\>\)\%(\_s*\%([-+*)\]}&|?,]\|/\%([/*]\|\_s*>\)\@!\)\)\@!\)+
       \ end=++
       \ contains=jsxElement