Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromneovim/neovim

Commitca50b70

Browse files
committed
feat(lsp/codelens): allow display codelens above the line
1 parent09c045a commitca50b70

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

‎runtime/lua/vim/lsp/codelens.lua‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ local M = {}
77
--- to throttle refreshes to at most one at a time
88
localactive_refreshes= {}
99

10+
--- bufnr -> lnum -> padding
11+
localpadding_cache_by_buf=setmetatable({}, {
12+
__index=function(t,b)
13+
localkey=b>0andborapi.nvim_get_current_buf()
14+
t[key]= {}
15+
returnrawget(t,key)
16+
end,
17+
})
18+
1019
--- bufnr -> lnum -> extmark
1120
localextmarks_cache_by_buf=setmetatable({}, {
1221
__index=function(t,b)
@@ -69,6 +78,20 @@ local function execute_lens(lens, bufnr, client_id)
6978
end,bufnr)
7079
end
7180

81+
localfunctionget_padding_lnum(bufnr,lnum)
82+
ifnotpadding_cache_by_buf[bufnr][lnum]then
83+
localline=vim.api.nvim_buf_get_lines(bufnr,lnum,lnum+1,true)[1]
84+
85+
local_,first=line:find('^%s*.')
86+
first=firstandfirst-1or0
87+
88+
localpadding=string.rep('',first)
89+
padding_cache_by_buf[bufnr][lnum]=padding
90+
end
91+
92+
returnpadding_cache_by_buf[bufnr][lnum]
93+
end
94+
7295
--- Return all lenses for the given buffer
7396
---
7497
---@parambufnrnumber Buffer number. 0 can be used for the current buffer.
@@ -90,9 +113,18 @@ local function set_extmark(chunks, bufnr, i, ns, prev_extmarks)
90113
localopts= {
91114
id=id,
92115
hl_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+
ifi>1then
122+
opts.virt_lines= {chunks }
123+
opts.virt_lines_above=true
124+
else
125+
opts.virt_text=chunks
126+
end
127+
96128
ifidthen
97129
-- may raise 'line value outside range' outside range
98130
localok,_=pcall(api.nvim_buf_set_extmark,bufnr,ns,i,0,opts)
@@ -183,7 +215,13 @@ function M.display(lenses, bufnr, client_id, prev_extmarks)
183215
end)
184216
localchunks= {}
185217
forj,lensinipairs(line_lenses)do
186-
localtext=lens.commandandlens.command.titleor'Unresolved lens ...'
218+
-- TODO make it optional; see vim.lsp.with
219+
localpadding=''
220+
ifj==1then
221+
padding=get_padding_lnum(bufnr,i)
222+
end
223+
224+
localtext=padding.. (lens.commandandlens.command.titleor'Unresolved lens ...')
187225
table.insert(chunks, {text,'LspCodeLens'})
188226
ifj<#line_lensesthen
189227
table.insert(chunks, {' |','LspCodeLensSeparator'})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp