@@ -146,6 +146,30 @@ function M.clear(buf)
146
146
pcall (vim .api .nvim_buf_clear_namespace , buf , DIAGNOSTIC_NAMESPACE , 0 , - 1 )
147
147
end
148
148
149
+ --- Count characters of inlay hints on a line
150
+ --- @param buf number
151
+ --- @param linenr number
152
+ local function count_inlay_hints_characters (buf , linenr )
153
+ local inlay_hints = vim .lsp .inlay_hint .get ({
154
+ bufnr = buf ,
155
+ range = {
156
+ start = { line = linenr , character = 0 },
157
+ [" end" ] = { line = linenr , character = - 1 },
158
+ },
159
+ })
160
+ local count = 0
161
+ for _ , hint in ipairs (inlay_hints ) do
162
+ if type (hint .inlay_hint .label ) == " string" then
163
+ count = count + # hint .inlay_hint .label
164
+ else
165
+ for _ , label in ipairs (hint .inlay_hint .label ) do
166
+ count = count + # label .value
167
+ end
168
+ end
169
+ end
170
+ return count
171
+ end
172
+
149
173
--- @param bufnr number
150
174
--- @param linenr number
151
175
--- @param col number
@@ -163,12 +187,12 @@ function M.get_extmarks_on_line(bufnr, linenr, col)
163
187
return vim .api .nvim_buf_get_extmarks (bufnr , - 1 , { linenr , col }, { linenr , - 1 }, opts )
164
188
end
165
189
166
- --- @param buf number
190
+ --- @param bufnr number
167
191
--- @param curline number
168
192
--- @param col number
169
193
--- @return number
170
- function M .handle_other_extmarks (_ , buf , curline , col )
171
- local extmarks = M .get_extmarks_on_line (buf , curline , col )
194
+ function M .handle_other_extmarks (_ , bufnr , curline , col )
195
+ local extmarks = M .get_extmarks_on_line (bufnr , curline , col )
172
196
local offset = 0
173
197
174
198
for _ , extmark in ipairs (extmarks ) do
@@ -180,6 +204,11 @@ function M.handle_other_extmarks(_, buf, curline, col)
180
204
end
181
205
end
182
206
207
+ if vim .lsp .inlay_hint .is_enabled ({ bufnr = bufnr }) then
208
+ local inlay_hints_count = count_inlay_hints_characters (bufnr , curline )
209
+ offset = offset + inlay_hints_count
210
+ end
211
+
183
212
return offset
184
213
end
185
214
0 commit comments