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

Crashes in monorepo #183

Closed
iamim opened this issue Jul 11, 2024 · 9 comments
Closed

Crashes in monorepo #183

iamim opened this issue Jul 11, 2024 · 9 comments

Comments

@iamim
Copy link

iamim commented Jul 11, 2024

When I open a root folder containing 2 TS projects (ProjectA and ProjectB) and open one of them vtsls initializes properly. However, when I try to open a buffer from its sibling project (ProjectB), vtsls is stuck re-initializing and failing.

I can see in :LspInfo ran from ProjectA/index.ts that it initializes correctly with the root set to /ProjectA. :LspInfo from the problematic ProjectB shows either that it's running in a single file mode or set to /ProjectA.

This is my config in nvim-lspconfig:

vtsls = {
  filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
  settings = {
    vtsls = {
      -- autoUseWorkspaceTsdk = true,
      tsserver = {
        globalPlugins = {
          {
            name = '@vue/typescript-plugin',
            location = '/opt/homebrew/lib/node_modules/@vue/typescript-plugin',
            languages = { 'vue' },
            configNamespace = 'typescript',
            enableForWorkspaceTypeScriptVersions = true,
          },
        },
      },
    },
  },
},
@yioneko
Copy link
Owner

yioneko commented Jul 11, 2024

Root directory is determined on the client side, you should check the root_dir function of lspconfig. Does the server still crash if you disable all the ts plugins?

@iamim
Copy link
Author

iamim commented Jul 11, 2024

Thanks for replying!
root_dir should be fine as it's the one set in nvim-lspconfig.

I believe I found the issue. It seems like the node process managing tsserver runs out of memory. The two projects I'm working with are fairly small but they import a lot of type definitions. Is there a way to spawn a new node instance per project or increase --max-old-space-size of the node instance (you can see that it's set to 3GiB)?

What happens is that as I open a second project, the memory of the node process on the picture goes to 3.2GiB and it crashes shortly.

image

@yioneko
Copy link
Owner

yioneko commented Jul 12, 2024

Good catch. The memory limit is controlled by typescript.tsserver.maxTsServerMemory and it defaults to 3GB which is the same as VSCode default. You can increase that limit to see if it solves your problem. I'll consider removing that limit by default since I've seen many people reporting the server crashed on large monorepo.

@yioneko
Copy link
Owner

yioneko commented Jul 12, 2024

Added a section in README for it: 376a43d

@iamim
Copy link
Author

iamim commented Jul 12, 2024

Awesome, thanks!

I wonder how vscode handled those 2 projects with no issues.

@yioneko
Copy link
Owner

yioneko commented Jul 12, 2024

VSCode uses a special built Node.js to reduce the memory usage by nearly half: #136 (comment)

@iamim
Copy link
Author

iamim commented Jul 12, 2024

Crazy, didn't know that. Thank you for your assistance!

@iamim iamim closed this as completed Jul 12, 2024
@iamim
Copy link
Author

iamim commented Jul 12, 2024

Since vscode uses a custom runtime to run tsserver, could it be a good experimental feature for this LSP? Maybe bun, or other runtimes?

@yioneko
Copy link
Owner

yioneko commented Jul 12, 2024

I think the server as a npm package could not control the runtime used to run it, users are free to choose any runtime through cmd like /path/to/runtime /path/to/vtsls_bin --stdio. There is also a setting typescript.tsserver.nodePath to specifically control the runtime used for tsserver. However, at least we could document which runtime is supported like the special node compiled with pointer compression.

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

2 participants