Skip to content

Commit

Permalink
Add golang semanic support. Adjust some lsp config
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticalDevil committed Oct 12, 2023
1 parent 9039f4a commit 020f771
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 36 deletions.
46 changes: 13 additions & 33 deletions lua/configs/plugin/clangd_extensions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
26 changes: 26 additions & 0 deletions lua/lsp/attach.lua
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion lua/lsp/config/clangd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 20 additions & 2 deletions lua/lsp/config/gopls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions lua/lsp/config/jsonls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions lua/lsp/config/yamlls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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/*",
Expand Down
1 change: 1 addition & 0 deletions lua/lsp/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ for _, name in ipairs(lsp_servers) do
end

require("lsp.ui")
require("lsp.attach")

util.enable_inlay_hints_autocmd()

Expand Down
10 changes: 10 additions & 0 deletions lua/lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 020f771

Please sign in to comment.