eldoc-box icon indicating copy to clipboard operation
eldoc-box copied to clipboard

eldoc-box and lsp-ui integration

Open andreyorst opened this issue 5 years ago • 5 comments
trafficstars

It's chicken egg problem where to solve this, but recently I've started using lsp-mode with lsp-ui package, and found out that it's quite nice to see both information from eldoc and documentation on hover:

image

However there's a problem. When there's not enough space, or when lsp-ui just feels like it, it will show documentation below the cursor:

image

Eldoc box seem to always prefer below the point position which causes those two to overlap:

image

Also, documentation popup aligns to the word we currently at, not point, so I think it may be possible to figure out correct position for eldoc box to prevent overlapping

andreyorst avatar Mar 18 '20 07:03 andreyorst

Hmmm, what would be the ideal behavior for this?

casouri avatar Mar 18 '20 12:03 casouri

It's complicated. I think sticking to the opposite side of the line is fine (like the first screenshot), but this means that we may hit the same problem of not enough space, like when the line we currently on is the top one.

Second option is to put those alongside:

above:

 __________               | window
|          |              | edge
|          | ___________  |
|  lsp-ui  ||           | |
|          || eldoc-box | |
|__________||___________| |
item                      |

below:

item                      | window
 __________  ___________  | edge
|          ||           | | 
|          || eldoc-box | | 
|  lsp-ui  ||___________| | 
|          |              | 
|__________|              | 

above left:

              __________  | window
             |          | | edge
 ___________ |          | | 
|           ||  lsp-ui  | | 
| eldoc-box ||          | | 
|___________||__________| | 
item at window edge       |

below left:

item at window edge       | window
 ___________  __________  | edge
|           ||          | | 
| eldoc-box ||          | | 
|___________||  lsp-ui  | | 
             |          | | 
             |__________| | 

I think the second option may be more complicated, but perhaps you can reuse existing code used for aligning with company? Maybe both ways can be used, e.g. when we have space use the first one, and if not find some place to fit.

There's another problem though. Currently, due some bug, when eldoc displays it's info the lsp-ui doc disappears (it's not your package fault, reproduces with eldoc alone). Here's the report: https://github.com/emacs-lsp/lsp-ui/issues/162. I've managed to workaround it by showing lsp-ui documentation popup after eldoc. So maybe to provide better integration a hook on show of lsp-ui can be used to adjust eldoc-box position?

This means:

  • show eldoc-box as usual
  • if lsp-ui displays it's documenation
    • check if child frames overlap (if possible?)
    • change eldoc-box position so no overlap happen.

The good thing is that once shown lsp-ui documentation popup never move, unlike eldoc box that follows the cursor. And as I've mentioned, lsp-ui documentation box aligns with the word it was invoked upon.

andreyorst avatar Mar 18 '20 15:03 andreyorst

eldoc-box can look at the visible frames before it displays its childframe and make sure its childframe doesn't cover other's. I need to come up with a good algorithm to find a good position for display. This way eldoc-box won't cover other frames, although other frames could cover eldoc-box's frame.

casouri avatar Mar 18 '20 17:03 casouri

Is it possible to run hook on child frame appearance? Because if it is, maybe a more general mechanism should be contributed to make it possible for all packages to align with each other

andreyorst avatar Mar 19 '20 09:03 andreyorst

Generally you want to size and move the child frame before making it visible. But yeah, it would be nice to have a function, given desired position an geometry (and maybe some constrains), returns a closest available (meaning no overlap) position and geometry.

casouri avatar Mar 19 '20 18:03 casouri