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