Closed JustBarnt closed 8 months ago
I am getting the exact same error on :LspRestart
. Was about to post the same thing.
emm could you provide a min config and reproduce step i just give it a try no error through.
@glepnir Yes. My bad. I can set a note to provide a minimal start point tonight when I get home from work.
there already provide a min test file https://github.com/neovim/nvim-lspconfig/blob/master/test/minimal_init.lua you can try it :) no worry
I tried with the minimal config above and did not see the error on :LspRestart
. I experimented with my lsp-config setup and found that when I removed the onAttach autocommand it did not give me the error. But with the on attach autocommand it did.
So this config gave the error:
return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = { "hrsh7th/cmp-nvim-lsp" },
config = function()
local lspconfig = require("lspconfig")
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("Lsp_Custom_Attach", {}),
callback = function(_, bufnr)
local opts = { buffer = bufnr }
vim.keymap.set("n", "gr", ":Telescope lsp_references<CR>", opts)
vim.keymap.set("n", "gd", ":Telescope lsp_definitions<CR>", opts)
vim.keymap.set("n", "gi", ":Telescope lsp_implementations<CR>", opts)
vim.keymap.set("n", "gt", ":Telescope lsp_type_definitions<CR>", opts)
vim.keymap.set("n", "<Leader>a", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<Leader>d", ":Telescope diagnostics bufnr=0<CR>", opts)
vim.keymap.set("n", "<Leader>s", ":Telescope lsp_document_symbols<CR>", opts)
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
local virtual_text_enabled = false
vim.keymap.set("n", "<Leader>td", function()
virtual_text_enabled = not virtual_text_enabled
vim.diagnostic.config({
virtual_text = virtual_text_enabled,
})
end, opts)
vim.keymap.set("n", "<Leader>th", function()
vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled())
end, opts)
end,
})
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
require("lspconfig.ui.windows").default_options = { border = "rounded" }
vim.diagnostic.config({
float = { border = "rounded" },
severity_sort = true,
update_in_insert = true,
virtual_text = false,
})
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" })
vim.lsp.handlers["textDocument/signatureHelp"] =
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" })
--------------- SERVER CONFIGURATIONS ---------------
local capabilities = require("cmp_nvim_lsp").default_capabilities()
lspconfig.cssls.setup({ capabilities = capabilities })
lspconfig.html.setup({ capabilities = capabilities })
lspconfig.hls.setup({
capabilities = capabilities,
settings = {
haskell = {
formattingProvider = "fourmolu",
},
},
})
lspconfig.jsonls.setup({ capabilities = capabilities })
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = { globals = { "hs", "vim" } },
},
},
})
lspconfig.pyright.setup({ capabilities = capabilities })
lspconfig.rust_analyzer.setup({ capabilities = capabilities })
lspconfig.tsserver.setup({ capabilities = capabilities })
end,
}
And this one worked fine:
return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = { "hrsh7th/cmp-nvim-lsp" },
config = function()
local lspconfig = require("lspconfig")
local on_attach = function(_, bufnr)
local opts = { buffer = bufnr }
vim.keymap.set("n", "gr", ":Telescope lsp_references<CR>", opts)
vim.keymap.set("n", "gd", ":Telescope lsp_definitions<CR>", opts)
vim.keymap.set("n", "gi", ":Telescope lsp_implementations<CR>", opts)
vim.keymap.set("n", "gt", ":Telescope lsp_type_definitions<CR>", opts)
vim.keymap.set("n", "<Leader>a", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<Leader>d", ":Telescope diagnostics bufnr=0<CR>", opts)
vim.keymap.set("n", "<Leader>s", ":Telescope lsp_document_symbols<CR>", opts)
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
local virtual_text_enabled = false
vim.keymap.set("n", "<Leader>td", function()
virtual_text_enabled = not virtual_text_enabled
vim.diagnostic.config({
virtual_text = virtual_text_enabled,
})
end, opts)
vim.keymap.set("n", "<Leader>th", function()
vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled())
end, opts)
end
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
require("lspconfig.ui.windows").default_options = { border = "rounded" }
vim.diagnostic.config({
float = { border = "rounded" },
severity_sort = true,
update_in_insert = true,
virtual_text = false,
})
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" })
vim.lsp.handlers["textDocument/signatureHelp"] =
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" })
--------------- SERVER CONFIGURATIONS ---------------
local capabilities = require("cmp_nvim_lsp").default_capabilities()
lspconfig.cssls.setup({ capabilities = capabilities, on_attach = on_attach })
lspconfig.html.setup({ capabilities = capabilities, on_attach = on_attach })
lspconfig.hls.setup({
capabilities = capabilities,
on_attach = on_attach,
settings = {
haskell = {
formattingProvider = "fourmolu",
},
},
})
lspconfig.jsonls.setup({ capabilities = capabilities, on_attach = on_attach })
lspconfig.lua_ls.setup({
capabilities = capabilities,
on_attach = on_attach,
settings = {
Lua = {
diagnostics = { globals = { "hs", "vim" } },
},
},
})
lspconfig.pyright.setup({ capabilities = capabilities, on_attach = on_attach })
lspconfig.rust_analyzer.setup({ capabilities = capabilities, on_attach = on_attach })
lspconfig.tsserver.setup({ capabilities = capabilities, on_attach = on_attach })
end,
}
@ZacharyRizer hmm that's odd I'll have to experiment as well because I'm doing the method you are now doing that doesn't give you there. My config has never used the LspAttach
method for setting up my lsps.
@glepnir I was also went through and re-wrote my LSP setup and that error was gone, unfortunately I still couldn't figure out why. So I'm just going to mark this as closed since for both of our cases it seemed to be related to how we were setting it up.
Description
I was going to file this in (Neovim)[https://github.com/neovim/neovim]'s repo, but
:LspRestart
is specifically only included with this package so I still thought putting this here was more appropriate? I can always move it if not.When ever I run
:LspRestart
I get the following error, but then the LSP proceeds to restart anyways and it reattaches currently to the buffer.This error doesn't appear to cause any issues other than an annoying error whenever it runs.
Neovim version (Nightly) (nvim -v)
NVIM v0.10.0-dev-2451+g8b4e26915
OS
Windows 11
Terminal
Windows Terminal