-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Range hover support #836
Comments
Sorry I made a mistake here, what I said is didn't find a better way. rust-analyzer extends the hover request, accepts a position or range and returns document. So the range is passed in coc's We have this mapping now: " Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction How do we use Range hover alone with basic hover action ? |
First of all, to me a range hover only makes sense either in visual mode (the range is the visual area) or using text objects (the range is the area of the text object). In this post I'll be talking only about the visual mode case. It would work like
coc.vim already has a |
This range is used for highlight. I got your point of |
If you can't modify the coc.vim source for some reason, then it's possible to use |
Because the range hover is not in LSP now, IDK we can add it to coc yes or not. Maybe later microsoft/language-server-protocol#377 ?
How to use |
For Instead of calling fun! EchoMode()
echo mode() " mode is 'v'
endfun
vnoremap <silent> <buffer> K <cmd>call EchoMode()<CR> It finally clicked for me that the middleware |
It's my fault, I should point this out in the beginning. |
@resolritter I've made this PR, can you give it a review? Also, if you want to test this, you need to patch coc to make it allow float hover in diff --git a/src/handler/hover.ts b/src/handler/hover.ts
index 23fcb770..521af161 100644
--- a/src/handler/hover.ts
+++ b/src/handler/hover.ts
@@ -152,7 +152,7 @@ export default class HoverHandler {
}
if (target == 'float') {
let opts: FloatWinConfig = {
- modes: ['n'],
+ modes: ['n', 'v'],
maxWidth: this.config.floatMaxWidth,
maxHeight: this.config.floatMaxHeight,
autoHide: this.config.autoHide, |
You're using getSelectedRange while expecting Vim to be in visual mode, however
:<C-U>
kind of mappings (e.g.xmap <Plug>(coc-codeaction-selected)
) exit visual mode before executing the range and therefore that check will not pass.While you could use
<cmd>
mappings to avoid exiting visual mode, exiting is needed to get the visual mode range with'<
and'>
like here (as far as I'm aware it's not possible to do that while staying in visual mode, you have to exit it first for those marks' positions to be updated).So, in short, the solution is to make the mapping work like
xmap <Plug>(coc-codeaction-selected)
where you'll detectvisualmode()
when the mapping is triggered, not after. Here's the doCodeAction code for reference and you'll see that it fetches the visual range using the marks' positions as mentioned.Originally posted by @resolritter in #256 (comment)
The text was updated successfully, but these errors were encountered: