vim-tsdetect
/coc-tsdetect
provides vim/neovim and coc.nvim
extension to initialize workspace automatically for coc-tsserver
and coc-deno
.
Run :CocInstall coc-tsdetect
in vim/neovim or install vim-tsdetect
with your favorite plugin manager and build with pnpm install && pnpm run build
. It is enough to install one of them.
Checking following in order.
- If buffer name starts with
deno:/
-> deno - If buffer name ends with
.js
,.ts
,.tsx
-> check following in order
a. Shebang is present and includingnode
-> node
b. Shebang is present and includingdeno
-> deno
c.node_modules/
directory is found in ancestors of (following) -> node
- If buffer name is not empty, search from that path.
- Otherwise, search from current working directory.
d. Otherwise. -> deno - -> Check following in order
a. Shebang is present and includingnode
-> node
b. Shebang is present and includingdeno
-> deno - Otherwise, nothing is detected.
This tries to detect when following events occurred.
FileType javascript,javascriptreact,typescript,typescript.tsx,typescriptreact
BufEnter,BufNewFile,BufWritePost *
Please configure following if necessary by :CocConfig
.
Set this "manual"
to disable auto initialization. Variable b:tsdetect_is_node
remains available.
Values: "auto" | "manual"
Default:
{
"tsdetect.mode": "auto"
}
By default, in Node.js environment, tsdetect does not create a workspace configuration (.vim/coc-settings.json
). Set this false
to create configuration file whether the configuration exists.
Values: boolean
Default:
{
"tsdetect.doNotCreateOnNode": true
}
Workspace configuration to be set in Node.js environment. If you want to extend original configuration, you need to include default ones. Not recommended to touch deno.enable
and tsserver.enable
.
Values: object
Default:
{
"tsdetect.nodeOverride": {
"deno.lint": false,
"coc.source.file.trimSameExts": [
".js",
".ts"
],
"prettier.disableLanguages": []
}
}
Workspace configuration to be set in Deno environment. If you want to extend original configuration, you need to include default ones. Not recommended not to touch deno.enable
and tsserver.enable
.
Values: object
Default:
{
"tsdetect.denoOverride": {
"deno.lint": true,
"coc.source.file.trimSameExts": [],
"prettier.disableLanguages": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
}
Fired when the tsdetect detects TypeScript environment in the flow shown in above.
Fired when tsdetect#detect
is fired and environment was detected as node.
Fired when tsdetect#detect
is fired and environment was detected as deno.
Fired after the automatic switch to node triggered and finished.
Fired after the automatic switch to deno triggered and finished.
Set when tsdetect#detect
is fired.
- Not recommended to include
deno.enable
andtsserver.enable
settings in user configuration (~/.vim/coc-settings.json
that can be opened by:CocConfig
). - To prevent
.vim/
directory being committed by VCS, you can globally ignore.vim/
, or ignore one by one usinggit update-index --skip-worktree .vim
for git projects.
Example for deno.cache on save if deno environment is detected:
function! s:my_coc_tsdetect_buf_write_post() abort
if !get(g:, 'coc_enabled', 0)
return
endif
if exists('b:tsdetect_is_node') && !b:tsdetect_is_node
CocCommand deno.cache
endif
endfunction
augroup my-coc-tsdetect
autocmd!
autocmd BufWritePost * call <SID>my_coc_tsdetect_buf_write_post()
augroup END