forked from qt-creator/qt-creator
Clang: simplify column convertion calls
Pass QTextBlock directly into clangColumn call. Change-Id: I3410a82ed9a84da66e7b430e2aefce64ec459db8 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -559,8 +559,7 @@ ClangCompletionAssistProcessor::extractLineColumn(int position)
|
||||
int line = -1, column = -1;
|
||||
::Utils::Text::convertPosition(m_interface->textDocument(), position, &line, &column);
|
||||
|
||||
const QTextBlock block = m_interface->textDocument()->findBlock(position);
|
||||
column = Utils::clangColumn(block.text(), column);
|
||||
column = Utils::clangColumn(m_interface->textDocument()->findBlock(position), column);
|
||||
return {line, column};
|
||||
}
|
||||
|
||||
|
@@ -347,8 +347,7 @@ ClangEditorDocumentProcessor::cursorInfo(const CppTools::CursorInfoParams ¶m
|
||||
if (!isCursorOnIdentifier(params.textCursor))
|
||||
return defaultCursorInfoFuture();
|
||||
|
||||
const QTextBlock block = params.textCursor.document()->findBlockByNumber(line - 1);
|
||||
column = Utils::clangColumn(block.text(), column);
|
||||
column = Utils::clangColumn(params.textCursor.document()->findBlockByNumber(line - 1), column);
|
||||
const CppTools::SemanticInfo::LocalUseMap localUses
|
||||
= CppTools::BuiltinCursorInfo::findLocalUses(params.semanticInfo.doc, line, column);
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
#include <QTextBlock>
|
||||
|
||||
using namespace ClangCodeModel;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
@@ -190,14 +191,14 @@ void setLastSentDocumentRevision(const QString &filePath, uint revision)
|
||||
document->sendTracker().setLastSentRevision(int(revision));
|
||||
}
|
||||
|
||||
int clangColumn(const QString &lineText, int cppEditorColumn)
|
||||
int clangColumn(const QTextBlock &line, int cppEditorColumn)
|
||||
{
|
||||
// (1) cppEditorColumn is the actual column shown by CppEditor.
|
||||
// (2) The return value is the column in Clang which is the utf8 byte offset from the beginning
|
||||
// of the line.
|
||||
// Here we convert column from (1) to (2).
|
||||
// '+ 1' is for 1-based columns
|
||||
return lineText.left(cppEditorColumn).toUtf8().size() + 1;
|
||||
return line.text().left(cppEditorColumn).toUtf8().size() + 1;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -27,6 +27,10 @@
|
||||
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextBlock;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace CppTools {
|
||||
class CppEditorDocumentHandle;
|
||||
}
|
||||
@@ -46,7 +50,7 @@ CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath);
|
||||
CppTools::ProjectPart::Ptr projectPartForFileBasedOnProcessor(const QString &filePath);
|
||||
bool isProjectPartLoaded(const CppTools::ProjectPart::Ptr projectPart);
|
||||
QString projectPartIdForFile(const QString &filePath);
|
||||
int clangColumn(const QString &lineText, int cppEditorColumn);
|
||||
int clangColumn(const QTextBlock &lineText, int cppEditorColumn);
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace Clang
|
||||
|
Reference in New Issue
Block a user