repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: put inlay hints at the end of the line

5b861af34403b8795e05ffa5b0db55c359fa8418

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

neovim/init.lua

Modified
59 59 require 'bugabinga.sessions'
60 60 require 'bugabinga.treesitter'
61 61 require 'bugabinga.terminal'
62 +require 'bugabinga.inlay'
63 64 --[[ PLUGINS ]]
64 65 require 'bugabinga.autotag'

neovim/lua/bugabinga/fuzzy_find.lua

Modified
24 24 map.normal {
25 - description = 'Find files',
25 + description = 'find files',
26 26 command = pick.builtin.files,
27 27 keys = '<leader>ff',
28 28 category = 'fuzzy'
31 31 map.normal {
32 - description = 'Live Grep',
32 + description = 'live grep',
33 33 command = pick.builtin.grep_live,
34 34 keys = '<leader>fg',
35 35 category = 'fuzzy'
38 38 map.normal {
39 - description = 'Find symbols',
39 + description = 'find symbols',
40 40 command = function() extra.pickers.lsp { scope = 'document_symbol' } end,
41 41 keys = '<leader>fs',
42 42 category = 'fuzzy'
45 45 map.normal {
46 - description = 'Find highlight groups',
46 + description = 'find highlight groups',
47 47 command = extra.pickers.hl_groups,
48 48 keys = '<leader>fl',
49 49 category = 'fuzzy'
52 52 map.normal {
53 - description = 'Find spellsuggests',
53 + description = 'find spellsuggests',
54 54 command = extra.pickers.spellsuggest,
55 55 keys = '<leader>fz',
56 56 category = 'fuzzy'
59 59 map.normal {
60 - description = 'Find keymaps',
60 + description = 'find keymaps',
61 61 command = extra.pickers.keymaps,
62 62 keys = '<leader>fk',
63 63 category = 'fuzzy'
66 + map.normal {
67 + description = 'find marks',
68 + command = extra.pickers.marks,
69 + keys = '<leader>fm',
70 + category = 'fuzzy'
71 + }
65 72 end)

neovim/lua/bugabinga/inlay.lua

Added
new file mode 100644
1 +-- diaplay inlay hints at the END of the line, instead of
2 +-- mixed with the source code
3 +--
4 +-- stolen from: https://github.com/chrisgrieser/nvim-lsp-endhints/blob/main/lua/lsp-endhints/override-handler.lua
6 +local config = {
7 + icons = {
8 + type = "󰜁 ",
9 + parameter = "󰏪 ",
10 + offspec = " ", -- hint kind not defined in official LSP spec
11 + unknown = " ", -- hint kind is nil
12 + },
13 + label = {
14 + truncateAtChars = 20,
15 + padding = 1,
16 + marginLeft = 0,
17 + sameKindSeparator = ", ",
18 + },
19 + extmark = {
20 + priority = 50,
21 + },
24 +local ns = vim.api.nvim_create_namespace("bugabinga-inlay")
26 +local function changedRefreshHandler(err, result, ctx, _)
27 + -- GUARD
28 + if not vim.lsp.inlay_hint.is_enabled() then return end
29 + local bufnr = ctx.bufnr or -1
30 + if not vim.api.nvim_buf_is_valid(bufnr) then return end
31 + if not result then return end
32 + local client = vim.lsp.get_client_by_id(ctx.client_id)
33 + if not client then return end
34 + local inlayHintProvider = client.server_capabilities.inlayHintProvider
35 + if not inlayHintProvider then return end
36 + if err then
37 + vim.notify(vim.inspect(err), vim.log.levels.ERROR)
38 + return
39 + end
41 + local padding = (" "):rep(config.label.padding)
42 + local marginLeft = (" "):rep(config.label.marginLeft)
44 + vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
46 + -- Collect all hints for each line, so we can sort them by column in the loop
47 + -- below. This ensures that the hints are displayed in the correct order.
48 + local hintLines = vim.iter(result):fold({}, function(acc, hint)
49 + local lnum = hint.position.line
50 + local col = hint.position.character
52 + -- LABEL
53 + local label = hint.label
54 + if type(label) ~= "string" then
55 + -- label can be string or `InlayHintLabelPart[]` https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#inlayHint
56 + label = vim.iter(hint.label):map(function(labelPart) return labelPart.value end):join("")
57 + end
58 + label = vim.trim(label:gsub("^:", ""):gsub(":$", ""))
59 + if config.label.truncateAtChars and #label > config.label.truncateAtChars then
60 + label = label:sub(1, config.label.truncateAtChars) .. "…"
61 + end
63 + -- KIND
64 + -- 1: type, 2: parameter -- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#inlayHintKind
65 + local kind
66 + if hint.kind == 1 then
67 + kind = "type"
68 + elseif hint.kind == 2 then
69 + kind = "parameter"
70 + elseif hint.kind == nil then
71 + kind = "unknown"
72 + else
73 + kind = "offspec"
74 + end
76 + if not acc[lnum] then acc[lnum] = {} end
77 + table.insert(acc[lnum], { label = label, col = col, kind = kind })
78 + return acc
79 + end)
81 + -- loop: add hints as extmarks for each line
82 + for lnum, hints in pairs(hintLines) do
83 + table.sort(hints, function(a, b) return a.col < b.col end)
85 + -- merge hints of same kind
86 + -- add icon only when parameter kind is different from the previous one
87 + local hintsMerged = ""
88 + for i = 1, #hints do
89 + local hint = hints[i]
90 + local lastKind = hints[i - 1] and hints[i - 1].kind
91 + if lastKind == hint.kind then
92 + hintsMerged = hintsMerged .. config.label.sameKindSeparator .. hint.label
93 + else
94 + local icon = config.icons[hint.kind]
95 + local pad = i ~= 1 and " " or ""
96 + hintsMerged = hintsMerged .. pad .. icon .. hint.label
97 + end
98 + end
100 + -- add padding & margin
101 + local virtText = {
102 + { padding .. hintsMerged .. padding, "LspInlayHint" },
104 + if marginLeft ~= "" then table.insert(virtText, 1, { marginLeft }) end
106 + -- add extmark for the line
107 + vim.api.nvim_buf_set_extmark(bufnr, ns, lnum, 0, {
108 + virt_text = virtText,
109 + virt_text_pos = "eol",
110 + hl_mode = "combine", -- ensures highlights are combined with the background, see #2
111 + strict = false, -- prevents error on quick buffer changes (e.g. quick series of undos)
112 + priority = config.extmark.priority,
113 + })
114 + end
115 +end
117 +vim.lsp.handlers["textDocument/inlayHint"] = changedRefreshHandler

nushell/env.nu

Modified
10 10 $env.CARGO_HOME = ( "~/.cargo" | path expand )
11 11 $env.GO_HOME = ( "~/.go" | path expand )
12 12 $env.NIM_HOME = ( "~/.nimble" | path expand)
13 +$env.OPENCODE_HOME = ( "~/.opencode" | path expand)
14 15 if $env.WIN32 {
15 16 $env.Path = (
19 20 | append ($env.GO_HOME | path join bin)
20 21 | append ($env.NIM_HOME | path join bin)
21 22 | append ($env.TOOLS | path join bin)
23 + | append ($env.OPENCODE_HOME | path join bin)
22 24 | uniq # filter so the paths are unique
24 26 } else {
29 31 | append ($env.GO_HOME | path join bin)
30 32 | append ($env.NIM_HOME | path join bin)
31 33 | append ($env.TOOLS | path join bin)
34 + | append ($env.OPENCODE_HOME | path join bin)
32 35 | uniq # filter so the paths are unique