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

Help Needed: vtsls seems to restart frequently on switching files, performing some actions like line delete etc. #136

Open
mohnasir-gh opened this issue Jan 31, 2024 · 7 comments

Comments

@mohnasir-gh
Copy link

Hey, Thanks for this amazing plugin, I have been using it since yesterday, and the perfomance gain compare to other lsp is huge.
However when I switch from one .ts file to other .ts file or perform some file operations like delete etc, the LSP server seems to restart. Please find below my config from the nvim-lspconfig.

vtsls = {
          root_dir = require("lspconfig.util").root_pattern(".git", "tsconfig.json", "package.json", "jsconfig.json"),
          single_file_support = false,
          autoUseWorkspaceTsdk = true,
          settings = {
            typescript = {
              tsdk = "node_modules/typescript/lib",
              preferences = {
                includeCompletionsForModuleExports = false,
              },
              tsserver = {
                maxTsServerMemory = 4096,
              },
              inlayHints = {
                parameterNames = {
                  enabled = "all",
                },
              },
            },
          },
        }

image

Please suggest if I need to make any changes in the config

@yioneko
Copy link
Owner

yioneko commented Jan 31, 2024

I suspect this is not an issue of vtsls. The most probable reason for this is that the server setup like require('lspconfig').vtsls.setup({}) is called multiple times. I guess that you wrongly put it in a Filetype autocmd, which accounts for the server restarting on file switch.

@mohnasir-gh
Copy link
Author

mohnasir-gh commented Jan 31, 2024

I am using LazyVim distro. I am sure I haven't put anything in autocmd. The repo I am working is a huge MonoRepo(Angular projects). When I disable angularls lsp it seems to be working fine.

So I believe, it could be because of the memory hog or some issue with the angularls config.

Is there any other config of vtsls , that can be changed to optimized it further?

@yioneko
Copy link
Owner

yioneko commented Jan 31, 2024

If you struggled with memory issue, take a look at typescript-language-server/typescript-language-server#472.

Brief summary: download Node.js compiled with pointer compression from nodejs/unofficial-builds and use that to run server, if you are on Linux platform. This will cut down the memory usage by nearly half. But if your repo is really huge and the memory required is more than 4GB, this will exceed the hard limit of memory space and possibly kill the server process.

Another option you could try is to set typescript.tsserver.useSeparateSyntaxServer to false and typescript.tsserver.useSyntaxServer to never. This will ensure only one tsserver process will be spawned instead of two.

I am not familiar with angularls, but I could try to reproduce the problem if minimal nvim config could be provided.

@Demianeen
Copy link

Demianeen commented Feb 3, 2024

Hi! Seems that I could reproduce when issue appears, but I not sure why. It appears in small nx monorepo I just started when I add new path in tsconfig. Take a look (the vtsls messages are at the bottom right):

CleanShot.2024-02-03.at.11.31.08.mp4

Could this be a memory issue? I use MacOS on M1 Pro chip

Minimal lazyvim repro:

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	"folke/LazyVim",
	-- LazyVim default plugins
	{
		"LazyVim/LazyVim",
		import = "lazyvim.plugins",
	},
	{
		"nvim-treesitter/nvim-treesitter",
		opts = function(_, opts)
			if type(opts.ensure_installed) == "table" then
				vim.list_extend(opts.ensure_installed, { "typescript", "tsx" })
			end
		end,
	},
	opts = {
		-- make sure mason installs the server
		servers = {
			vtsls = {},
		},
	},
	{
		"williamboman/mason.nvim",
		opts = {
			ensure_installed = {
				"vtsls",
			},
		},
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")

@yioneko
Copy link
Owner

yioneko commented Feb 5, 2024

@Demianeen Thanks for your detailed information. It seems not a memory issue. Could you try to set typescript.tsserver.log to "verbose" and view the log at /tmp/tsserver-log-* to see if the problem is caused by tsserver crash. Also, if tsserver crashed more than 5 times, a prompt will be shown to asking for submitting an issue to vscode (the behavior is inherited from vscode).

@Demianeen
Copy link

Okay, it seems that the issue just stopped appearing. I think it could be just some error with tsconfig at that time.

I never got the prompt from vtsls to submit the issue though

@mohnasir-gh
Copy link
Author

mohnasir-gh commented Feb 7, 2024

Slightly Off topic, Is it possible to not attach angular lsp to some specific file like .spec.ts or .cy.ts and attach in rest of the .ts files.
Also I notice when I rename something in the .ts file it put the rename text twice.

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

3 participants