casouri / eldoc-box

childframe doc for eglot and anything that uses eldoc
360 stars 26 forks source link

eldoc-box and lsp-ui integration #27

Closed andreyorst closed 2 years ago

andreyorst commented 4 years ago

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

casouri commented 4 years ago

Hmmm, what would be the ideal behavior for this?

andreyorst commented 4 years ago

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:

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.

casouri commented 4 years ago

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.

andreyorst commented 4 years ago

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

casouri commented 4 years ago

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.