Giter Site home page Giter Site logo

Comments (7)

glepnir avatar glepnir commented on June 2, 2024 1

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

from nvim-lspconfig.

ZacharyRizer avatar ZacharyRizer commented on June 2, 2024

I am getting the exact same error on :LspRestart. Was about to post the same thing.

from nvim-lspconfig.

glepnir avatar glepnir commented on June 2, 2024

emm could you provide a min config and reproduce step i just give it a try no error through.

from nvim-lspconfig.

JustBarnt avatar JustBarnt commented on June 2, 2024

@glepnir Yes. My bad. I can set a note to provide a minimal start point tonight when I get home from work.

from nvim-lspconfig.

ZacharyRizer avatar ZacharyRizer commented on June 2, 2024

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,
}

from nvim-lspconfig.

JustBarnt avatar JustBarnt commented on June 2, 2024

@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.

from nvim-lspconfig.

JustBarnt avatar JustBarnt commented on June 2, 2024

@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.

from nvim-lspconfig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.