-
Notifications
You must be signed in to change notification settings - Fork 142
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
Override neovim 0.5.0 and up's typescript support #193
Conversation
This version of neovim has the same typescript support as vim 8 patch-8.1.1486, so we should override it as well.
Unsure if this will get merged but figured I'd at least put up an attempt at a simple fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this.
This change broke my syntax highlighting. I am on neovim 0.7.0 and using base16-one-light theme. When I open a typescript file, it has no syntax highlighting. Strangely enough, if I run Minimal vimrc: call plug#begin(stdpath('data') . '/plugged')
Plug 'chriskempson/base16-vim' " Base16 color scheme
Plug 'leafgarland/typescript-vim' " Typescript syntax
call plug#end()
colorscheme base16-one-light Typescript file: class Foo {} Result of After some further investigation into base16 colorscheme, I found that it resets the highlight syntax with |
Does this only happen when you open a TypeScript file on startup ( What stands out to me is that I feel like |
This only happens when I open a ts file on startup. If I open another typescript file within neovim, the problem goes away. It looks like the typescript file is being sourced after the base16 colorscheme:
It's a very strange issue. I can't seem to figure it out. |
Thanks! The color scheme is being sourced first, but I wonder if it's being set after (in your minimal config with I also had some (different) issues with syntax highlighting, but after switching to packer as a plugin manager they seemed to go away. I think this is because packer uses the built-in package support in vim and loads my colorscheme config (under Does doing |
I couldn't find a way to get the colorscheme to be sourced before the ftdetect. I've given up debugging this since it seems that sourcing the colorscheme manually before everything else works: source ~/.local/share/nvim/plugged/base16-vim/colors/base16-one-light.vim |
👋🏻 I ran into some similar breakage and In my case, I have some overengineered garbage in my dotfiles that uses I can see in the Now, I don't know whether
and that makes it pretty clear that the reason why the So with that context, I'm trying to understand the intent of the if version >= 508 || !exists("did_typescript_syn_inits")
if version < 508 || has('patch-8.1.1486') || has('nvim-0.5.0')
let did_typescript_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
" ... etc It seems to be "don't rerun the
So, on Neovim, we're now getting non-default highlight links, which is why they get blown away by If I grok the conditionals correctly, we're using In short, I have more questions than answers 🤣. For now, my work around is going to be to apply a small patch to my local copy of typescript-vim (to always use if version < 508
command -nargs=+ HiLink hi link <args>
elseif version >= 508
command -nargs=+ HiLink hi def link <args>
endif Out of curiosity, I went to see what another popular filetype plugin does which overrides styles set by the default bundled with Vim/Neovim's hi def link markdownH1 htmlH1
hi def link markdownH2 htmlH2
hi def link markdownH3 htmlH3
hi def link markdownH4 htmlH4
hi def link markdownH5 htmlH5
hi def link markdownH6 htmlH6
" etc... And if we look at a popular alternative, plasticboy/vim-markdown, that also favors " don't use standard HiLink, it will not work with included syntax files
if v:version < 508
command! -nargs=+ HtmlHiLink hi link <args>
else
command! -nargs=+ HtmlHiLink hi def link <args>
endif which lines up with my suggestion above. Would you be open to a PR for that? Update: As it was very cheap to do so, sent the PR. Footnotes |
Implements the suggestion posted in: leafgarland#193 (comment) Which aligns the plugin with what other popular plugins that override bundled syntax files do. eg. - https://github.com/plasticboy/vim-markdown (uses `hi def link` on version 508 and above) - https://github.com/tpope/vim-markdown (uses `hi def link` unconditionally) This stops highlighting from getting obliterated when activating a colorscheme that uses `:hi clear` (which will reset highlights back to defaults), such as a Base16 theme: - https://github.com/chriskempson/base16-vim/blob/3be3cd82cd31acfcab9a41bad853d9c68d30478d/colors/base16-one-light.vim#L146 or Dracula: - https://github.com/dracula/vim/blob/b2cc39273abbb6b38a3d173d2a5d8c2d1c79fc19/colors/dracula.vim#L19-L24 and presumably others.
Great writeup @wincent. As you mentioned this logic was there from the original code and this repository started off as a way to make it easier to install Microsoft's own highlight code that they released only in a blog post about a very early version of typescript, so you probably understand more about it than anybody here. I'm happy to go with your PR. |
I'd be happy to see this re-written/cleaned-up to drop some of the crazy old vim support - doubt anyone uses earlier than v7. Unfortunately I probably won't do that as I don't use this code often - I use neovim and tree-sitter highlighters wherever I can. |
This version of neovim has the same typescript support as vim 8
patch-8.1.1486, so we should override it as well.