prisma / language-tools

🌐 Prisma Language Tools = Language Server and Prisma's VS Code extension.
https://marketplace.visualstudio.com/items?itemName=Prisma.prisma
Apache License 2.0
255 stars 36 forks source link

Implement workaround for hanging types in LSP #315

Closed janpio closed 4 years ago

janpio commented 4 years ago

https://github.com/prisma/prisma/issues/2962 and https://github.com/prisma/prisma/issues/2771 describe a problem with outdated TypeScript types after generation. That is bad for our users.

In https://prisma-company.slack.com/archives/CKCQQGXJM/p1594197337043400 (internal) we came up with a possible way to work around this via an implementation in our LSP.

carmenberndt commented 4 years ago

Update: The extension can monitor files with a specific path and do something on changes, but apparently the node_modules folder is excluded from that.

carmenberndt commented 4 years ago

There's a files.watcherExclude setting with the following defaults:

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true,
    "**/.hg/store/**": true
}

Excluding large folders is used to reduce the initial load on startup of VSCode. Performance-wise it's probably not advisable to remove node_modules from here either, since it can contain a lot of files. But there is an issue to exclude all files except a specific one (https://github.com/microsoft/vscode/issues/869). Since this is a user setting though, we cannot set this inside the extension.

carmenberndt commented 4 years ago

In https://github.com/prisma/language-tools/pull/357, a solution for the VSCode extension got implemented. A file watcher is added to **/.prisma/client/*.d.ts , restarting the TS Language Server if something changes inside the watched files.

peterp commented 4 years ago

I'm not 100% sure that the solution in #357 is working correctly. I'm still finding that I need to manually restart the ts-server to refresh types, and I think @burnsy reported the same to me.

carmenberndt commented 4 years ago

This regression was fixed in #443.

What happened: To be able to solve the problem of hanging types, our solution was to restart the TS Language Server on every change to node_modules/.prisma/client/index.d.ts. In order to detect changes to this file, we had to change the workspace settings, otherwise changes to node_modules were ignored by default. However, this solution only worked if the prisma project was opened with a workspace.

We now are detecting changes with a different file watcher (chokidar), which does detect changes to the node_modules folder and also works independently of having the project opened as a folder or a workspace.

Please try out 2.6.0 and let us know if there are any issue with it.

peterp commented 4 years ago

That was amazingly fast, thanks so much!

gruckion commented 5 months ago

Doesn't look like it works with pnpm mono repo.

janpio commented 5 months ago

Please open a new issue then @gruckion and explain how to reproduce. Thanks.