summaryrefslogtreecommitdiff
path: root/.config/nvim
diff options
context:
space:
mode:
authorKyren223 <ulmliad223@gmail.com>2024-10-04 00:12:33 +0300
committerKyren223 <ulmliad223@gmail.com>2024-10-04 00:12:33 +0300
commit60d3026945ff69c6ab49247da8fc7b8193c26d34 (patch)
treefb6c27abe62d8eb177b3155914877fcd7e21d6d8 /.config/nvim
parentc25f6912ab55e278a63b8bcd84bc7c287d8039af (diff)
feat: go lsp changes
Diffstat (limited to '.config/nvim')
-rw-r--r--.config/nvim/lua/custom/config/commands.lua33
-rw-r--r--.config/nvim/lua/custom/config/language-servers.lua42
-rw-r--r--.config/nvim/lua/custom/config/lsp.lua12
3 files changed, 66 insertions, 21 deletions
diff --git a/.config/nvim/lua/custom/config/commands.lua b/.config/nvim/lua/custom/config/commands.lua
index acb2cbb..50fca05 100644
--- a/.config/nvim/lua/custom/config/commands.lua
+++ b/.config/nvim/lua/custom/config/commands.lua
@@ -48,3 +48,36 @@ end, {
desc = 'Toggle autoformat on save',
bang = true,
})
+
+-- NOTE: highlight %v, %s etc in go string literals
+vim.api.nvim_create_autocmd({ 'BufEnter', 'TextChanged', 'InsertLeave' }, {
+ pattern = '*.go',
+ callback = function()
+ local query = vim.treesitter.query.parse('go', '(interpreted_string_literal) @string')
+ local parser = vim.treesitter.get_parser(0, 'go')
+ local tree = parser:parse()[1]
+ local root = tree:root()
+ local bufnr = vim.api.nvim_get_current_buf()
+
+ for id, node in query:iter_captures(root, bufnr, 0, -1) do
+ if query.captures[id] == 'string' then
+ local start_row, start_col, end_row, end_col = node:range()
+
+ -- Get the text of the string literal
+ local text = vim.api.nvim_buf_get_text(bufnr, start_row, start_col, end_row, end_col, {})[1]
+
+ -- Highlight only the parts matching `%[a-z]`
+ for match_start, match_end in text:gmatch('()%%[a-z]()') do
+ vim.api.nvim_buf_add_highlight(
+ bufnr,
+ -1,
+ '@lsp.type.formatSpecifier.go', -- Higlight group
+ start_row,
+ start_col + match_start - 1,
+ start_col + match_end - 1
+ )
+ end
+ end
+ end
+ end,
+})
diff --git a/.config/nvim/lua/custom/config/language-servers.lua b/.config/nvim/lua/custom/config/language-servers.lua
index 7700493..7da2eaf 100644
--- a/.config/nvim/lua/custom/config/language-servers.lua
+++ b/.config/nvim/lua/custom/config/language-servers.lua
@@ -83,28 +83,28 @@ return {
tidy = true,
upgrade_dependency = true,
vendor = true,
- hints = {
- assignVariableTypes = true,
- compositeLiteralFields = true,
- compositeLiteralTypes = true,
- constantValues = true,
- functionTypeParameters = true,
- parameterNames = true,
- rangeVariableTypes = true,
- },
- analyses = {
- fieldalignment = true,
- nilness = true,
- unusedparams = true,
- unusedwrite = true,
- useany = true,
- },
- usePlaceholders = false,
- completeUnimported = true,
- staticcheck = true,
- directoryFilters = { '-.git', '-.vscode', '-.idea', '-.vscode-test', '-node_modules' },
- semanticTokens = true,
},
+ hints = {
+ assignVariableTypes = true,
+ compositeLiteralFields = true,
+ compositeLiteralTypes = true,
+ constantValues = true,
+ functionTypeParameters = true,
+ -- parameterNames = true,
+ rangeVariableTypes = true,
+ },
+ analyses = {
+ fieldalignment = true,
+ nilness = true,
+ unusedparams = true,
+ unusedwrite = true,
+ useany = true,
+ },
+ usePlaceholders = false,
+ completeUnimported = true,
+ staticcheck = true,
+ directoryFilters = { '-.git', '-.vscode', '-.idea', '-.vscode-test', '-node_modules' },
+ semanticTokens = true,
},
},
}, -- Go LSP
diff --git a/.config/nvim/lua/custom/config/lsp.lua b/.config/nvim/lua/custom/config/lsp.lua
index 817b087..02ff31f 100644
--- a/.config/nvim/lua/custom/config/lsp.lua
+++ b/.config/nvim/lua/custom/config/lsp.lua
@@ -55,6 +55,18 @@ vim.api.nvim_create_autocmd('LspAttach', {
end
end
+ -- Workaround for semantic tokens apparently?
+ -- https://www.lazyvim.org/extras/lang/go
+ -- https://github.com/golang/go/issues/54531#issuecomment-1464982242
+ if client.name == 'gopls' and not client.server_capabilities.semanticTokensProvider then
+ local semantic = client.config.capabilities.textDocument.semanticTokens
+ client.server_capabilities.semanticTokensProvider = {
+ full = true,
+ legend = { tokenModifiers = semantic.tokenModifiers, tokenTypes = semantic.tokenTypes },
+ range = true,
+ }
+ end
+
-- Register buffer local LSP keymaps
require('custom.config.lsp-keymaps').setup(bufnr)
end,