Closed prabirshrestha closed 4 years ago
Sorry nit-picks. Totally LGTM.
@mattn no worries. I'm completely new to ctrlp code base. I did notice it but was more interested in getting proof of concept working.
For LSP servers we get the following response. Currently I'm getting the text from reading the file but I then loose this object. What is a better way to convert this to line also also preserve this entire object so when I go to the accept
callback we can get this raw object.
{
"location": {
"uri": "file:///home/prabirshrestha/code/others/typescript-language-server/node_modules/typescript/lib/lib.es5.d.ts",
"range": {
"end": {
"character": 16,
"line": 111
},
"start": {
"character": 4,
"line": 111
}
}
},
"name": "get",
"kind": 6
}
I worried that the "lines" can be modified from user's code.
Makes sense. But for other providers I see them doing the copy instead.
fu! ctrlp#bookmarkdir#init()
cal s:setentries()
cal s:syntax()
retu s:process(copy(s:bookmarks[1]), ':.')
endf
When would one change "lines". I was hoping g:ctrlp_lines
is actually internal since it wasn't documented.
Ah. Right. I don't want to make g:ctrlp_lines
be private variable since someone may already use it. So ctrlp#set
and ctrlp#get
is not required?
I'm ok removing ctrlp#set
and ctrlp#get
if we say g:ctrlp_lines
is the way to go and is ok to be public. I had thought of this too but wasn't sure. For now I will remove get
and set
methods. this would avoid introducing new apis.
Any idea on how to attach a metadata to a line? Something like user_data
for for completion items.
One option would be to use syntax but not the best way.
1| method helloWorld() hello.ts
2| method serve.start() server.ts
Also what is this function used for? not sure how to use it though. it does seem to modify g:ctrlp_lines
fu! ctrlp#setlines(...)
cal call('s:setlines_pre', a:000)
cal s:setlines_post()
endf
Apparently seems like we can do this currently without touching g:ctrlp_lines
based on the code.
let s:items = []
function! ctrlp#lsp#workspace_symbol#init() abort
return s:items
endfunction
" for onchange. `setlines()` seems to call init.
function! ctrlp#lsp#workspace_symbol#change() abort
let s:items = ['a', 'b', 'c']
call ctrlp#setlines()
call ctrlp#update()
endfunction
This might actually be better though it does get a bit ugly with script level variables.
Updated PR to remove ctrlp#get()
and ctrlp#set()
and also used ctrlp#setlines()
in vim-lsp.
Looks better.
Actually non of the functions seems to be documented. So this is good to be merged now. Docs can come later.
I also renamed change
to be search
instead since I would like to bring quickpick's another feature that is listen for selection changes. This allows to implement another features such as live colorscheme changes or popup to provide more info.
Thank you!
Thanks for the quick reviews and merge. Exiting to see what others will now build with these apis.
This is a PR to solve the issue I mentioned at https://github.com/ctrlpvim/ctrlp.vim/issues/200. The idea comes from quickpick.vim
You can find a working example here. https://github.com/prabirshrestha/vim-lsp/pull/826
This requires changes to ctrlp. View demo at https://asciinema.org/a/333925.
Most of the heavy lifting is already done via lsp servers so it is very fast and responsive.
ctrlp#input
to get the current search termchange
search
event to listen to the change in search termctrlp#set(lines)
to set the lines. to clear usectrl#set([])
ctrlp#get()
to get the linesctrlp#update()
to force re-render once you set.user_data
forset
so in accepts can get the value and do something with it. I'm thinking more of this where we can set an array of objects and then instead haveget_line_text
function which returnitem.label
. And we would also need to make sure that theaccept
takes in the entire object instead of just str.ctrlp#busy(1)