ClangCodeModel: Work around clangd cursor issue

If the cursor is right before the "." in a member access expression,
clangd interprets it as belonging to the member instead of the base
expression, which leads to unexpected behavior.
Work around this by sending a cursor position one to the left of the
real one to clangd in such cases.

Change-Id: I429ee9189760ccb02d231acfcb94ab6cfde3cd8d
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-12-02 13:18:02 +01:00
parent 0f9aa307a3
commit 825c9ea64f
4 changed files with 75 additions and 14 deletions

View File

@@ -523,8 +523,10 @@ void Client::requestDocumentHighlights(TextEditor::TextEditorWidget *widget)
if (m_highlightRequests.contains(widget))
cancelRequest(m_highlightRequests.take(widget));
const QTextCursor adjustedCursor = adjustedCursorForHighlighting(widget->textCursor(),
widget->textDocument());
DocumentHighlightsRequest request(
TextDocumentPositionParams(TextDocumentIdentifier(uri), Position(widget->textCursor())));
TextDocumentPositionParams(TextDocumentIdentifier(uri), Position{adjustedCursor}));
auto connection = connect(widget, &QObject::destroyed, this, [this, widget]() {
if (m_highlightRequests.contains(widget))
cancelRequest(m_highlightRequests.take(widget));
@@ -1570,4 +1572,11 @@ bool Client::sendWorkspceFolderChanges() const
return false;
}
QTextCursor Client::adjustedCursorForHighlighting(const QTextCursor &cursor,
TextEditor::TextDocument *doc)
{
Q_UNUSED(doc)
return cursor;
}
} // namespace LanguageClient