Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.

Commit c441df2

Browse files
committed
inlay: Added the last features
1 parent 905c1ce commit c441df2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lua/lsp_extensions/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ Note to self:
55
66
Each extension should probably look like:
77
8+
- request(opts)
9+
-> opts gets passed to get_callback, runs the request in your buffer.
10+
811
- get_callback(opts)
912
-> opts configures how you would want this extension to run.
1013
1114
- get_params(opts)
1215
-> get the params you need to make the request
1316
1417
--]]
18+
1519
local extensions = {}
1620

1721

lua/lsp_extensions/inlay_hints.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ local inlay_hints = {}
3131

3232
local inlay_hints_ns = vim.api.nvim_create_namespace('lsp_extensions.inlay_hints')
3333

34-
-- vim.lsp.callbacks['rust-analyzer/inlayHints'] = callback
35-
-- vim.lsp.callbacks['experimental/inlayHints'] = callback
34+
inlay_hints.request = function(opts, bufnr)
35+
vim.lsp.buf_request(bufnr or 0, 'rust-analyzer/inlayHints', inlay_hints.get_params(), inlay_hints.get_callback(opts))
36+
37+
-- TODO: At some point, rust probably adds this?
38+
-- vim.lsp.buf_request(bufnr or 0, 'experimental/inlayHints', inlay_hints.get_params(), inlay_hints.get_callback(opts))
39+
end
3640

3741
inlay_hints.get_callback = function(opts)
3842
opts = opts or {}
3943

4044
local highlight = opts.highlight or "Comment"
41-
local prefix = opts.prefix or " || "
45+
local prefix = opts.prefix or " > "
4246
local aligned = opts.aligned or false
4347

4448
local only_current_line = opts.only_current_line
@@ -80,9 +84,9 @@ inlay_hints.get_callback = function(opts)
8084
end
8185

8286
local text
83-
if aligned then
87+
if aligned then
8488
local line_length = #vim.api.nvim_buf_get_lines(bufnr, end_line, end_line + 1, false)[1]
85-
text = string.format("%s | %s", (" "):rep(longest_line - line_length), hint.label)
89+
text = string.format("%s %s", (" "):rep(longest_line - line_length), prefix .. hint.label)
8690
else
8791
text = prefix .. hint.label
8892
end

0 commit comments

Comments
 (0)