@@ -25,14 +25,15 @@ interface InlayHint {
25
25
label: string,
26
26
}
27
27
```
28
- --]]
28
+ --]]
29
29
30
30
local inlay_hints = {}
31
31
32
- local inlay_hints_ns = vim .api .nvim_create_namespace (' lsp_extensions.inlay_hints' )
32
+ local inlay_hints_ns = vim .api .nvim_create_namespace (" lsp_extensions.inlay_hints" )
33
33
34
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 ))
35
+ vim .lsp .buf_request (bufnr or 0 , " rust-analyzer/inlayHints" , inlay_hints .get_params (),
36
+ inlay_hints .get_callback (opts ))
36
37
37
38
-- TODO: At some point, rust probably adds this?
38
39
-- vim.lsp.buf_request(bufnr or 0, 'experimental/inlayHints', inlay_hints.get_params(), inlay_hints.get_callback(opts))
@@ -45,10 +46,10 @@ inlay_hints.get_callback = function(opts)
45
46
local prefix = opts .prefix or " > "
46
47
local aligned = opts .aligned or false
47
48
49
+ local enabled = opts .enabled or {" ChainingHint" }
50
+
48
51
local only_current_line = opts .only_current_line
49
- if only_current_line == nil then
50
- only_current_line = false
51
- end
52
+ if only_current_line == nil then only_current_line = false end
52
53
53
54
return function (err , _ , result , _ , bufnr )
54
55
-- I'm pretty sure this only happens for unsupported items.
@@ -66,13 +67,26 @@ inlay_hints.get_callback = function(opts)
66
67
67
68
local longest_line = - 1
68
69
70
+ -- Check if something is in the list
71
+ -- in_list({"ChainingHint"})("ChainingHint")
72
+ local in_list = function (list )
73
+ return function (item )
74
+ for _ , f in ipairs (list ) do
75
+ if f == item then return true end
76
+ end
77
+
78
+ return false
79
+ end
80
+ end
81
+
69
82
for _ , hint in ipairs (result ) do
70
83
local finish = hint .range [" end" ].line
71
- if not hint_store [finish ] or hint .kind == " ChainingHint " then
84
+ if not hint_store [finish ] and in_list ( enabled )( hint .kind ) then
72
85
hint_store [finish ] = hint
73
86
74
87
if aligned then
75
- longest_line = math.max (longest_line , # vim .api .nvim_buf_get_lines (bufnr , finish , finish + 1 , false )[1 ])
88
+ longest_line = math.max (longest_line ,
89
+ # vim .api .nvim_buf_get_lines (bufnr , finish , finish + 1 , false )[1 ])
76
90
end
77
91
end
78
92
end
@@ -82,10 +96,9 @@ inlay_hints.get_callback = function(opts)
82
96
83
97
-- Check for any existing / more important virtual text on the line.
84
98
-- TODO: Figure out how stackable virtual text works? What happens if there is more than one??
85
- local existing_virt_text = vim .api .nvim_buf_get_extmarks (bufnr , inlay_hints_ns , {end_line , 0 }, {end_line , 0 }, {})
86
- if not vim .tbl_isempty (existing_virt_text ) then
87
- return
88
- end
99
+ local existing_virt_text = vim .api .nvim_buf_get_extmarks (bufnr , inlay_hints_ns , {end_line , 0 },
100
+ {end_line , 0 }, {})
101
+ if not vim .tbl_isempty (existing_virt_text ) then return end
89
102
90
103
local text
91
104
if aligned then
@@ -94,7 +107,7 @@ inlay_hints.get_callback = function(opts)
94
107
else
95
108
text = prefix .. hint .label
96
109
end
97
- vim .api .nvim_buf_set_virtual_text (bufnr , inlay_hints_ns , end_line , { { text , highlight } }, {})
110
+ vim .api .nvim_buf_set_virtual_text (bufnr , inlay_hints_ns , end_line , {{ text , highlight } }, {})
98
111
end
99
112
100
113
if only_current_line then
@@ -106,22 +119,17 @@ inlay_hints.get_callback = function(opts)
106
119
display_virt_text (hint )
107
120
end
108
121
else
109
- for _ , hint in pairs (hint_store ) do
110
- display_virt_text (hint )
111
- end
122
+ for _ , hint in pairs (hint_store ) do display_virt_text (hint ) end
112
123
end
113
124
end
114
125
end
115
126
116
127
inlay_hints .get_params = function ()
117
- return {
118
- textDocument = vim .lsp .util .make_text_document_params ()
119
- }
128
+ return {textDocument = vim .lsp .util .make_text_document_params ()}
120
129
end
121
130
122
131
inlay_hints .clear = function ()
123
132
vim .api .nvim_buf_clear_namespace (0 , inlay_hints_ns , 0 , - 1 )
124
133
end
125
134
126
-
127
135
return inlay_hints
0 commit comments