@@ -7,6 +7,15 @@ local M = {}
77--- to throttle refreshes to at most one at a time
88local active_refreshes = {}
99
10+ --- bufnr -> lnum -> padding
11+ local padding_cache_by_buf = setmetatable ({}, {
12+ __index = function (t ,b )
13+ local key = b > 0 and b or api .nvim_get_current_buf ()
14+ t [key ]= {}
15+ return rawget (t ,key )
16+ end ,
17+ })
18+
1019--- bufnr -> lnum -> extmark
1120local extmarks_cache_by_buf = setmetatable ({}, {
1221__index = function (t ,b )
@@ -69,6 +78,20 @@ local function execute_lens(lens, bufnr, client_id)
6978end ,bufnr )
7079end
7180
81+ local function get_padding_lnum (bufnr ,lnum )
82+ if not padding_cache_by_buf [bufnr ][lnum ]then
83+ local line = vim .api .nvim_buf_get_lines (bufnr ,lnum ,lnum + 1 ,true )[1 ]
84+
85+ local _ ,first = line :find (' ^%s*.' )
86+ first = first and first - 1 or 0
87+
88+ local padding = string.rep (' ' ,first )
89+ padding_cache_by_buf [bufnr ][lnum ]= padding
90+ end
91+
92+ return padding_cache_by_buf [bufnr ][lnum ]
93+ end
94+
7295--- Return all lenses for the given buffer
7396---
7497--- @param bufnr number Buffer number. 0 can be used for the current buffer.
@@ -90,9 +113,18 @@ local function set_extmark(chunks, bufnr, i, ns, prev_extmarks)
90113local opts = {
91114id = id ,
92115hl_mode = ' combine' ,
93- virt_text = chunks ,
94116 }
95117
118+ -- TODO make it optional; see vim.lsp.with
119+
120+ -- https://github.com/neovim/neovim/issues/16166
121+ if i > 1 then
122+ opts .virt_lines = {chunks }
123+ opts .virt_lines_above = true
124+ else
125+ opts .virt_text = chunks
126+ end
127+
96128if id then
97129-- may raise 'line value outside range' outside range
98130local ok ,_ = pcall (api .nvim_buf_set_extmark ,bufnr ,ns ,i ,0 ,opts )
@@ -183,7 +215,13 @@ function M.display(lenses, bufnr, client_id, prev_extmarks)
183215end )
184216local chunks = {}
185217for j ,lens in ipairs (line_lenses )do
186- local text = lens .command and lens .command .title or ' Unresolved lens ...'
218+ -- TODO make it optional; see vim.lsp.with
219+ local padding = ' '
220+ if j == 1 then
221+ padding = get_padding_lnum (bufnr ,i )
222+ end
223+
224+ local text = padding .. (lens .command and lens .command .title or ' Unresolved lens ...' )
187225table.insert (chunks , {text ,' LspCodeLens' })
188226if j < # line_lenses then
189227table.insert (chunks , {' |' ,' LspCodeLensSeparator' })