language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Can't get all features working in neovim lsp

Open marcelbusch opened this issue 2 years ago • 5 comments

Hi there,

I installed volar through Mason, it's added through nvim-lspconfig but I can't figure out how to enable some of its features. I don't get autocompletion for imported packages and no hover documentation for example. I tried attaching tsserver as an extra but it won't do anything in SFC files even though it is loaded (also tried getting documentation and completion for the same package in a js/ts file with tsserver and that works). Is this just not implemented for volar or am I missing something? Also tried nvim-lspconfigs default config and this one, neither work:

local tspath = vim.fn.stdpath "data" .. "mason/packages/vue-language-server/node_modules/typescript/lib"
require("lspconfig").volar.setup({
	on_attach = on_attach,
	capabilities = capabilities,
	init_options = {
		typescript = {
			tsdk = tspath
		},
		languageFeatures = {
			references = true,
			definition = true,
			typeDefinition = true,
			callHierarchy = true,
			hover = true,
			rename = true,
			signatureHelp = true,
			codeAction = true,
			completion = {
				defaultTagNameCase = "both",
				defaultAttrNameCase = "kebabCase",
			},
			schemaRequestService = true,
			documentHighlight = true,
			codeLens = true,
			semanticTokens = true,
			diagnostics = true,
		},
	},
})

Versions:

NVIM v0.9.4
Volar 1.8.25

marcelbusch avatar Dec 11 '23 12:12 marcelbusch

For me, no features was working at all.

  • No error reporting
  • No documentation
  • No autoimport

Resolved by downgrading from 2.1.6 to 1.8.27

upd: Probably unrelated to this, found fix https://github.com/vuejs/language-tools/issues/3925

last-partizan avatar Apr 28 '24 12:04 last-partizan

Try this

	local mason_registry = require("mason-registry")
	local vue_language_server_path = mason_registry.get_package("vue-language-server"):get_install_path()
		.. "/node_modules/@vue/language-server"

	local lspconfig = require("lspconfig")

	lspconfig.tsserver.setup({
		init_options = {
			plugins = {
				{
					name = "@vue/typescript-plugin",
					location = vue_language_server_path,
					languages = { "vue" },
				},
			},
		},
		filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue" },
	})

	lspconfig.volar.setup({})

If that works, add your volar setup options one by one and see if one of them causes it to break.

codymikol avatar Apr 28 '24 13:04 codymikol

Thanks, it works!

At first I was getting errors like Cannot find module "./Component.vue", but fixed it by updating local vue-tsc to latest version.

Btw, what's the benefit of running separate tsserver (with default hybridMode=true), vs hybridMode=false?

last-partizan avatar Apr 29 '24 08:04 last-partizan

Prior to 2.0.x it used to be a requirement, but it no longer is.

codymikol avatar Apr 29 '24 08:04 codymikol

Try this

	local mason_registry = require("mason-registry")
	local vue_language_server_path = mason_registry.get_package("vue-language-server"):get_install_path()
		.. "/node_modules/@vue/language-server"

	local lspconfig = require("lspconfig")

	lspconfig.tsserver.setup({
		init_options = {
			plugins = {
				{
					name = "@vue/typescript-plugin",
					location = vue_language_server_path,
					languages = { "vue" },
				},
			},
		},
		filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue" },
	})

	lspconfig.volar.setup({})

If that works, add your volar setup options one by one and see if one of them causes it to break.

ty sooo much. you made my day 👍

mactanxin avatar Jun 12 '24 10:06 mactanxin

@mactanxin @codymikol Should this be documented somewhere?

davidmatter avatar Jul 07 '24 13:07 davidmatter

I'm pretty sure I pulled it out of the README and just made it a package, sorry it's been a minute 😅

codymikol avatar Jul 07 '24 21:07 codymikol