@@ -25,7 +25,7 @@ interface InlayHint {
25
25
label: string,
26
26
}
27
27
```
28
- --]]
28
+ --]]
29
29
30
30
local inlay_hints = {}
31
31
@@ -81,8 +81,12 @@ inlay_hints.get_callback = function(opts)
81
81
82
82
for _ , hint in ipairs (result ) do
83
83
local finish = hint .range [" end" ].line
84
- if not hint_store [finish ] and in_list (enabled )(hint .kind ) then
85
- hint_store [finish ] = hint
84
+ if in_list (enabled )(hint .kind ) then
85
+ if not hint_store [finish ] then
86
+ hint_store [finish ] = {hint }
87
+ elseif hint_store [finish ][1 ].kind == hint .kind then
88
+ table.insert (hint_store [finish ], hint )
89
+ end
86
90
87
91
if aligned then
88
92
longest_line = math.max (longest_line ,
@@ -91,8 +95,8 @@ inlay_hints.get_callback = function(opts)
91
95
end
92
96
end
93
97
94
- local display_virt_text = function (hint )
95
- local end_line = hint .range [" end" ].line
98
+ local display_virt_text = function (hints )
99
+ local end_line = hints [ 1 ] .range [" end" ].line
96
100
97
101
-- Check for any existing / more important virtual text on the line.
98
102
-- TODO: Figure out how stackable virtual text works? What happens if there is more than one??
@@ -101,25 +105,31 @@ inlay_hints.get_callback = function(opts)
101
105
if not vim .tbl_isempty (existing_virt_text ) then return end
102
106
103
107
local text
104
- if aligned then
105
- local line_length = # vim .api .nvim_buf_get_lines (bufnr , end_line , end_line + 1 , false )[1 ]
106
- text = string.format (" %s %s" , (" " ):rep (longest_line - line_length ), prefix .. hint .label )
107
- else
108
- text = prefix .. hint .label
108
+ for _ , hint in ipairs (hints ) do
109
+ if aligned then
110
+ local line_length = # vim .api .nvim_buf_get_lines (bufnr , end_line , end_line + 1 , false )[1 ]
111
+ text = string.format (" %s %s" , (" " ):rep (longest_line - line_length ), prefix .. hint .label )
112
+ else
113
+ if text then
114
+ text = text .. prefix .. hint .label
115
+ else
116
+ text = prefix .. hint .label
117
+ end
118
+ end
109
119
end
110
120
vim .api .nvim_buf_set_virtual_text (bufnr , inlay_hints_ns , end_line , {{text , highlight }}, {})
111
121
end
112
122
113
123
if only_current_line then
114
- local hint = hint_store [vim .api .nvim_win_get_cursor (0 )[1 ] - 1 ]
124
+ local hints = hint_store [vim .api .nvim_win_get_cursor (0 )[1 ] - 1 ]
115
125
116
- if not hint then
126
+ if not hints then
117
127
return
118
128
else
119
- display_virt_text (hint )
129
+ display_virt_text (hints )
120
130
end
121
131
else
122
- for _ , hint in pairs (hint_store ) do display_virt_text (hint ) end
132
+ for _ , hints in pairs (hint_store ) do display_virt_text (hints ) end
123
133
end
124
134
end
125
135
end
0 commit comments