Skip to content
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

Update to latest Yarn 2/pnpify support #166

Closed
tlvince opened this issue Jun 16, 2020 · 20 comments
Closed

Update to latest Yarn 2/pnpify support #166

tlvince opened this issue Jun 16, 2020 · 20 comments

Comments

@tlvince
Copy link

tlvince commented Jun 16, 2020

yarnpkg/berry#1446 and yarnpkg/berry#1481 introduced first-class support for vim/coc via yarn dlx @yarnpkg/pnpify --sdk vim.

I can confirm this works (as of Yarn v2.0.0-rc.36); a project-local .vim/coc-settings.json is generated with the following contents:

{
  "tsserver.tsdk": ".yarn/sdks/typescript/lib",
  "eslint.packageManager": "yarn",
  "eslint.nodePath": ".yarn/sdks"
}

This appears to have worked out of the box, so there's nothing needed in particular for coc-tsserver, besides updating the readme and perhaps simplifying the MODULE_FOLDERS lookup

const MODULE_FOLDERS = ['node_modules/typescript/lib', '.vscode/pnpify/typescript/lib']

@chemzqm
Copy link
Member

chemzqm commented Jun 29, 2020

Thanks, I've updated readme

@chemzqm chemzqm closed this as completed Jun 29, 2020
@simnalamburt
Copy link
Contributor

Without updating MODULE_FOLDERS, coc-tsserver work only when vim's CWD is same with .vim directories location. For example, if you execute vim in the child directory, coc-tsserver does not work. I've submitted a PR for this issue → #181

@desmap
Copy link

desmap commented Jul 20, 2020

I didn't get it working, maybe I did something wrong:

  • my coc-settings.json is in ~/.config/nvim/ and I added those three props from above
  • my project-based ./.yarn/sdks which I installed before with yarn dlx @yarnpkg/pnpify --sdk vim is in my yarn workspaces project dir where also the workspaces package.json is

What did I wrong?

@chemzqm
Copy link
Member

chemzqm commented Jul 20, 2020

You need create .vim/coc-settings.json in your project root.

@desmap
Copy link

desmap commented Jul 20, 2020

ok working now thx. for others driving by you need to rerun yarn dlx @yarnpkg/pnpify --sdk vim after you installed typescript.

btw, why can coc.vim not grab those three props from the standard coc-settings in .config/nvim? becausee it's a vim thing? and would this also work in ~/.vim/?

@chemzqm
Copy link
Member

chemzqm commented Jul 20, 2020

You have to use ${workspace} in tsserver.tsdk, but it may not exists at all.

@desmap
Copy link

desmap commented Jul 20, 2020

hey i just tried it again to put those three props in my .config/nvim/coc-settings..json without any change, like in the initial issue and the docs from yarn and it's working!! :-) I think I just forgot to rerun yarn dlx... after I installed TS before.

@desmap
Copy link

desmap commented Jul 20, 2020

there is one interesting thing though: If a yarn add some module to some workspace I need to restart nvim to make tsserver aware of it. otherwise it shows still an error (cannot find module...). If I remove a module I don't have to restart nvim, tsserver responds without restart with missing module.

It's no big deal but is this intended? Or is it related to you last post?

@chemzqm
Copy link
Member

chemzqm commented Jul 21, 2020

You make use :CocRestart to restart coc.nvim, it's problem of your tsserver.

@desmap
Copy link

desmap commented Jul 23, 2020

Thanks again. For others driving by and also as note to myself: The easiest way to get a TS monorepo ready without intefereing with other non-yarn-2 projects is and without putting anything into the global coc-settings:

yarn add typescript eslint -D && yarn dlx @yarnpkg/pnpify --sdk vim vscode in your monorepo's/project's root.

If you change anything think of rerunning the dlx command paired with :CocRestart.

In VSCode you need to unlock the extension with Ctrl-Shift-p, choose Select TypeScript Version, pick Use Workspace Version.

@desmap
Copy link

desmap commented Jul 23, 2020

What I described one post above is not working anymore, e.g. I get all the time:

[tsserver 2307] [E] Cannot find module 'type-graphql' or its corresponding type declarations.

... despite having an import { ObjectType } from 'type-graphql and it's installed as well.

CCing @arcanis : berry's editor support is shaky at best and not plug'n'play, rather trial'n'error. No rant but this is driving me nuts for days. Before I open an issue in your repo and create a bigger discussion, I would be happy about your feedback. I guees I must do something wrong.

@desmap
Copy link

desmap commented Jul 23, 2020

@arcanis ok I know what it was: Berry's lack on ESM support => yarnpkg/berry#638

@SteffeyDev
Copy link

Thanks for these instructions, needing to have typescript installed at the root before running yarn dlx was not obvious to me. However, I have now followed the steps for a mono-repo, which has generated the .vim/coc-settings.json and .yarn/sdks/typescript/lib folders successfully, but in vim I get the error:

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

Anyone know how to fix this?

@SteffeyDev
Copy link

I figured out the issue was that I did not launch vim from the root of the project, which makes sense because coc-settings.json have relative paths. Not a huge deal, but will be an annoyance whenever I accidentally launch from the src/ folder. Any way around this?

@chemzqm
Copy link
Member

chemzqm commented Nov 13, 2020

You can make 'tsserver.tsdk' the absolute path to your global tsserver module.

@SteffeyDev
Copy link

That's a fair point, though as this file is shared with my development team we would either have to all have the repo in a common location or I would have to impose a machine-specific override of some sort. Can that path support any variables such as $HOME?

@chemzqm
Copy link
Member

chemzqm commented Nov 13, 2020

Will support placeholder like VSCode, you can use ${workspace} then.

@geoyws
Copy link

geoyws commented Aug 1, 2021

Thanks for these instructions, needing to have typescript installed at the root before running yarn dlx was not obvious to me. However, I have now followed the steps for a mono-repo, which has generated the .vim/coc-settings.json and .yarn/sdks/typescript/lib folders successfully, but in vim I get the error:

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

Anyone know how to fix this?

Thanks for this. Apparently we have to install TypeScript in the root package.json and then also run yarn dlx in the root project folder before things work. We may want to update the docs to make it easier for people. Thanks again for your work @chemzqm . Everything is working great now!

@instil-spencerc
Copy link

I was having a hard time with getting this to work. What fixed it for me was running :CocCommand and then tsserver.chooseVersion where I selected "Local version".

@yarobash
Copy link

I was having a hard time with getting this to work. What fixed it for me was running :CocCommand and then tsserver.chooseVersion where I selected "Local version".

You deserve an equestrian monument in the main square of your city.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants