Commit fdf0a104 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Generalize CppUseSelectionsUpdater

Let CppUseSelectionsUpdater delegate the work to
*EditorDocumentProcessor so that the clang code model can also provide
results.

Change-Id: I6872afbfeea1a5c4a64fdf19fcb1992f134dde08
Reviewed-by: Marco Bubke's avatarMarco Bubke <marco.bubke@qt.io>
parent cd6bd3c4
......@@ -287,6 +287,12 @@ void ClangEditorDocumentProcessor::setParserConfig(
m_builtinProcessor.parser()->setConfiguration(config);
}
QFuture<CppTools::CursorInfo>
ClangEditorDocumentProcessor::cursorInfo(const CppTools::CursorInfoParams &params)
{
return m_builtinProcessor.cursorInfo(params);
}
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments() const
{
return fileContainerWithArguments(m_projectPart.data());
......
......@@ -84,6 +84,8 @@ public:
void setParserConfig(const CppTools::BaseEditorDocumentParser::Configuration config) override;
QFuture<CppTools::CursorInfo> cursorInfo(const CppTools::CursorInfoParams &params) override;
ClangBackEnd::FileContainer fileContainerWithArguments() const;
void clearDiagnosticsWithFixIts();
......
......@@ -370,6 +370,12 @@ ParseContextModel &CppEditorDocument::parseContextModel()
return m_parseContextModel;
}
QFuture<CppTools::CursorInfo>
CppEditorDocument::cursorInfo(const CppTools::CursorInfoParams &params)
{
return processor()->cursorInfo(params);
}
const MinimizableInfoBars &CppEditorDocument::minimizableInfoBars() const
{
return m_minimizableInfoBars;
......
......@@ -66,6 +66,8 @@ public:
const MinimizableInfoBars &minimizableInfoBars() const;
ParseContextModel &parseContextModel();
QFuture<CppTools::CursorInfo> cursorInfo(const CppTools::CursorInfoParams &params);
signals:
void codeWarningsUpdated(unsigned contentsRevision,
const QList<QTextEdit::ExtraSelection> selections,
......
......@@ -25,36 +25,18 @@
#pragma once
#include <cpptools/cppcursorinfo.h>
#include <cpptools/cppsemanticinfo.h>
#include <texteditor/texteditorconstants.h>
#include <cplusplus/CppDocument.h>
#include <QFutureWatcher>
#include <QTextEdit>
#include <QTimer>
QT_BEGIN_NAMESPACE
class QTextCharFormat;
class QTextCursor;
QT_END_NAMESPACE
namespace TextEditor { class TextEditorWidget; }
namespace CppEditor {
namespace Internal {
typedef QList<QTextEdit::ExtraSelection> ExtraSelections;
typedef QList<CppTools::SemanticInfo::Use> SemanticUses;
struct UseSelectionsResult
{
CppTools::SemanticInfo::LocalUseMap localUses;
SemanticUses selectionsForLocalVariableUnderCursor;
SemanticUses selectionsForLocalUnusedVariables;
QList<int> references;
};
class CppUseSelectionsUpdater : public QObject
{
Q_OBJECT
......@@ -63,10 +45,10 @@ class CppUseSelectionsUpdater : public QObject
public:
explicit CppUseSelectionsUpdater(TextEditor::TextEditorWidget *editorWidget);
enum CallType { Synchronous, Asynchronous };
void scheduleUpdate();
void abortSchedule();
enum CallType { Synchronous, Asynchronous };
void update(CallType callType = Asynchronous);
signals:
......@@ -75,37 +57,26 @@ signals:
private:
CppUseSelectionsUpdater();
void processResults(const CppTools::CursorInfo &result);
void onFindUsesFinished();
bool handleMacroCase(const CPlusPlus::Document::Ptr document);
void handleSymbolCaseAsynchronously(const CPlusPlus::Document::Ptr document,
const CPlusPlus::Snapshot &snapshot);
void handleSymbolCaseSynchronously(const CPlusPlus::Document::Ptr document,
const CPlusPlus::Snapshot &snapshot);
void processSymbolCaseResults(const UseSelectionsResult &result);
ExtraSelections toExtraSelections(const SemanticUses &uses, TextEditor::TextStyle style) const;
ExtraSelections toExtraSelections(const QList<int> &references,
TextEditor::TextStyle style) const;
// Convenience
using ExtraSelections = QList<QTextEdit::ExtraSelection>;
using CursorInfo = CppTools::CursorInfo;
ExtraSelections toExtraSelections(const CursorInfo::Ranges &ranges,
TextEditor::TextStyle style);
ExtraSelections currentUseSelections() const;
void updateUseSelections(const ExtraSelections &selections);
void updateUnusedSelections(const ExtraSelections &selections);
QTextCharFormat textCharFormat(TextEditor::TextStyle category) const;
QTextDocument *textDocument() const;
ExtraSelections updateUseSelections(const CursorInfo::Ranges &selections);
void updateUnusedSelections(const CursorInfo::Ranges &selections);
private:
TextEditor::TextEditorWidget *m_editorWidget;
QTimer m_timer;
CPlusPlus::Document::Ptr m_document;
QScopedPointer<QFutureWatcher<UseSelectionsResult>> m_findUsesWatcher;
int m_findUsesRevision = -1;
int m_findUsesCursorPosition = -1;
QScopedPointer<QFutureWatcher<CppTools::CursorInfo>> m_runnerWatcher;
int m_runnerRevision;
int m_runnerCursorPosition;
};
} // namespace Internal
......
......@@ -26,6 +26,7 @@
#pragma once
#include "baseeditordocumentparser.h"
#include "cppcursorinfo.h"
#include "cppsemanticinfo.h"
#include "cpptools_global.h"
......@@ -72,6 +73,8 @@ public:
virtual void setParserConfig(const BaseEditorDocumentParser::Configuration config);
virtual QFuture<CursorInfo> cursorInfo(const CursorInfoParams &params) = 0;
public:
using HeaderErrorDiagnosticWidgetCreator = std::function<QWidget*()>;
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "cppcursorinfo.h"
#include <QFuture>
namespace CppTools {
namespace Internal {
class BuiltinCursorInfo
{
public:
static QFuture<CursorInfo> run(const CursorInfoParams &params);
};
} // namespace Internal
} // namespace CppTools
......@@ -25,6 +25,7 @@
#include "builtineditordocumentprocessor.h"
#include "builtincursorinfo.h"
#include "cppchecksymbols.h"
#include "cppcodemodelsettings.h"
#include "cppmodelmanager.h"
......@@ -253,6 +254,12 @@ bool BuiltinEditorDocumentProcessor::isParserRunning() const
return m_parserFuture.isRunning();
}
QFuture<CursorInfo>
BuiltinEditorDocumentProcessor::cursorInfo(const CursorInfoParams &params)
{
return Internal::BuiltinCursorInfo::run(params);
}
void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr document,
CPlusPlus::Snapshot snapshot)
{
......
......@@ -51,6 +51,8 @@ public:
CPlusPlus::Snapshot snapshot() override;
bool isParserRunning() const override;
QFuture<CursorInfo> cursorInfo(const CursorInfoParams &params) override;
private:
void onParserFinished(CPlusPlus::Document::Ptr document, CPlusPlus::Snapshot snapshot);
void onSemanticInfoUpdated(const CppTools::SemanticInfo semanticInfo);
......
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "cpptools_global.h"
#include "cppsemanticinfo.h"
#include <QTextCursor>
#include <QVector>
namespace CppTools {
class CPPTOOLS_EXPORT CursorInfoParams
{
public:
CppTools::SemanticInfo semanticInfo;
QTextCursor textCursor;
};
class CPPTOOLS_EXPORT CursorInfo
{
public:
struct Range {
Range() = default;
Range(unsigned line, unsigned column, unsigned length)
: line(line)
, column(column)
, length(length)
{
}
unsigned line = 0; // 1-based
unsigned column = 0; // 1-based
unsigned length = 0;
};
using Ranges = QVector<Range>;
Ranges useRanges;
bool areUseRangesForLocalVariable = false;
Ranges unusedVariablesRanges;
SemanticInfo::LocalUseMap localUses;
};
} // namespace CppTools
......@@ -6,6 +6,7 @@ HEADERS += \
abstracteditorsupport.h \
baseeditordocumentparser.h \
baseeditordocumentprocessor.h \
builtincursorinfo.h \
builtineditordocumentparser.h \
builtineditordocumentprocessor.h \
builtinindexingsupport.h \
......@@ -26,6 +27,7 @@ HEADERS += \
cppcompletionassist.h \
cppcompletionassistprocessor.h \
cppcompletionassistprovider.h \
cppcursorinfo.h \
cppcurrentdocumentfilter.h \
cppeditoroutline.h \
cppdoxygen.h \
......@@ -90,6 +92,7 @@ SOURCES += \
abstracteditorsupport.cpp \
baseeditordocumentparser.cpp \
baseeditordocumentprocessor.cpp \
builtincursorinfo.cpp \
builtineditordocumentparser.cpp \
builtineditordocumentprocessor.cpp \
builtinindexingsupport.cpp \
......
......@@ -40,6 +40,8 @@ Project {
"builtineditordocumentprocessor.h",
"builtinindexingsupport.cpp",
"builtinindexingsupport.h",
"builtincursorinfo.cpp",
"builtincursorinfo.h",
"clangcompileroptionsbuilder.cpp",
"clangcompileroptionsbuilder.h",
"clangdiagnosticconfig.cpp",
......@@ -81,6 +83,7 @@ Project {
"cppcompletionassistprocessor.h",
"cppcompletionassistprovider.cpp",
"cppcompletionassistprovider.h",
"cppcursorinfo.h",
"cppcurrentdocumentfilter.cpp",
"cppcurrentdocumentfilter.h",
"cppdoxygen.cpp",
......
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