From 70c8eade7c8708dd562d34e1efff364121db6736 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 9 Jul 2024 19:54:45 +0100 Subject: [PATCH] cssls: exclude `@tailwind` and `@apply` at rule ...diagnostic errors --- lua/opdavies/lsp/handlers.lua | 33 +++++++++++++++++++++++++++++++++ lua/opdavies/lsp/init.lua | 16 +++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lua/opdavies/lsp/handlers.lua b/lua/opdavies/lsp/handlers.lua index 0fd582c..5c0c235 100644 --- a/lua/opdavies/lsp/handlers.lua +++ b/lua/opdavies/lsp/handlers.lua @@ -1,5 +1,15 @@ local M = {} +local function should_remove_diagnostic(messages_to_filter, message) + for _, filter_message in ipairs(messages_to_filter) do + if message:match(filter_message) then + return true + end + end + + return false +end + M.definition = function() local params = vim.lsp.util.make_position_params() @@ -32,4 +42,27 @@ M.definition = function() end) end +M.on_publish_diagnostics = function(_, result, ctx, config) + local client = vim.lsp.get_client_by_id(ctx.client_id) + + if client.name == "cssls" then + local filtered_diagnostics = {} + + local messages_to_filter = { + "Unknown at rule @apply", + "Unknown at rule @tailwind", + } + + for _, diagnostic in ipairs(result.diagnostics) do + if not should_remove_diagnostic(messages_to_filter, diagnostic.message) then + table.insert(filtered_diagnostics, diagnostic) + end + end + + result.diagnostics = filtered_diagnostics + end + + vim.lsp.diagnostic.on_publish_diagnostics(_, result, ctx, config) +end + return M diff --git a/lua/opdavies/lsp/init.lua b/lua/opdavies/lsp/init.lua index 0c67994..6ae90f7 100644 --- a/lua/opdavies/lsp/init.lua +++ b/lua/opdavies/lsp/init.lua @@ -1,16 +1,26 @@ local lspconfig = require "lspconfig" local nvim_status = require "lsp-status" +local handlers = require "opdavies.lsp.handlers" + require("neodev").setup {} local servers = { bashls = true, - cssls = true, + + cssls = { + on_attach = function(client, bufnr) + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(handlers.on_publish_diagnostics, {}) + end, + }, + gopls = true, html = true, + intelephense = { filetypes = { "php", "module", "test", "inc" }, }, + lua_ls = { settings = { Lua = { @@ -36,8 +46,10 @@ local servers = { }, }, }, + marksman = true, nil_ls = true, + tailwindcss = { filetypes = { "html", "javascript", "twig", "typescript", "vue" }, @@ -49,9 +61,11 @@ local servers = { }, }, }, + terraformls = true, tsserver = true, vuels = true, + yamlls = { settings = { yaml = {