forked from qt-creator/qt-creator
Clang: use HighlightingMarks for hover with Ctrl highlighting
Make this highlighting work without builtin code model but based on the HighlightingMarks that we already have from ClangCodeModel. Redundant parameters are removed by this change. Change-Id: I73b5dab46ba59d2f813236831818f0a9bc94c5bc Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -275,7 +275,6 @@ CppTools::SymbolInfo toSymbolInfo(const FollowSymbolMessage &message)
|
||||
result.endLine = static_cast<int>(end.line());
|
||||
result.endColumn = static_cast<int>(end.column());
|
||||
result.fileName = start.filePath();
|
||||
result.failedToFollow = message.failedToFollow();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -748,14 +747,12 @@ QFuture<CppTools::SymbolInfo> IpcCommunicator::requestFollowSymbol(
|
||||
const FileContainer &curFileContainer,
|
||||
const QVector<Utf8String> &dependentFiles,
|
||||
quint32 line,
|
||||
quint32 column,
|
||||
bool resolveTarget)
|
||||
quint32 column)
|
||||
{
|
||||
const RequestFollowSymbolMessage message(curFileContainer,
|
||||
dependentFiles,
|
||||
line,
|
||||
column,
|
||||
resolveTarget);
|
||||
column);
|
||||
m_ipcSender->requestFollowSymbol(message);
|
||||
|
||||
return m_ipcReceiver.addExpectedRequestFollowSymbolMessage(message.ticketNumber());
|
||||
|
||||
@@ -169,8 +169,7 @@ public:
|
||||
QFuture<CppTools::SymbolInfo> requestFollowSymbol(const FileContainer &curFileContainer,
|
||||
const QVector<Utf8String> &dependentFiles,
|
||||
quint32 line,
|
||||
quint32 column,
|
||||
bool resolveTarget);
|
||||
quint32 column);
|
||||
void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath,
|
||||
quint32 line,
|
||||
quint32 column,
|
||||
|
||||
@@ -225,6 +225,12 @@ toTextEditorBlocks(QTextDocument *textDocument,
|
||||
}
|
||||
}
|
||||
|
||||
const QVector<ClangBackEnd::HighlightingMarkContainer>
|
||||
&ClangEditorDocumentProcessor::highlightingMarks() const
|
||||
{
|
||||
return m_highlightingMarks;
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::updateHighlighting(
|
||||
const QVector<ClangBackEnd::HighlightingMarkContainer> &highlightingMarks,
|
||||
const QVector<ClangBackEnd::SourceRangeContainer> &skippedPreprocessorRanges,
|
||||
@@ -234,6 +240,7 @@ void ClangEditorDocumentProcessor::updateHighlighting(
|
||||
const auto skippedPreprocessorBlocks = toTextEditorBlocks(textDocument(), skippedPreprocessorRanges);
|
||||
emit ifdefedOutBlocksUpdated(documentRevision, skippedPreprocessorBlocks);
|
||||
|
||||
m_highlightingMarks = highlightingMarks;
|
||||
m_semanticHighlighter.setHighlightingRunner(
|
||||
[highlightingMarks]() {
|
||||
auto *reporter = new HighlightingMarksReporter(highlightingMarks);
|
||||
@@ -376,7 +383,7 @@ static QVector<Utf8String> prioritizeByBaseName(const QString &curPath,
|
||||
}
|
||||
|
||||
QFuture<CppTools::SymbolInfo>
|
||||
ClangEditorDocumentProcessor::requestFollowSymbol(int line, int column, bool resolveTarget)
|
||||
ClangEditorDocumentProcessor::requestFollowSymbol(int line, int column)
|
||||
{
|
||||
QVector<Utf8String> dependentFiles;
|
||||
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||
@@ -390,8 +397,7 @@ ClangEditorDocumentProcessor::requestFollowSymbol(int line, int column, bool res
|
||||
return m_ipcCommunicator.requestFollowSymbol(simpleFileContainer(),
|
||||
dependentFiles,
|
||||
static_cast<quint32>(line),
|
||||
static_cast<quint32>(column),
|
||||
resolveTarget);
|
||||
static_cast<quint32>(column));
|
||||
}
|
||||
|
||||
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments() const
|
||||
|
||||
@@ -86,14 +86,14 @@ public:
|
||||
void setParserConfig(const CppTools::BaseEditorDocumentParser::Configuration config) override;
|
||||
|
||||
QFuture<CppTools::CursorInfo> cursorInfo(const CppTools::CursorInfoParams ¶ms) override;
|
||||
QFuture<CppTools::SymbolInfo> requestFollowSymbol(int line,
|
||||
int column,
|
||||
bool resolveTarget) override;
|
||||
QFuture<CppTools::SymbolInfo> requestFollowSymbol(int line, int column) override;
|
||||
|
||||
ClangBackEnd::FileContainer fileContainerWithArguments() const;
|
||||
|
||||
void clearDiagnosticsWithFixIts();
|
||||
|
||||
const QVector<ClangBackEnd::HighlightingMarkContainer> &highlightingMarks() const;
|
||||
|
||||
public:
|
||||
static ClangEditorDocumentProcessor *get(const QString &filePath);
|
||||
|
||||
@@ -122,6 +122,7 @@ private:
|
||||
QTimer m_updateTranslationUnitTimer;
|
||||
unsigned m_parserRevision;
|
||||
|
||||
QVector<ClangBackEnd::HighlightingMarkContainer> m_highlightingMarks;
|
||||
CppTools::SemanticHighlighter m_semanticHighlighter;
|
||||
CppTools::BuiltinEditorDocumentProcessor m_builtinProcessor;
|
||||
};
|
||||
|
||||
@@ -23,14 +23,78 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangfollowsymbol.h"
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "texteditor/texteditor.h"
|
||||
#include "texteditor/convenience.h"
|
||||
#include "clangfollowsymbol.h"
|
||||
|
||||
#include <texteditor/convenience.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <clangsupport/highlightingmarkcontainer.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
// Returns invalid Mark if it is not found at (line, column)
|
||||
static bool findMark(const QVector<ClangBackEnd::HighlightingMarkContainer> &marks,
|
||||
uint line,
|
||||
uint column,
|
||||
ClangBackEnd::HighlightingMarkContainer &mark)
|
||||
{
|
||||
mark = Utils::findOrDefault(marks,
|
||||
[line, column](const ClangBackEnd::HighlightingMarkContainer &curMark) {
|
||||
if (curMark.line() != line)
|
||||
return false;
|
||||
if (curMark.column() == column)
|
||||
return true;
|
||||
if (curMark.column() < column && curMark.column() + curMark.length() >= column)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
if (mark.isInvalid())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int getMarkPos(QTextCursor cursor, const ClangBackEnd::HighlightingMarkContainer &mark)
|
||||
{
|
||||
cursor.setPosition(0);
|
||||
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, mark.line() - 1);
|
||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, mark.column() - 1);
|
||||
return cursor.position();
|
||||
}
|
||||
|
||||
static TextEditor::TextEditorWidget::Link linkAtCursor(QTextCursor cursor,
|
||||
const QString &filePath,
|
||||
uint line,
|
||||
uint column,
|
||||
ClangEditorDocumentProcessor *processor)
|
||||
{
|
||||
using Link = TextEditor::TextEditorWidget::Link;
|
||||
|
||||
const QVector<ClangBackEnd::HighlightingMarkContainer> &marks
|
||||
= processor->highlightingMarks();
|
||||
ClangBackEnd::HighlightingMarkContainer mark;
|
||||
if (!findMark(marks, line, column, mark))
|
||||
return Link();
|
||||
|
||||
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
const QString tokenStr = cursor.selectedText();
|
||||
|
||||
Link token(filePath, mark.line(), mark.column());
|
||||
token.linkTextStart = getMarkPos(cursor, mark);
|
||||
token.linkTextEnd = token.linkTextStart + mark.length();
|
||||
if (mark.isIncludeDirectivePath()) {
|
||||
if (tokenStr != "include" && tokenStr != "#" && tokenStr != "<")
|
||||
return token;
|
||||
return Link();
|
||||
}
|
||||
if (mark.isIdentifier() || tokenStr == "operator")
|
||||
return token;
|
||||
return Link();
|
||||
}
|
||||
|
||||
TextEditor::TextEditorWidget::Link ClangFollowSymbol::findLink(
|
||||
const CppTools::CursorInEditor &data,
|
||||
bool resolveTarget,
|
||||
@@ -39,42 +103,39 @@ TextEditor::TextEditorWidget::Link ClangFollowSymbol::findLink(
|
||||
CppTools::SymbolFinder *,
|
||||
bool)
|
||||
{
|
||||
Link link;
|
||||
|
||||
int lineNumber = 0, positionInBlock = 0;
|
||||
QTextCursor cursor = TextEditor::Convenience::wordStartCursor(data.cursor());
|
||||
TextEditor::Convenience::convertPosition(cursor.document(), cursor.position(), &lineNumber,
|
||||
&positionInBlock);
|
||||
const unsigned line = lineNumber;
|
||||
const unsigned column = positionInBlock + 1;
|
||||
|
||||
if (!resolveTarget)
|
||||
return link;
|
||||
const uint line = lineNumber;
|
||||
const uint column = positionInBlock + 1;
|
||||
|
||||
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(
|
||||
data.filePath().toString());
|
||||
if (!processor)
|
||||
return link;
|
||||
return Link();
|
||||
|
||||
if (!resolveTarget)
|
||||
return linkAtCursor(cursor, data.filePath().toString(), line, column, processor);
|
||||
|
||||
QFuture<CppTools::SymbolInfo> info
|
||||
= processor->requestFollowSymbol(static_cast<int>(line),
|
||||
static_cast<int>(column),
|
||||
resolveTarget);
|
||||
static_cast<int>(column));
|
||||
|
||||
if (info.isCanceled())
|
||||
return link;
|
||||
return Link();
|
||||
|
||||
while (!info.isFinished()) {
|
||||
if (info.isCanceled())
|
||||
return link;
|
||||
return Link();
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
CppTools::SymbolInfo result = info.result();
|
||||
|
||||
if (result.failedToFollow)
|
||||
return link;
|
||||
|
||||
// We did not fail but the result is empty
|
||||
if (result.fileName.isEmpty())
|
||||
return link;
|
||||
return Link();
|
||||
|
||||
return Link(result.fileName, result.startLine, result.startColumn - 1);
|
||||
}
|
||||
|
||||
@@ -158,8 +158,15 @@ void HighlightingMarksReporter::run_internal()
|
||||
if (isCanceled())
|
||||
return;
|
||||
|
||||
for (const auto &highlightingMark : m_highlightingMarks)
|
||||
using ClangBackEnd::HighlightingType;
|
||||
|
||||
for (const auto &highlightingMark : m_highlightingMarks) {
|
||||
const HighlightingType mainType = highlightingMark.types().mainHighlightingType;
|
||||
if (mainType == HighlightingType::StringLiteral)
|
||||
continue;
|
||||
|
||||
reportChunkWise(toHighlightingResult(highlightingMark));
|
||||
}
|
||||
|
||||
if (isCanceled())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user