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

Commitd61437a

Browse files
committed
feat(lsp): completion support completitem/resolve when popup exist
support completeitem/resolve request to get documentation and showit in popup floating window when cot include popupFixes#29225
1 parent7e2b757 commitd61437a

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

‎runtime/lua/vim/lsp/completion.lua‎

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,153 @@ local function get_augroup(bufnr)
671671
returnstring.format('nvim.lsp.completion_%d',bufnr)
672672
end
673673

674+
---@paramwinidinteger
675+
---@parambufnrinteger
676+
---@paramft?string
677+
localfunctionupdate_popup_window(winid,bufnr,ft)
678+
ifwinidandapi.nvim_win_is_valid(winid)andbufnrandapi.nvim_buf_is_valid(bufnr)then
679+
vim.wo[winid].conceallevel=2
680+
ifftthen
681+
locallang=vim.treesitter.language.get_lang(ft)
682+
iflangthen
683+
localok=pcall(vim.treesitter.get_parser,bufnr,lang)
684+
ifokthen
685+
vim.treesitter.start(bufnr,lang)
686+
end
687+
else
688+
vim.wo[winid].eventignorewin='OptionSet'
689+
vim.bo[bufnr].filetype=ft
690+
end
691+
end
692+
localall=api.nvim_win_text_height(winid, {}).all
693+
api.nvim_win_set_height(winid,all)
694+
end
695+
end
696+
697+
---@returnfunction
698+
localfunctioncmpitem_resolve()
699+
localdoc_rtt_ms=100
700+
localdoc_compute_new_average=exp_avg(10,5)
701+
702+
localinfoContext= {
703+
timer=nil,-- [[uv_time_t]]
704+
request_ids= {},--- @typetable<integer,integer>
705+
bufnr=nil,
706+
word=nil,
707+
last_request_time=nil,
708+
}
709+
710+
localfunctionnext_doc_debounce()
711+
ifnotinfoContext.last_request_timethen
712+
returndoc_rtt_ms
713+
end
714+
715+
localms_since_request= (vim.uv.hrtime()-infoContext.last_request_time)*ns_to_ms
716+
returnmath.max((ms_since_request-doc_rtt_ms)*-1,0)
717+
end
718+
719+
localfunctioncancel_pending()
720+
forclient_id,request_idinpairs(infoContext.request_ids)do
721+
localclient=lsp.get_client_by_id(client_id)
722+
ifclientthen
723+
client:cancel_request(request_id)
724+
end
725+
end
726+
infoContext.request_ids= {}
727+
end
728+
729+
localfunctioncleanup()
730+
ifinfoContext.timerandnotinfoContext.timer:is_closing()then
731+
infoContext.timer:stop()
732+
infoContext.timer:close()
733+
infoContext.timer=nil
734+
end
735+
cancel_pending()
736+
end
737+
738+
---@returnboolean,table
739+
localfunctionis_valid()
740+
localcmp_info=vim.fn.complete_info({'selected','completed'})
741+
returnapi.nvim_buf_is_valid(infoContext.bufnr)
742+
andapi.nvim_get_current_buf()==infoContext.bufnr
743+
andvim.startswith(api.nvim_get_mode().mode,'i')
744+
andtonumber(vim.fn.pumvisible())==1
745+
and (vim.tbl_get(cmp_info,'completed','word')or'')==infoContext.word,
746+
cmp_info
747+
end
748+
749+
returnfunction(bufnr,param,select_word)
750+
cleanup()
751+
752+
infoContext.bufnr=bufnr
753+
infoContext.word=select_word
754+
localdebounce_time=next_doc_debounce()
755+
756+
infoContext.timer=assert(vim.uv.new_timer())
757+
infoContext.timer:start(
758+
debounce_time,
759+
0,
760+
vim.schedule_wrap(function()
761+
localvalid,cmp_info=is_valid()
762+
ifnotvalidthen
763+
cleanup()
764+
return
765+
end
766+
767+
cancel_pending()
768+
localclient_id=vim.tbl_get(cmp_info.completed,'user_data','nvim','lsp','client_id')
769+
localclient=client_idandlsp.get_client_by_id(client_id)
770+
ifnotclientthen
771+
return
772+
end
773+
774+
localstart_time=vim.uv.hrtime()
775+
infoContext.last_request_time=start_time
776+
777+
localok,request_id=client:request(
778+
vim.lsp.protocol.Methods.completionItem_resolve,
779+
param,
780+
function(err,result)
781+
localend_time=vim.uv.hrtime()
782+
localresponse_time= (end_time-start_time)*ns_to_ms
783+
doc_rtt_ms=doc_compute_new_average(response_time)
784+
785+
iferrornotresultornext(result)==nilthen
786+
iferrthen
787+
vim.notify(err.message,vim.log.levels.WARN)
788+
end
789+
return
790+
end
791+
792+
valid,cmp_info=is_valid()
793+
ifnotvalidthen
794+
return
795+
end
796+
797+
localvalue=vim.tbl_get(result,'documentation','value')
798+
ifnotvaluethen
799+
return
800+
end
801+
802+
localwindata=api.nvim__complete_set(cmp_info.selected, {
803+
info=value,
804+
})
805+
localkind=vim.tbl_get(result,'documentation','kind')
806+
update_popup_window(windata.winid,windata.bufnr,kind)
807+
end,
808+
bufnr
809+
)
810+
811+
ifokandrequest_idthen
812+
infoContext.request_ids[client.id]=request_id
813+
end
814+
end)
815+
)
816+
end
817+
end
818+
819+
localdebounce_info_request=cmpitem_resolve()
820+
674821
--- @classvim.lsp.completion.BufferOpts
675822
--- @fieldautotrigger?boolean Default:false When true,completion triggers automatically based on the server's `triggerCharacters`.
676823
--- @fieldconvert?fun(item:lsp.CompletionItem):table Transforms an LSP CompletionItem to|complete-items|.
@@ -706,6 +853,33 @@ local function enable_completions(client_id, bufnr, opts)
706853
end
707854
end,
708855
})
856+
857+
ifvim.o.completeopt:find('popup')then
858+
api.nvim_create_autocmd('completechanged', {
859+
group=group,
860+
buffer=bufnr,
861+
callback=function(args)
862+
localcompleted_item=api.nvim_get_vvar('event').completed_itemor {}
863+
if (completed_item.infoor'')~=''then
864+
localdata=vim.fn.complete_info({'selected'})
865+
update_popup_window(data.preview_winid,data.preview_bufnr)
866+
return
867+
end
868+
869+
local_client_id=vim.tbl_get(completed_item,'user_data','nvim','lsp','client_id')
870+
ifnotlsp.get_client_by_id(client_id)then
871+
return
872+
end
873+
874+
localparam=vim.tbl_get(completed_item,'user_data','nvim','lsp','completion_item')
875+
ifparamthen
876+
debounce_info_request(args.buf,param,completed_item.word)
877+
end
878+
end,
879+
desc='Request and display LSP completion item documentation via completionItem/resolve',
880+
})
881+
end
882+
709883
ifopts.autotriggerthen
710884
api.nvim_create_autocmd('InsertCharPre', {
711885
group=group,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp