forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user