From 020f771e6e71588eaa7bddd633d1a839f0d8e895 Mon Sep 17 00:00:00 2001 From: MysticalDevil Date: Fri, 13 Oct 2023 07:45:35 +0800 Subject: [PATCH] Add golang semanic support. Adjust some lsp config --- lua/configs/plugin/clangd_extensions.lua | 46 +++++++----------------- lua/lsp/attach.lua | 26 ++++++++++++++ lua/lsp/config/clangd.lua | 5 ++- lua/lsp/config/gopls.lua | 22 ++++++++++-- lua/lsp/config/jsonls.lua | 2 ++ lua/lsp/config/yamlls.lua | 2 ++ lua/lsp/setup.lua | 1 + lua/lsp/util.lua | 10 ++++++ 8 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 lua/lsp/attach.lua diff --git a/lua/configs/plugin/clangd_extensions.lua b/lua/configs/plugin/clangd_extensions.lua index dfe9786..61d5a15 100644 --- a/lua/configs/plugin/clangd_extensions.lua +++ b/lua/configs/plugin/clangd_extensions.lua @@ -52,42 +52,22 @@ local opts = { ast = { -- These are unicode, should be available in any font role_icons = { - type = "🄣", - declaration = "🄓", - expression = "🄔", - statement = ";", - specifier = "🄢", - ["template argument"] = "🆃", + type = "", + declaration = "", + expression = "", + specifier = "", + statement = "", + ["template argument"] = "", }, kind_icons = { - Compound = "🄲", - Recovery = "🅁", - TranslationUnit = "🅄", - PackExpansion = "🄿", - TemplateTypeParm = "🅃", - TemplateTemplateParm = "🅃", - TemplateParamObject = "🅃", + Compound = "", + Recovery = "", + TranslationUnit = "", + PackExpansion = "", + TemplateTypeParm = "", + TemplateTemplateParm = "", + TemplateParamObject = "", }, - --[[ These require codicons (https://github.com/microsoft/vscode-codicons) - role_icons = { - type = "", - declaration = "", - expression = "", - specifier = "", - statement = "", - ["template argument"] = "", - }, - - kind_icons = { - Compound = "", - Recovery = "", - TranslationUnit = "", - PackExpansion = "", - TemplateTypeParm = "", - TemplateTemplateParm = "", - TemplateParamObject = "", - }, ]] - highlights = { detail = "Comment", }, diff --git a/lua/lsp/attach.lua b/lua/lsp/attach.lua new file mode 100644 index 0000000..50b2a65 --- /dev/null +++ b/lua/lsp/attach.lua @@ -0,0 +1,26 @@ +local util = require("lsp.util") + +-- python ruff +util.on_attach(function(client, _) + if client.name == "ruff_lsp" then + -- Disable hover in favor of Pyright + client.server_capabilities.hoverProvider = false + end +end) + +-- config gopls semantic +util.on_attach(function(client, _) + if client.name == "gopls" then + if not client.server_capabilities.semanticTokensProvider then + local semantic = client.config.capabilities.textDocument.semanticTokens + client.server_capabilities.semanticTokensProvider = { + full = true, + legend = { + tokenTypes = semantic.tokenTypes, + tokenModifiers = semantic.tokenModifiers, + }, + range = true, + } + end + end +end) diff --git a/lua/lsp/config/clangd.lua b/lua/lsp/config/clangd.lua index 7d6b12b..abfd69c 100644 --- a/lua/lsp/config/clangd.lua +++ b/lua/lsp/config/clangd.lua @@ -31,10 +31,13 @@ opts.settings = { } opts.cmd = { "clangd", - "--background-index", "--pch-storage=memory", + "--background-index", "--clang-tidy", + "--header-insertion=iwyu", "--completion-style=detailed", + "--function-arg-placeholders", + "--fallback-style=llvm", } opts.init_options = { clangdFileStatus = true, diff --git a/lua/lsp/config/gopls.lua b/lua/lsp/config/gopls.lua index 03da040..e8a7f6d 100644 --- a/lua/lsp/config/gopls.lua +++ b/lua/lsp/config/gopls.lua @@ -7,10 +7,13 @@ opts.settings = { gopls = { experimentalPostfixCompletions = true, analyses = { - unusedparams = true, shadow = true, + fieldalignment = true, + nilness = true, + unusedparams = true, + unusedwrite = true, + useany = true, }, - staticcheck = true, gofumpt = true, hints = { rangeVariableTypes = true, @@ -21,6 +24,21 @@ opts.settings = { compositeLiteralTypes = true, functionTypeParameters = true, }, + codelenses = { + gc_details = false, + generate = true, + regenerate_cgo = true, + run_govulncheck = true, + test = true, + tidy = true, + upgrade_dependency = true, + vendor = true, + }, + usePlaceholders = true, + completeUnimported = true, + staticcheck = true, + directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" }, + semanticTokens = true, }, } opts.init_options = { diff --git a/lua/lsp/config/jsonls.lua b/lua/lsp/config/jsonls.lua index f1a6842..d7fdfee 100644 --- a/lua/lsp/config/jsonls.lua +++ b/lua/lsp/config/jsonls.lua @@ -6,6 +6,8 @@ opts.filetypes = { "json", "jsonc" } opts.settings = { json = { schemas = require("schemastore").json.schemas(), + format = { enable = true }, + validate = { enable = true }, }, } opts.init_options = { diff --git a/lua/lsp/config/yamlls.lua b/lua/lsp/config/yamlls.lua index fa222a0..1db176a 100644 --- a/lua/lsp/config/yamlls.lua +++ b/lua/lsp/config/yamlls.lua @@ -7,9 +7,11 @@ local url = "https://raw.githubusercontent.com/quantumblacklabs/kedro/develop/st opts.filetypes = { "yaml", "yaml.docker-compose" } opts.settings = { yaml = { + keyOrdering = false, format = { enable = true, }, + validate = true, schemas = { [url] = "conf/**/*catalog*", ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*", diff --git a/lua/lsp/setup.lua b/lua/lsp/setup.lua index 3cb7f1c..44c8233 100644 --- a/lua/lsp/setup.lua +++ b/lua/lsp/setup.lua @@ -94,6 +94,7 @@ for _, name in ipairs(lsp_servers) do end require("lsp.ui") +require("lsp.attach") util.enable_inlay_hints_autocmd() diff --git a/lua/lsp/util.lua b/lua/lsp/util.lua index 4df2206..05d05cc 100644 --- a/lua/lsp/util.lua +++ b/lua/lsp/util.lua @@ -111,6 +111,16 @@ function M.enable_inlay_hints_autocmd() }) end +function M.on_attach(on_attach) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local buffer = args.buf ---@type number + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) +end + ---@param name string|table ---@return boolean function M.find_binary_exists(name)