neoclide / coc-tsserver

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

Lack of relative lookup for pnpfied (Yarn v2) tsserver.tsdk #260

Closed ambasta closed 3 years ago

ambasta commented 3 years ago

Hi,

I have a yarn v2 monorepo with the .vim/coc-settings in the rootdir. However, while launching vim from any subdirectory recognizes the coc-settings.json from parent .vim directory, relative paths in tsserver.tsk are resolved wrt cwdir instead of relative to project root.

This leads to tsserver failing to find modules w/

[coc.nvim] Can not find typescript module, in 'tsserver.tsdk': .yarn/sdks/typescript/lib

chemzqm commented 3 years ago

Use ${workspaceRoot} at the beggining.

ambasta commented 3 years ago

@chemzqm You mean like so?

[coc.nvim] Can not find typescript module, in 'tsserver.tsdk': ${workspaceRoot}/.yarn/sdks/typescript/lib

chemzqm commented 3 years ago

Yes

chemzqm commented 3 years ago

Yes

ambasta commented 3 years ago

@chemzqm Thanks a lot.. setting appropriate root pattern in vim settings resolves this. I am not sure if coc-tsserver should handle this, but the current contributes.rootPatterns doesn't work for monorepos. I am not sure how this can be addressed in general, but using npm.lock or yarn.lock instead for pnp projects instead of package.json/tsconfig.json might be more benefitial.

For future reference, when using a pnp monorepo, following changes to vimrc and .vim/coc-settings.json address the issue:

vimrc

autocmd FileType typescript let b:coc_root_patterns=["yarn.lock", "npm.lock"]

coc-settings.json

"tsserver.tsdk": "${workspaceRoot}/.yarn/sdks/typescript/lib"

chemzqm commented 3 years ago

You may have to use workspace.bottomUpFiletypes configuration.