manateelazycat / lsp-bridge

A blazingly fast LSP client for Emacs
GNU General Public License v3.0
1.36k stars 197 forks source link

Inlay hints #899

Closed milanjovanovic closed 3 months ago

milanjovanovic commented 3 months ago

Hi, I'm using lsp-bridge with rust-analyzer. I have an issue with inlay hints, most of the time I need to C-k (kill-line) for inlay hints to be shown in newly added lines but in new empty project hint is shown after Return. Does is somehow depend on project size ? Thanks

manateelazycat commented 3 months ago

Inlay hint running in lsp-bridge-monitor-post-command function, maybe we need submit a inlay hint request to LSP server once we open some file.

milanjovanovic commented 3 months ago

I'm not talking about hints after opening file, I'm fine with current behaviour when opening new file. This is already in open file that is already showing hints in the buffer, then I start typing new function for example:

pre_kl

So, it's not showing hints until I do C-k (kill-line). After C-k

post_kl

I can't figure out what is causing this behaviour because sometimes it does work ok (showing hints after Ret). I'm trying to figure it out by myself but no luck for now, I would appreciate guidance where to look. Thanks.

manateelazycat commented 3 months ago

Reference links:

I recommend that you first enable the option lsp-bridge-enable-log, then observe the return log of *lsp-bridge*. From my experience, there are only two reasons:

  1. The lsp server returned an inlay hint message, and we have not fully parsed it.
  2. The lsp-bridge-inlay-hint function is not sending enough; we need to increase the frequency of sending. Currently, inlay hint requests are only sent after modifying the code or scrolling the window.

Note that the lsp-bridge-enable-log option will affect performance. Please turn it off after debugging to avoid affecting your normal use.

milanjovanovic commented 3 months ago

I'm seeing that LSP-BRIDGE-INLAY-HINT--RENDER is not being called (when I edit file or press RET) until I do 'kill-line'.

LSP-BRIDGE-INLAY-HINT is being called all the time though.

What I'm seeing in project that doesn't work when I press RET is:

Recv message (error): { "jsonrpc": "2.0", "id": 30617, "error": { "code": -32801, "message": "content modified" } }

In project that works I get LSP-BRIDGE-INLAY-HINT--RENDER call all the time and no lsp-server errors like this.

milanjovanovic commented 3 months ago

This is from log, every time before the error I see this sequence, I don't know much about lsp protocol but it looks like second "didChange" call is invalidating "inlayHint" request ?

--- [17:07:55.093370] Send textDocument/inlayHint request (11744) to 'rust-analyzer' for project rsbom --- [17:07:55.096867] Send textDocument/didChange notification to 'rust-analyzer' for project rsbom

Recv message (error): { "jsonrpc": "2.0", "id": 11744, "error": { "code": -32801, "message": "content modified" } }

milanjovanovic commented 3 months ago

This looks like some kind of race condition with LSP-BRIDGE-MONITOR-POST-COMMAND and LSP-BRIDGE-MONITOR-AFTER-CHANGE. When I insert 50ms sleep in LSP-BRIDGE-MONITOR-POST-COMMAND it does work.

manateelazycat commented 3 months ago

@milanjovanovic Thanks for the detailed research. I have pushed the patch https://github.com/manateelazycat/lsp-bridge/commit/dfabfc818c688b38fce8c09323bd8ed9bcdd011f to fix this problem. Please update and try again. ;)

manateelazycat commented 3 months ago

Please re-open this issue if update newest version still have problem.