-
-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug Failure. Did not expect ImportDeclaration to have an Identifier in its trivia #4271
Comments
Closing as removing the following from my config ended the issue: local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
callback = vim.lsp.buf.clear_references,
})
end |
Excuse me, I have a problem. It works fine without diagnostics, but if diagnostics is present in the code, I still get this error when I called Here is my lsp setup: {
'neovim/nvim-lspconfig',
event = 'VeryLazy',
dependencies = {
{ 'folke/neodev.nvim', opts = {} },
{ 'j-hui/fidget.nvim', opts = {} },
},
config = function()
local lspconfig = require('lspconfig')
local icons = require('plugins.config.icons').diagnostic_icons
-- diagnostic
vim.diagnostic.config({
virtual_text = false,
float = { border = 'rounded' },
})
-- set signs
local signs = {
Error = icons.error,
Warn = icons.warn,
Hint = icons.hint,
Info = icons.info,
}
for type, icon in pairs(signs) do
local hl = 'DiagnosticSign' .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
local opts = { buffer = ev.buf }
vim.keymap.set('n', '<space>gk', vim.lsp.buf.hover, opts)
vim.keymap.set('n', '<space>gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<space>gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
end,
})
-- border for float win
require('lspconfig.ui.windows').default_options.border = 'rounded'
local handlers = {
['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'rounded' }),
['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = 'rounded' }),
}
-- float diagnostic under cursor
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
group = vim.api.nvim_create_augroup('float_diagnostic', { clear = true }),
callback = function()
vim.diagnostic.open_float(nil, { focus = false })
end,
})
-- autocompletion
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
-- on attch
local on_attach = function(client, bufnr)
-- float diagnostic under cursor
vim.api.nvim_create_autocmd('CursorHold', {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { 'BufLeave', 'CursorMoved', 'InsertEnter', 'FocusLost' },
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
}
vim.diagnostic.open_float(nil, opts)
end,
})
-- highlight symbol under cursor
if client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_augroup('lsp_document_highlight', {
clear = false,
})
vim.api.nvim_clear_autocmds({
buffer = bufnr,
group = 'lsp_document_highlight',
})
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
group = 'lsp_document_highlight',
buffer = bufnr,
callback = function()
if vim.bo.filetype ~= 'vue' then
vim.lsp.buf.document_highlight()
end
end,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
group = 'lsp_document_highlight',
buffer = bufnr,
callback = function()
if vim.bo.filetype ~= 'vue' then
vim.lsp.buf.clear_references()
end
end,
})
end
end
local servers = {
'clangd',
'vimls',
'html',
'cssls',
'jsonls',
'tailwindcss',
}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({
on_attach = on_attach,
capabilities = capabilities,
})
end
-- lua
lspconfig.lua_ls.setup({
on_attach = on_attach,
handlers = handlers,
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { 'vim' },
},
},
},
})
-- vue
local getServerPath = function(package_name, server_path)
local mason_registry = require('mason-registry')
return mason_registry.get_package(package_name):get_install_path() .. server_path
end
local vue_language_server_path = getServerPath('vue-language-server', '/node_modules/@vue/language-server')
local typescript_language_server_path =
getServerPath('typescript-language-server', '/node_modules/typescript/lib')
lspconfig.tsserver.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
init_options = {
plugins = {
{
name = '@vue/typescript-plugin',
location = vue_language_server_path,
languages = { 'vue' },
},
},
},
})
lspconfig.volar.setup({
on_attach = on_attach,
capabilities = capabilities,
init_options = {
typescript = {
tsdk = typescript_language_server_path,
},
},
})
end,
}, |
This issue does not seem resolved, since removing this code is not a fix to the underlying problem. (I am having that same code snippet which @samuliraty removed to remove the error) The specific code causing the error is this: vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
}) It's just responsible to highlight the word underneath the cursor and all its occurences inside the document. That works even when the error occurs, btw. So I don't see a reason why this code should be removed. The TS/vue integration needs to be fixed I suppose. The complete snippet again for: local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
callback = vim.lsp.buf.clear_references,
})
end |
Agreed, did not and do not have time to investigate this further, but what I did does not fix the issue, only got rid of the worst symptoms for me. I will reopen this issue since you are still experiencing it. |
This should fixed by volarjs/volar.js@f0aad5d, please update |
In neovim i get bombarded with:
Project Dependencies:
neovim config (init.lua)
Originally posted by @samuliraty in #4246 (comment)
The text was updated successfully, but these errors were encountered: