diff options
| author | Kyren223 <ulmliad223@gmail.com> | 2024-10-04 00:12:33 +0300 |
|---|---|---|
| committer | Kyren223 <ulmliad223@gmail.com> | 2024-10-04 00:12:33 +0300 |
| commit | 60d3026945ff69c6ab49247da8fc7b8193c26d34 (patch) | |
| tree | fb6c27abe62d8eb177b3155914877fcd7e21d6d8 /.config/nvim/lua/custom/config/commands.lua | |
| parent | c25f6912ab55e278a63b8bcd84bc7c287d8039af (diff) | |
feat: go lsp changes
Diffstat (limited to '.config/nvim/lua/custom/config/commands.lua')
| -rw-r--r-- | .config/nvim/lua/custom/config/commands.lua | 33 |
1 files changed, 33 insertions, 0 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, +}) |
