VonHeikemen / lsp-zero.nvim

A starting point to setup some lsp related features in neovim.
https://lsp-zero.netlify.app/v4.x/
MIT License
3.75k stars 95 forks source link

Autostart tsserver with default settings #339

Closed lpww closed 8 months ago

lpww commented 10 months ago

Hi,

First of all, thanks for making this great plugin! I have greatly enjoyed using it so far. I am using it with Mason. However, I am having one small issue that I can't figure out.

The servers are working perfectly if I manually start them with :LspZeroSetupServers tsserver but I can't figure out how to automatically start them. I have read the docs but must be missing something because I thought the installed servers should start automatically? Here is a link to my config https://github.com/lpww/dots/blob/master/.config/nvim/after/plugin/lsp.lua

Thanks!

VonHeikemen commented 10 months ago

You can check if mason-lspconfig knows the language server is installed. Execute this command.

:lua = require('mason-lspconfig').get_installed_servers()

This should return a list of language server names. If the list is empty, try reinstalling tsserver, execute :LspInstall tsserver.

lpww commented 10 months ago

Thanks @VonHeikemen ! Running that command showed that I have 4 servers installed, including tsserver. The full response is: { "gopls", "tsserver", "lua_ls", "zls" }. I'm still having the same problem with them not starting automatically when opening a relevant file (eg.ts/.js for typescript and .go for gopls)

VonHeikemen commented 10 months ago

Okay. Now try executing the command :LspInfo in a typescript file. This should show you some information about the server.

Sometimes the server doesn't start because it can't find the "root directory". For tsserver, you need to make sure the root of your project has a tsconfig.json or jsconfig.json.

lpww commented 10 months ago

Hi @VonHeikemen , thanks for getting back to me.

I opened nvim from a typescript codebase and ran :LspInfo from a .ts file. The project has a tsconfig.json. The output said it detected the file type correctly (typescript) but said 0 clients attached to this buffer.

If I run the command I mentioned in the first post (:LspZeroSetupServers tsserver), then :LspInfo shows the connected server and everything works as expected.

VonHeikemen commented 10 months ago

What does it said about the root directory?

edit: I've added to the documentation a guide with each step I could think of to debug a problem like this:

https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/what-to-do-when-lsp-doesnt-start.md