-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
TUI / GUI tooltip with content from ALEHover #1556
Conversation
I added a bunch of If we agree on the basic mechanism, we can start discussing about how making this clean (options for the user, avoid writing information at 2 positions, avoid code duplication...) EDIT : as a side-note, I didn't touch the tsserver handler because I just wanted a dirty fix to show what needs to be done, but it's basically the same implementation as the LSPHandler, use the string passed to |
autoload/ale/balloon.vim
Outdated
function! ale#balloon#Disable() abort | ||
set noballooneval balloonexpr= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to check for features here. We ought not to call these functions if you don't have the features for them.
autoload/ale/balloon.vim
Outdated
@@ -19,10 +19,43 @@ function! ale#balloon#Expr() abort | |||
return ale#balloon#MessageForPos(v:beval_bufnr, v:beval_lnum, v:beval_col) | |||
endfunction | |||
|
|||
function! ale#balloon#HoverExpr() abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALE already uses balloons for diagnostics. I think we should make hovering over a position show details in a balloon if and only if you turn an option for hovering on, and we should show diagnostics on hover if you have that option on. For echoing hover messages, which is something I would also like to implement, I'd prioritize problems over hover information. For hovering with a mouse cover, it might make more sense to do the opposite.
This change is requested to be able to call the function with mouse position to enable hover information in vim's balloon
This check prevented the 'ALEHover in balloon' feature, since mouse position is almost never cursor position.
Note : the tests currently fail because vim versions that have I'm assuming tests are failing because vim versions in test instances are in this gap. |
balloonexpr evaluation now works even without balloon_show for basic diagnostics, leaving the balloon_show call to ale#hover#Show, which can then feature guard the call to avoid errors
Also add a small comment to warn readers the different outputs the ale#hover#Show will write to
It seems like it's impossible to use The only thing that still irks me is having the |
The last (I think) 'pure design' decision remaining is knowing if we should print Hover output to both messages and balloon or just balloon when enabled and available. The issue with having both output is for multiline output (that trigger a new split and take the cursor), because not having the cursor in the same window anymore breaks Hover (see the GIFs).
|
Something happened in the merge, hopefully it's some Appveyor bug so it will magically repair in the next commit, otherwise I don't see how this operation broke anything |
It is clearer that we only rely on l:options to get the relevant data to build the LSP Response string
The issue was caused by not using a buffer-specific version of getline() to cap the value of the column sent in the message to LSP. Therefore a cursor on column 10 in an inactive window could send a message with column=0, if the active window had a buffer with too few lines
With the upcoming change in ale_set_balloons default value (see Pull Request dense-analysis#1565), this check will be useless
I've fixed my issue with the preview window (I forgot to replace a So now the behaviour for
On the points that may need a little fixing so the whole feature feels less experimental :
The whole inspiration for this idea came from Bram's termdebug plugin, which sets a local flag in balloonexpr and print/reset the flag accordingly in the callback |
The goal of this flag is to make `:ALEHover` calls not pop a balloon under the cursor, since the user has probably no interest in their cursor while typing the command The flag is a default argument which is overridden only in ballonexpr call of ale#hover#Show, and stays set in the hover_map until the callback for the LSP handles it. There are no automated tests for this feature right now, and the nature of the addition (one optional argument in the API) should make it transparent to existing tests. Since the differentiation is now possible, the check for moved cursor has been put back in ale#hover#HandleLSPResponse
Using get() is safer than trying to access directly with ., as the tests show.
The last commit raised the timeout on one failing appveyor test, since the output from the tests seemed to show that the linter was not finished when the check was called. Feel free to revert it. EDIT : Small gif to show the feature finalized (Notice how the mouse do not trigger the message in the command line, and how the |
It sounds like you hit a similar issue to what I hit with Vim. Vim doesn't like you showing messages via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty damn good. Nice stuff. 👍
autoload/ale/hover.vim
Outdated
" Currently, the callbacks displays the info | ||
" - in the balloon if requested from balloonexpr and balloon_show is detected | ||
" - as status message otherwise | ||
function! ale#hover#Show(buffer, line, col, ...) abort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping track of the arguments will probably get a bit tedious as we go on. I think it's probably best to just write a single argument here instead, which contains all of the arguments in on Dictionary
. That's probably the most future-proof option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional arguments is my (lazy) way of making changes without having to delve too much in changing the tests to make them work, this is definitely something I want to make better. I'll implement the dictionary, and call it opt (for optional arguments).
The get()
function should help with default values anyway.
autoload/ale/hover.vim
Outdated
\|| min([l:column, l:end]) isnot min([l:options.column, l:end]) | ||
" Cancel display the message if the cursor has moved. | ||
return | ||
if !get(l:options, 'hover_from_balloonexpr', 0) " If the call did __not__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the comments on the RHS to lines above instead. That's my preferred style.
call ale#util#ShowMessage(a:response.body.displayString) | ||
if get(l:options, 'hover_from_balloonexpr', 0) | ||
\&& exists('*balloon_show') | ||
\&& ale#Var(l:options.buffer, 'set_balloons') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to think about the meaning of the set_balloons
setting. I guess it makes sense how you've done it here. I doubt many people really look at the balloons for the error messages at the moment.
I say we should do it how you've done it here, and update the documentation to say that the option also enables hover information for LSP and tsserver.
I might update the tsserver stuff myself, or you can give it a go if you want. If you install TypeScript into node_modules
for a project, it should be pretty easy to get it running tsserver
comes with TypeScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed that the ale#hover
callbacks were only called by ale#hover#Show
, and therefore the value of set_ballons in this context is only relevant for the Hover information to begin with. I think this specific part of the code is not related to the actual design decision, it's really just a sanity check on what the user asked for relatively to balloons before we make it appear.
The part that makes the meaning of set_balloons
matter in a "hover vs diagnostics" way is in ale#balloon#MessageForPos
(where I decided that if diagnostics are found, show them and don't even try to get hover information for the position).
This optional dictionary has documentation just before the function using it, ale#hover#Show, and allows easier extension in the future.
I think the "nice" way to make this work if to call the whole But as far as I understand, it's not possible to create a job for vim functions, so I think the easy way is to leave it this way, and hope that async support for vim functions will happen some day (neovim can already create children processes can't it ?) |
Let's go with it, and get others to try it. Cheers! 🍻 |
This is a RFC / small fix maybe.
I would like to have
:ALEHover
content displayed in a tooltip liketermdebug
plugin so beautifully do in vimI found out that ale already uses the balloon feature that termdebug uses under the hood, therefore I would like to find the correct way to access the string that
ale#hover#Show()
ultimately shows in the message bar. I discovered that it's not that easy. What do you think the best way is ?Should I reimplement all functions that autoload/hover.vim uses ?
Ultimately, the goal is to allow users to choose a source for the
balloonexpr
, from loclist like it's currently done, or from:ALEHover
content (typically a setting that would be buffer dependent, so it's possible to activate the Hover source only for filetypes where LSP linters are plugged in)Also, since I was there, I added some guards around the
set ballooneval
, so neovim or old vim versions won't complain, and also addedballoonevalterm
because in vim the GUI and TUI tooltips are separated options (but I assumed that we would want them in all possible cases if the user activated the feature).