Repository navigation
gopls: fix mouse navigation race with hover response - #1377
rthakur-gateway wants to merge 1 commit into
Conversation
Ctrl/Cmd-hover sends textDocument/hover and textDocument/definition together. The link was only shown if the hover reply arrived first; otherwise the definition reply cleared it, so click navigation failed intermittently. Each mouse move also cancelled the prior hover, making stale definition replies clear the link. Build the link from the definition reply alone (hover text is optional), ignore all but the latest navigation request per editor, and drop pending navigation state when an editor closes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visualfc
left a comment
There was a problem hiding this comment.
The race diagnosis is correct. Ctrl/Cmd-hover sends textDocument/hover and textDocument/definition together, and the old code only showed the link if hover text had already arrived. Tracking the latest definition id per editor with m_pendingNavigations is the right approach.
Please fix the editor-close cleanup before merge. After removing the pending id from m_navigationEditors, a still-in-flight definition reply is handled as a menu Go to Definition and calls gotoLine() on the current editor.
Also clear stale hover text when starting a new navigation. A fast mouse move can attach the previous identifier's hover text to the new link if definition arrives first.
Test plan
- Ctrl/Cmd-hover when definition arrives before hover: link is clickable
- Move quickly across symbols: only the last identifier keeps a link
- Ctrl/Cmd-hover and close the editor immediately: current editor does not jump via
gotoLine - Identifier with no definition: link is cleared
- Menu Go to Definition still jumps
| m_completionPrefixes.remove(requestId); | ||
| m_completionRoots.remove(requestId); | ||
| m_navigationEditors.remove(m_pendingNavigations.take(editor)); | ||
| m_navigationHoverText.remove(editor); |
There was a problem hiding this comment.
This only drops the latest id from m_navigationEditors. m_locationRequests for that id is left in place, and older in-flight definition ids are not removed.
When the reply arrives, navigationEditor is null, so handleLocationResponse falls through to LiteApi::gotoLine() and jumps the current editor.
On close, cancel the pending definition request (hover already does this) and also clear that id from m_locationRequests, m_locationSearchText, m_navigationPositions, m_navigationStarts, and m_navigationEnds. In handleLocationResponse, return immediately if requestMethod is empty.
A cleaner split is to mark mouse-navigation requests separately from menu Go to Definition, so a missing editor pointer is never treated as a jump.
| return; | ||
| } | ||
| m_pendingNavigations.remove(navigationEditor); | ||
| QString hoverText = m_navigationHoverText.take(navigationEditor); |
There was a problem hiding this comment.
hoverRequested does not clear m_navigationHoverText when a new navigation starts.
Sequence: hover foo and the hover reply lands; move to bar; bar's definition arrives first. take() still returns foo's text, so the link target is bar and the tooltip text is foo.
Remove the editor's hover cache when starting a new navigation. If definition arrives first, showing the location-only link is fine.
| m_locationRequests.insert(id,"textDocument/definition"); | ||
| m_locationSearchText.insert(id,LiteApi::wordUnderCursor(requestCursor)); | ||
| m_navigationEditors.insert(id,editor); | ||
| m_pendingNavigations.insert(editor,id); |
There was a problem hiding this comment.
This overwrites the previous pending id without cancelling the old textDocument/definition request. Stale replies are ignored, which is enough for correctness, but rapid mouse movement piles up in-flight requests.
Consider cancelling the previous definition the same way requestHover cancels the previous hover, and drop that old id from the navigation maps. That also reduces leftover ids if the editor closes while several definitions are still in flight.
Ctrl/Cmd-hover sends textDocument/hover and textDocument/definition together. The link was only shown if the hover reply arrived first; otherwise the definition reply cleared it, so click navigation failed intermittently. Each mouse move also cancelled the prior hover, making stale definition replies clear the link.
Build the link from the definition reply alone (hover text is optional), ignore all but the latest navigation request per editor, and drop pending navigation state when an editor closes.