Commit 0db7ad77 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Fix built-in's ExtractFunction action

Since

  Clang: Provide highlighting for identifier under cursor
  commit ca72c294

the LocalUseMap, used for some refactoring actions, was not updated
anymore. Fall back to the built-in implementation for the LocalUseMap
because it contains pointers to built-in AST that clang obviously can't
provide.

Task-number: QTCREATORBUG-18607
Change-Id: I08762fe457835d4d83aca719febcb3497ee9696b
Reviewed-by: Ivan Donchevskii's avatarIvan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: default avatarRobert Loehning <robert.loehning@qt.io>
Reviewed-by: Marco Bubke's avatarMarco Bubke <marco.bubke@qt.io>
parent a9ddbb61
......@@ -129,8 +129,10 @@ void IpcReceiver::deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *t
}
}
QFuture<CppTools::CursorInfo> IpcReceiver::addExpectedReferencesMessage(quint64 ticket,
QTextDocument *textDocument)
QFuture<CppTools::CursorInfo> IpcReceiver::addExpectedReferencesMessage(
quint64 ticket,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
{
QTC_CHECK(textDocument);
QTC_CHECK(!m_referencesTable.contains(ticket));
......@@ -138,7 +140,7 @@ QFuture<CppTools::CursorInfo> IpcReceiver::addExpectedReferencesMessage(quint64
QFutureInterface<CppTools::CursorInfo> futureInterface;
futureInterface.reportStarted();
const ReferencesEntry entry{futureInterface, textDocument};
const ReferencesEntry entry{futureInterface, textDocument, localUses};
m_referencesTable.insert(ticket, entry);
return futureInterface.future();
......@@ -229,6 +231,7 @@ CppTools::CursorInfo::Range toCursorInfoRange(const QTextDocument &textDocument,
static
CppTools::CursorInfo toCursorInfo(const QTextDocument &textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses,
const ReferencesMessage &message)
{
CppTools::CursorInfo result;
......@@ -239,6 +242,7 @@ CppTools::CursorInfo toCursorInfo(const QTextDocument &textDocument,
result.useRanges.append(toCursorInfoRange(textDocument, reference));
result.useRanges.reserve(references.size());
result.localUses = localUses;
return result;
}
......@@ -257,7 +261,7 @@ void IpcReceiver::references(const ReferencesMessage &message)
return; // Editor document closed or a new request was issued making this result outdated.
QTC_ASSERT(entry.textDocument, return);
futureInterface.reportResult(toCursorInfo(*entry.textDocument, message));
futureInterface.reportResult(toCursorInfo(*entry.textDocument, entry.localUses, message));
futureInterface.reportFinished();
}
......@@ -672,12 +676,14 @@ QFuture<CppTools::CursorInfo> IpcCommunicator::requestReferences(
const FileContainer &fileContainer,
quint32 line,
quint32 column,
QTextDocument *textDocument)
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
{
const RequestReferencesMessage message(fileContainer, line, column);
m_ipcSender->requestReferences(message);
return m_ipcReceiver.addExpectedReferencesMessage(message.ticketNumber(), textDocument);
return m_ipcReceiver.addExpectedReferencesMessage(message.ticketNumber(), textDocument,
localUses);
}
void IpcCommunicator::updateTranslationUnitWithRevisionCheck(Core::IDocument *document)
......
......@@ -75,8 +75,10 @@ public:
void addExpectedCodeCompletedMessage(quint64 ticket, ClangCompletionAssistProcessor *processor);
void deleteProcessorsOfEditorWidget(TextEditor::TextEditorWidget *textEditorWidget);
QFuture<CppTools::CursorInfo> addExpectedReferencesMessage(quint64 ticket,
QTextDocument *textDocument);
QFuture<CppTools::CursorInfo>
addExpectedReferencesMessage(quint64 ticket,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses);
bool isExpectingCodeCompletedMessage() const;
void reset();
......@@ -99,11 +101,14 @@ private:
struct ReferencesEntry {
ReferencesEntry() = default;
ReferencesEntry(QFutureInterface<CppTools::CursorInfo> futureInterface,
QTextDocument *textDocument)
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses)
: futureInterface(futureInterface)
, textDocument(textDocument) {}
, textDocument(textDocument)
, localUses(localUses) {}
QFutureInterface<CppTools::CursorInfo> futureInterface;
QPointer<QTextDocument> textDocument;
CppTools::SemanticInfo::LocalUseMap localUses;
};
QHash<quint64, ReferencesEntry> m_referencesTable;
};
......@@ -149,9 +154,12 @@ public:
void registerUnsavedFilesForEditor(const FileContainers &fileContainers);
void unregisterUnsavedFilesForEditor(const FileContainers &fileContainers);
void requestDocumentAnnotations(const ClangBackEnd::FileContainer &fileContainer);
QFuture<CppTools::CursorInfo> requestReferences(const FileContainer &fileContainer,
quint32 line,
quint32 column, QTextDocument *textDocument);
QFuture<CppTools::CursorInfo> requestReferences(
const FileContainer &fileContainer,
quint32 line,
quint32 column,
QTextDocument *textDocument,
const CppTools::SemanticInfo::LocalUseMap &localUses);
void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath,
quint32 line,
quint32 column,
......
......@@ -36,6 +36,7 @@
#include <diagnosticcontainer.h>
#include <sourcelocationcontainer.h>
#include <cpptools/builtincursorinfo.h>
#include <cpptools/clangdiagnosticconfigsmodel.h>
#include <cpptools/clangdiagnosticconfigsmodel.h>
#include <cpptools/compileroptionsbuilder.h>
......@@ -334,11 +335,14 @@ ClangEditorDocumentProcessor::cursorInfo(const CppTools::CursorInfoParams &param
const QTextBlock block = params.textCursor.document()->findBlockByNumber(line - 1);
column += ClangCodeModel::Utils::extraUtf8CharsShift(block.text(), column);
const CppTools::SemanticInfo::LocalUseMap localUses
= CppTools::BuiltinCursorInfo::findLocalUses(params.semanticInfo.doc, line, column);
return m_ipcCommunicator.requestReferences(simpleFileContainer(),
static_cast<quint32>(line),
static_cast<quint32>(column),
textDocument());
textDocument(),
localUses);
}
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments() const
......
......@@ -47,7 +47,6 @@ using namespace CPlusPlus;
using SemanticUses = QList<CppTools::SemanticInfo::Use>;
namespace CppTools {
namespace Internal {
namespace {
CursorInfo::Range toRange(const SemanticInfo::Use &use)
......@@ -186,7 +185,8 @@ private:
{
CursorInfo result;
const CppTools::SemanticInfo::LocalUseMap localUses = findLocalUses();
const CppTools::SemanticInfo::LocalUseMap localUses
= BuiltinCursorInfo::findLocalUses(m_document, m_line, m_column);
result.localUses = localUses;
splitLocalUses(localUses, &result.useRanges, &result.unusedVariablesRanges);
......@@ -200,16 +200,6 @@ private:
return result; // OK, result.unusedVariablesRanges will be passed on
}
CppTools::SemanticInfo::LocalUseMap findLocalUses() const
{
AST *ast = m_document->translationUnit()->ast();
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(m_document->translationUnit());
DeclarationAST *declaration = functionDefinitionUnderCursor(ast,
static_cast<unsigned>(m_line),
static_cast<unsigned>(m_column));
return CppTools::LocalSymbols(m_document, declaration).uses;
}
void splitLocalUses(const CppTools::SemanticInfo::LocalUseMap &uses,
CursorInfo::Ranges *rangesForLocalVariableUnderCursor,
CursorInfo::Ranges *rangesForLocalUnusedVariables) const
......@@ -365,5 +355,15 @@ QFuture<CursorInfo> BuiltinCursorInfo::run(const CursorInfoParams &cursorInfoPar
return Utils::runAsync(&FindUses::find, document, snapshot, line, column, scope, expression);
}
} // namespace Internal
CppTools::SemanticInfo::LocalUseMap
BuiltinCursorInfo::findLocalUses(const Document::Ptr &document, int line, int column)
{
AST *ast = document->translationUnit()->ast();
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(document->translationUnit());
DeclarationAST *declaration = functionDefinitionUnderCursor(ast,
static_cast<unsigned>(line),
static_cast<unsigned>(column));
return CppTools::LocalSymbols(document, declaration).uses;
}
} // namespace CppTools
......@@ -26,17 +26,21 @@
#pragma once
#include "cppcursorinfo.h"
#include "cpptools_global.h"
#include <cplusplus/CppDocument.h>
#include <QFuture>
namespace CppTools {
namespace Internal {
class BuiltinCursorInfo
class CPPTOOLS_EXPORT BuiltinCursorInfo
{
public:
static QFuture<CursorInfo> run(const CursorInfoParams &params);
static CppTools::SemanticInfo::LocalUseMap
findLocalUses(const CPlusPlus::Document::Ptr &document, int line, int column);
};
} // namespace Internal
} // namespace CppTools
......@@ -257,7 +257,7 @@ bool BuiltinEditorDocumentProcessor::isParserRunning() const
QFuture<CursorInfo>
BuiltinEditorDocumentProcessor::cursorInfo(const CursorInfoParams &params)
{
return Internal::BuiltinCursorInfo::run(params);
return BuiltinCursorInfo::run(params);
}
void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr document,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment