Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions liteidex/src/plugins/gopls/goplsplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void GoplsPlugin::clientStopped()
m_navigationStarts.clear();
m_navigationEnds.clear();
m_navigationHoverText.clear();
m_pendingNavigations.clear();
m_metadataWarnings.clear();
setLegacyCompletionEnabled(true);
if (m_restartClient) {
Expand Down Expand Up @@ -493,6 +494,8 @@ void GoplsPlugin::editorAboutToClose(LiteApi::IEditor *editor)
m_completionEditors.remove(requestId);
m_completionPrefixes.remove(requestId);
m_completionRoots.remove(requestId);
m_navigationEditors.remove(m_pendingNavigations.take(editor));
m_navigationHoverText.remove(editor);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

int hoverId = m_pendingHovers.take(editor);
if (hoverId) {
m_client->notify("$/cancelRequest",QJsonObject{{"id",hoverId}});
Expand Down Expand Up @@ -667,14 +670,11 @@ void GoplsPlugin::handleLocationResponse(int id, const QJsonValue &result, const
}
QJsonObject start = range.value("start").toObject();
if (navigationEditor) {
QString hoverText = m_navigationHoverText.take(navigationEditor);
if (hoverText.isEmpty()) {
LiteApi::ILiteEditor *liteEditor = LiteApi::getLiteEditor(navigationEditor);
if (liteEditor) {
liteEditor->clearLink();
}
if (m_pendingNavigations.value(navigationEditor) != id) {
return;
}
m_pendingNavigations.remove(navigationEditor);
QString hoverText = m_navigationHoverText.take(navigationEditor);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

LiteApi::Link link;
link.linkTextStart = navigationStart;
link.linkTextEnd = navigationEnd;
Expand All @@ -686,8 +686,7 @@ void GoplsPlugin::handleLocationResponse(int id, const QJsonValue &result, const
link.targetColumn = start.value("character").toInt();
QString location = QString("> %1:%2:%3")
.arg(link.targetFileName).arg(link.targetLine + 1).arg(link.targetColumn + 1);
link.sourceInfo = hoverText + "\n\n";
link.sourceInfo += location;
link.sourceInfo = hoverText.isEmpty() ? location : hoverText + "\n\n" + location;
link.targetInfo = link.sourceInfo;
LiteApi::ILiteEditor *liteEditor = LiteApi::getLiteEditor(navigationEditor);
if (liteEditor) {
Expand All @@ -697,7 +696,8 @@ void GoplsPlugin::handleLocationResponse(int id, const QJsonValue &result, const
}
LiteApi::gotoLine(m_liteApp,QUrl(uri).toLocalFile(),start.value("line").toInt(),start.value("character").toInt(),true,true);
}
else if (navigationEditor) {
else if (navigationEditor && m_pendingNavigations.value(navigationEditor) == id) {
m_pendingNavigations.remove(navigationEditor);
LiteApi::ILiteEditor *liteEditor = LiteApi::getLiteEditor(navigationEditor);
if (liteEditor) {
liteEditor->clearLink();
Expand Down Expand Up @@ -911,6 +911,7 @@ void GoplsPlugin::hoverRequested(const QTextCursor &cursor, const QPoint &positi
m_locationRequests.insert(id,"textDocument/definition");
m_locationSearchText.insert(id,LiteApi::wordUnderCursor(requestCursor));
m_navigationEditors.insert(id,editor);
m_pendingNavigations.insert(editor,id);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

m_navigationPositions.insert(id,position);
m_navigationStarts.insert(id,cursor.selectionStart());
m_navigationEnds.insert(id,cursor.selectionEnd());
Expand Down
1 change: 1 addition & 0 deletions liteidex/src/plugins/gopls/goplsplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private slots:
QHash<int,int> m_navigationStarts;
QHash<int,int> m_navigationEnds;
QHash<LiteApi::IEditor*,QString> m_navigationHoverText;
QHash<LiteApi::IEditor*,int> m_pendingNavigations;
GoplsSearchResults *m_searchResults;
QAction *m_definitionAction;
QAction *m_referencesAction;
Expand Down
Loading