neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.05k stars 68 forks source link

How do I disable coc-tsserver for a buffer based on filetype, but have coc-tsserver still running in typescript buffers? #368

Closed NullVoxPopuli closed 2 years ago

NullVoxPopuli commented 2 years ago

My overall problem is that I want to have multiple buffers open, containing files with extensions ts and gts, where ts - should have coc-tsserver enabled -- filetype is: typescript gts - should not have coc-tsserver enabled -- filetype is: typescript.glimmer <- this is a custom syntax I'm helping with, and because tsserver doesn't allow syntax plugins, I gotta do some custom stuff (like what Vue and Svelte do), so I need tsserver turned off for this file type.

I tried doing this within vim

  autocmd FileType,BufEnter *.gjs,*gts call CocActionAsync('deactivateExtension', 'coc-tsserver')
  autocmd FileType,BufEnter *.js,*ts call CocActionAsync('activeExtension', 'coc-tsserver')

but active/deactivate extension applies to the whole vim instance and is not per-buffer.

I'm going to poke around the code here to see if I can find anything obvious to help out, because the behavior for vue and svelte is what I want -- just need to figure out how (custom language server -- which already exsits -- just need to disable tsserver)

chemzqm commented 2 years ago

You need filetype to be something like typescriptglimmer

chemzqm commented 2 years ago

Or use g:coc_filetype_map

NullVoxPopuli commented 2 years ago

You need filetype to be something like typescriptglimmer

why? what's the difference? (other than the missing dot) and why does it have an effect?

g:coc_filetype_map

I couldn't find any examples how this is used -- do you have examples?

chemzqm commented 2 years ago

:h g:coc_filetype_map

NullVoxPopuli commented 2 years ago

I added

    let g:coc_filetype_map = {
        \ 'typescript.glimmer': '',
        \ }

to my init.vim, and confirmed it's set with :echo g:coc_filetype_map

however, tsserver is still starting up on typescript.glimmer files

chemzqm commented 2 years ago

Empty string not work since it considered as false value.

NullVoxPopuli commented 2 years ago

gotchya.

setting to

    let g:coc_filetype_map = {
        \ 'typescript.glimmer': 'glint',
        \ }

appears to do the trick! thanks!

next up -- coc-glint!

NullVoxPopuli commented 2 years ago

oh, is there a way a language server plugin can provide a config like this so users don't have to configure their coc_filetype_map?

chemzqm commented 2 years ago

No, main filetype from filetype with dot is considered as languageId, it should have a different language id.

NullVoxPopuli commented 2 years ago

oh :thinking: are there docs somewhere on filetype formats?

chemzqm commented 2 years ago

:h 'filetype' nothing else.

NullVoxPopuli commented 2 years ago

kind of overwhelming amount of text in there that mostly seems unrelated :sweat_smile:

NullVoxPopuli commented 2 years ago

the words "language" and "Id" do not appear in this document :upside_down_face:

chemzqm commented 2 years ago

https://github.com/neoclide/coc.nvim/blob/master/src/model/document.ts#L128