-
Thanks for your super project. I've been using LunarVim with TSServer as my LSP and Null-ls for diagnostics. I am encountering an issue where I keep getting error code 80001 ("File is a CommonJS module; it may be converted to an ES module.") from TSServer, which I want to suppress or filter out from my diagnostics. I've tried various solutions but none of them have worked so far. I have read https://www.lunarvim.org/docs/configuration/language-features/language-servers And each edition i used I've attempted to filter out the error code with the following method in my -- Store the default handler
local default_handler = vim.lsp.handlers["textDocument/publishDiagnostics"]
-- Define a new handler
vim.lsp.handlers["textDocument/publishDiagnostics"] = function(err, method, result, client_id, bufnr, config)
local client = vim.lsp.get_client_by_id(client_id)
-- Check if the client is tsserver
if client and client.name == "tsserver" then
if result and result.diagnostics then
result.diagnostics = vim.tbl_filter(function(diagnostic)
-- Change 80001 to the code you want to ignore
return diagnostic.code ~= 80001
end, result.diagnostics)
end
end
-- Call the default handler
default_handler(err, method, result, client_id, bufnr, config)
end Then I had tried to another method: vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "tsserver" }) then in -- Store the default handler
local default_handler = vim.lsp.handlers["textDocument/publishDiagnostics"]
-- Define a new handler
vim.lsp.handlers["textDocument/publishDiagnostics"] = function(err, method, result, client_id, bufnr, config)
local client = vim.lsp.get_client_by_id(client_id)
-- Check if the client is tsserver
if client and client.name == "tsserver" then
if result and result.diagnostics then
result.diagnostics = vim.tbl_filter(function(diagnostic)
-- Change '80001' to the code you want to ignore
return tostring(diagnostic.code) ~= '80001'
end, result.diagnostics)
end
end
-- Call the default handler
default_handler(err, method, result, client_id, bufnr, config)
end
-- Set up tsserver with LunarVim's LSP manager
require("lvim.lsp.manager").setup("tsserver", {
init_options = {
preferences = {
disableSuggestions = true,
},
},
})
However, the error code 80001 still shows up in my diagnostics. I would appreciate if anyone could provide me with some guidance on how to suppress or filter out this specific error code (80001) from TSServer's diagnostics using LunarVim and Null-ls. With the code lua in my require("lvim.lsp.manager").setup("tsserver", {
init_options = {
preferences = {
disableSuggestions = true,
},
},
}) Thank you in advance for your help! LunarVim versionrelease-1.3/neovim-0.9-0aea5a68 Neovim version (>= 0.9.0)NVIM v0.9.0 Terminal nameiTerm2 Operating system/versionmacOs Steps to reproduceNo response Screenshots |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
After interacting with ChatGPT and consulting various documents, I found a viable solution. I'm grateful to the open-source community. Even though nobody directly helped me, the shared knowledge of the open-source community was invaluable. local function filter_tsserver_diagnostics(_, result, ctx, config)
if result.diagnostics == nil then
return
end
-- ignore some tsserver diagnostics
local idx = 1
while idx <= #result.diagnostics do
local entry = result.diagnostics[idx]
-- codes: https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
if entry.code == 80001 then
-- { message = "File is a CommonJS module; it may be converted to an ES module.", }
table.remove(result.diagnostics, idx)
else
idx = idx + 1
end
end
vim.lsp.diagnostic.on_publish_diagnostics(_, result, ctx, config)
end
vim.lsp.handlers["textDocument/publishDiagnostics"] = filter_tsserver_diagnostics |
Beta Was this translation helpful? Give feedback.
After interacting with ChatGPT and consulting various documents, I found a viable solution. I'm grateful to the open-source community. Even though nobody directly helped me, the shared knowledge of the open-source community was invaluable.