Reputation: 91
I am trying to utilize NVIM's built-in LSPs. While I've been able to implement the LSP for css and python, I haven't been successful with javascript and html.
I installed the LSPs with
:LspInstall <LSP>
Here's how I'm loading the LSPs:
packadd nvim-lspconfig
packadd completion-nvim
:lua << EOF
local nvim_lsp = require('nvim_lsp')
local on_attach = function(_, bufnr)
require('completion').on_attach()
local opts = { noremap=true, silent=true }
end
local servers = {'tsserver', 'cssls', 'html', 'pyls'}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach
}
print("lsp istalled -", lsp)
end
EOF
:LspInstallInfo shows:
{
cssls = {
bin_dir = "~/.cache/nvim/nvim_lsp/cssls/node_modules/.bin",
binaries = {
["css-languageserver"] = "~/.cache/nvim/nvim_lsp/cssls/node_modules/.bin/css-languageserver"
},
install_dir = "~/.cache/nvim/nvim_lsp/cssls",
is_installed = true
},
html = {
bin_dir = "~/.cache/nvim/nvim_lsp/html/node_modules/.bin",
binaries = {
["html-languageserver"] = "~/.cache/nvim/nvim_lsp/html/node_modules/.bin/html-languageserver"
},
install_dir = "~/.cache/nvim/nvim_lsp/html",
is_installed = true
},
tsserver = {
bin_dir = "~/.cache/nvim/nvim_lsp/tsserver/node_modules/.bin",
binaries = {
["typescript-language-server"] = "~/.cache/nvim/nvim_lsp/tsserver/node_modules/.bin/typescript
-language-server"
},
install_dir = "~/.cache/nvim/nvim_lsp/tsserver",
is_installed = true
}
}
They seem to be installed and the LSPs for *.css and *.py work fine.
When I open a *.js, *.ts, or *.html file I get the same response with the :LspInstallInfo command. However, I don't think the LSP is active because I do not receive any warning or error messages regarless of what I type.
I've tried loading the LSP different ways, including:
require'nvim_lsp'.tsserver.setup{}
require'nvim_lsp'.html.setup{}
I came across a post about installing typescript and I did, but it didn't seem to have any effect.
I've deactivated all of the other plugins and had the same results.
Upvotes: 2
Views: 18796
Reputation: 41
After installation, you should take consider root_dir. So if you don't have a matching root directory LSP doesn't launch.
In order to automatically launch a language server, lspconfig searches up the directory tree from your current buffer to find a file matching the root_dir pattern defined in each server's configuration. For pyright, this is any directory containing ".git", "setup.py", "setup.cfg", "pyproject.toml", or "requirements.txt").
Language servers require each project to have a root in order to provide completion and search across symbols that may not be defined in your current file, and to avoid having to index your entire filesystem on each startup.
But if you want to launch LSP in any directory, you can use something like this for Javscript:
require'lspconfig'.tsserver.setup{
filetypes = { "typescript", "typescriptreact", "typescript.tsx" },
root_dir = function() return vim.loop.cwd() end -- run lsp for javascript in any directory
}
Upvotes: 4
Reputation: 792
I was working on setting up neovim 0.5 today and landed up here looking for something else related to LSP. Anyho, I do have a working setup; here's a brief:
nvim-lspconfig
package (I used vim-plug)npm i -g typescript-language-server
lua << EOF
require'lspconfig'.tsserver.setup{}
EOF
I noticed you're using commands like LspInstall
& LspInstallInfo
, but they are not present in my setup. I'm afraid I cannot comment of why they it work as expected.
LSP by itself doesn't show autocompletion. Have to use another plugin. I am getting good results with completion-nvim
This is a good reference : neovim-and-its-built-in-language-server-protocol
Oh, do give :help lsp
a read if you haven't already. Cheers!
Upvotes: 1