forked from qt-creator/qt-creator
C++: Base parsing on editor document instead of widget
This mainly takes CppEditorSupport apart.
* Parsing is now invoked by CPPEditorDocument itself by listening to
QTextDocument::contentsChanged().
* Upon construction and destruction CPPEditorDocument creates and
deletes an EditorDocumentHandle for (un)registration in the model
manager. This handle provides everything to generate the working copy
and to access the editor document processor.
* A CPPEditorDocument owns a BaseEditorDocumentProcessor instance that
controls parsing, semantic info recalculation and the semantic
highlighting for the document. This is more or less what is left from
CppEditorSupport and can be considered as the backend of a
CPPEditorDocument. CPPEditorDocument itself is quite small.
* BuiltinEditorDocumentProcessor and ClangEditorDocumentProcessor
derive from BaseEditorDocumentProcessor and implement the gaps.
* Since the semantic info calculation was bound to the widget, it
also calculated the local uses, which depend on the cursor
position. This calculation got moved into the extracted class
UseSeletionsUpdater in the cppeditor plugin, which is run once the
cursor position changes or the semantic info document is updated.
* Some more logic got extracted:
- SemanticInfoUpdater (logic was in CppEditorSupport)
- SemanticHighlighter (logic was in CppEditorSupport)
* The *Parser and *Processor classes can be easily accessed by the
static function get().
* CppHighlightingSupport is gone since it turned out to be useless.
* The editor dependency in CompletionAssistProviders is gone since we
actually only need the file path now.
Change-Id: I49d3a7bd138c5ed9620123e34480772535156508
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -17,18 +17,14 @@ contains(DEFINES, CLANG_COMPLETION) {
|
||||
}
|
||||
|
||||
contains(DEFINES, CLANG_HIGHLIGHTING) {
|
||||
HEADERS += cppcreatemarkers.h clanghighlightingsupport.h
|
||||
SOURCES += cppcreatemarkers.cpp clanghighlightingsupport.cpp
|
||||
HEADERS += cppcreatemarkers.h
|
||||
SOURCES += cppcreatemarkers.cpp
|
||||
}
|
||||
|
||||
HEADERS += clangutils.h \
|
||||
cxprettyprinter.h
|
||||
|
||||
SOURCES += clangutils.cpp \
|
||||
cxprettyprinter.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/clangcodemodelplugin.cpp \
|
||||
$$PWD/clangeditordocumentparser.cpp \
|
||||
$$PWD/clangeditordocumentprocessor.cpp \
|
||||
$$PWD/sourcemarker.cpp \
|
||||
$$PWD/symbol.cpp \
|
||||
$$PWD/sourcelocation.cpp \
|
||||
@@ -48,6 +44,8 @@ SOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/clangcodemodelplugin.h \
|
||||
$$PWD/clangeditordocumentparser.h \
|
||||
$$PWD/clangeditordocumentprocessor.h \
|
||||
$$PWD/clang_global.h \
|
||||
$$PWD/sourcemarker.h \
|
||||
$$PWD/constants.h \
|
||||
@@ -68,6 +66,12 @@ HEADERS += \
|
||||
$$PWD/raii/scopedclangoptions.h \
|
||||
$$PWD/clangmodelmanagersupport.h
|
||||
|
||||
HEADERS += clangutils.h \
|
||||
cxprettyprinter.h
|
||||
|
||||
SOURCES += clangutils.cpp \
|
||||
cxprettyprinter.cpp
|
||||
|
||||
contains(DEFINES, CLANG_INDEXING) {
|
||||
HEADERS += \
|
||||
$$PWD/clangindexer.h \
|
||||
|
||||
@@ -94,8 +94,6 @@ QtcPlugin {
|
||||
name: "Highlighting support"
|
||||
condition: product.clangHighlighting
|
||||
files: [
|
||||
"clanghighlightingsupport.cpp",
|
||||
"clanghighlightingsupport.h",
|
||||
"cppcreatemarkers.cpp",
|
||||
"cppcreatemarkers.h",
|
||||
]
|
||||
@@ -156,6 +154,10 @@ QtcPlugin {
|
||||
|
||||
files: [
|
||||
"clang_global.h",
|
||||
"clangeditordocumentparser.cpp",
|
||||
"clangeditordocumentparser.h",
|
||||
"clangeditordocumentprocessor.cpp",
|
||||
"clangeditordocumentprocessor.h",
|
||||
"clangmodelmanagersupport.cpp",
|
||||
"clangmodelmanagersupport.h",
|
||||
"clangcodemodelplugin.cpp",
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include "clangcodemodelplugin.h"
|
||||
#include "clangprojectsettingspropertiespage.h"
|
||||
#include "fastindexer.h"
|
||||
#include "pchmanager.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -65,11 +64,9 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
|
||||
ClangCodeModel::Internal::initializeClang();
|
||||
|
||||
PchManager *pchManager = new PchManager(this);
|
||||
FastIndexer *fastIndexer = 0;
|
||||
|
||||
#ifdef CLANG_INDEXING
|
||||
m_indexer.reset(new ClangIndexer);
|
||||
fastIndexer = m_indexer.data();
|
||||
CppTools::CppModelManagerInterface::instance()->setIndexingSupport(m_indexer->indexingSupport());
|
||||
#endif // CLANG_INDEXING
|
||||
|
||||
@@ -80,7 +77,7 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
|
||||
connect(CppTools::CppModelManagerInterface::instance(), SIGNAL(projectPartsUpdated(ProjectExplorer::Project*)),
|
||||
pchManager, SLOT(onProjectPartsUpdated(ProjectExplorer::Project*)));
|
||||
|
||||
m_modelManagerSupport.reset(new ModelManagerSupport(fastIndexer));
|
||||
m_modelManagerSupport.reset(new ModelManagerSupport);
|
||||
CppTools::CppModelManagerInterface::instance()->addModelManagerSupport(
|
||||
m_modelManagerSupport.data());
|
||||
|
||||
|
||||
@@ -203,15 +203,14 @@ IAssistProcessor *ClangCompletionAssistProvider::createProcessor() const
|
||||
}
|
||||
|
||||
IAssistInterface *ClangCompletionAssistProvider::createAssistInterface(
|
||||
ProjectExplorer::Project *project, TextEditor::BaseTextEditor *editor,
|
||||
ProjectExplorer::Project *project, const QString &filePath,
|
||||
QTextDocument *document, bool isObjCEnabled, int position, AssistReason reason) const
|
||||
{
|
||||
Q_UNUSED(project);
|
||||
Q_UNUSED(isObjCEnabled);
|
||||
|
||||
QString fileName = editor->document()->filePath();
|
||||
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
|
||||
QList<ProjectPart::Ptr> parts = modelManager->projectPart(fileName);
|
||||
QList<ProjectPart::Ptr> parts = modelManager->projectPart(filePath);
|
||||
if (parts.isEmpty())
|
||||
parts += modelManager->fallbackProjectPart();
|
||||
ProjectPart::HeaderPaths headerPaths;
|
||||
@@ -220,7 +219,7 @@ IAssistInterface *ClangCompletionAssistProvider::createAssistInterface(
|
||||
foreach (ProjectPart::Ptr part, parts) {
|
||||
if (part.isNull())
|
||||
continue;
|
||||
options = ClangCodeModel::Utils::createClangOptions(part, fileName);
|
||||
options = ClangCodeModel::Utils::createClangOptions(part, filePath);
|
||||
pchInfo = PchManager::instance()->pchInfo(part);
|
||||
if (!pchInfo.isNull())
|
||||
options.append(ClangCodeModel::Utils::createPCHInclusionOptions(pchInfo->fileName()));
|
||||
@@ -230,7 +229,7 @@ IAssistInterface *ClangCompletionAssistProvider::createAssistInterface(
|
||||
|
||||
return new ClangCodeModel::ClangCompletionAssistInterface(
|
||||
m_clangCompletionWrapper,
|
||||
document, position, fileName, reason,
|
||||
document, position, filePath, reason,
|
||||
options, headerPaths, pchInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
virtual TextEditor::IAssistProcessor *createProcessor() const;
|
||||
virtual TextEditor::IAssistInterface *createAssistInterface(
|
||||
ProjectExplorer::Project *project, TextEditor::BaseTextEditor *editor,
|
||||
ProjectExplorer::Project *project, const QString &filePath,
|
||||
QTextDocument *document, bool isObjCEnabled, int position,
|
||||
TextEditor::AssistReason reason) const;
|
||||
|
||||
|
||||
128
src/plugins/clangcodemodel/clangeditordocumentparser.cpp
Normal file
128
src/plugins/clangcodemodel/clangeditordocumentparser.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangeditordocumentparser.h"
|
||||
#include "clangutils.h"
|
||||
#include "pchinfo.h"
|
||||
#include "pchmanager.h"
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <cpptools/cppprojects.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
static const bool DebugTiming = qgetenv("QTC_CLANG_VERBOSE") == "1";
|
||||
|
||||
namespace {
|
||||
|
||||
QStringList createOptions(const QString &filePath, const CppTools::ProjectPart::Ptr &part)
|
||||
{
|
||||
using namespace ClangCodeModel;
|
||||
|
||||
QStringList options;
|
||||
if (part.isNull())
|
||||
return options;
|
||||
|
||||
options += QLatin1String("-fspell-checking");
|
||||
options += ClangCodeModel::Utils::createClangOptions(part, filePath);
|
||||
|
||||
if (Internal::PchInfo::Ptr pchInfo = Internal::PchManager::instance()->pchInfo(part))
|
||||
options.append(ClangCodeModel::Utils::createPCHInclusionOptions(pchInfo->fileName()));
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
QString commandLine(const QStringList &options, const QString &fileName)
|
||||
{
|
||||
const QStringList allOptions = QStringList(options)
|
||||
<< QLatin1String("-fsyntax-only") << fileName;
|
||||
QStringList allOptionsQuoted;
|
||||
foreach (const QString &option, allOptions)
|
||||
allOptionsQuoted.append(QLatin1Char('\'') + option + QLatin1Char('\''));
|
||||
return ::Utils::HostOsInfo::withExecutableSuffix(QLatin1String("clang"))
|
||||
+ QLatin1Char(' ') + allOptionsQuoted.join(QLatin1Char(' '));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath)
|
||||
: BaseEditorDocumentParser(filePath)
|
||||
, m_marker(new ClangCodeModel::SemanticMarker)
|
||||
{
|
||||
}
|
||||
|
||||
void ClangEditorDocumentParser::update(CppTools::WorkingCopy workingCopy)
|
||||
{
|
||||
QTC_ASSERT(m_marker, return);
|
||||
QMutexLocker lock(m_marker->mutex());
|
||||
QMutexLocker lock2(&m_mutex);
|
||||
|
||||
updateProjectPart();
|
||||
const QStringList options = createOptions(filePath(), projectPart());
|
||||
|
||||
QTime t;
|
||||
if (DebugTiming) {
|
||||
qDebug("*** Reparse options (cmd line equivalent): %s",
|
||||
commandLine(options, filePath()).toUtf8().constData());
|
||||
t.start();
|
||||
}
|
||||
|
||||
m_marker->setFileName(filePath());
|
||||
m_marker->setCompilationOptions(options);
|
||||
const Internal::UnsavedFiles unsavedFiles = Utils::createUnsavedFiles(workingCopy);
|
||||
m_marker->reparse(unsavedFiles);
|
||||
|
||||
if (DebugTiming)
|
||||
qDebug() << "*** Reparse took" << t.elapsed() << "ms.";
|
||||
}
|
||||
|
||||
QList<Diagnostic> ClangEditorDocumentParser::diagnostics() const
|
||||
{
|
||||
QTC_ASSERT(m_marker, return QList<Diagnostic>());
|
||||
QMutexLocker(m_marker->mutex());
|
||||
return m_marker->diagnostics();
|
||||
}
|
||||
|
||||
QList<SemanticMarker::Range> ClangEditorDocumentParser::ifdefedOutBlocks() const
|
||||
{
|
||||
QTC_ASSERT(m_marker, return QList<SemanticMarker::Range>());
|
||||
QMutexLocker(m_marker->mutex());
|
||||
return m_marker->ifdefedOutBlocks();
|
||||
}
|
||||
|
||||
SemanticMarker::Ptr ClangEditorDocumentParser::semanticMarker() const
|
||||
{
|
||||
return m_marker;
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
@@ -27,43 +27,42 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CLANG_CLANGHIGHLIGHTINGSUPPORT_H
|
||||
#define CLANG_CLANGHIGHLIGHTINGSUPPORT_H
|
||||
|
||||
#include "clangutils.h"
|
||||
#include "cppcreatemarkers.h"
|
||||
#include "fastindexer.h"
|
||||
#ifndef CLANGEDITORDOCUMENTPARSER_H
|
||||
#define CLANGEDITORDOCUMENTPARSER_H
|
||||
|
||||
#include <cpptools/cpphighlightingsupport.h>
|
||||
#include "semanticmarker.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <cpptools/baseeditordocumentparser.h>
|
||||
|
||||
#include <utils/qtcoverride.h>
|
||||
|
||||
namespace CppTools { class WorkingCopy; }
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
class ClangHighlightingSupport: public CppTools::CppHighlightingSupport
|
||||
class ClangEditorDocumentParser : public CppTools::BaseEditorDocumentParser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClangHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument,
|
||||
Internal::FastIndexer *fastIndexer);
|
||||
~ClangHighlightingSupport();
|
||||
typedef QSharedPointer<ClangEditorDocumentParser> Ptr;
|
||||
|
||||
virtual bool requiresSemanticInfo() const
|
||||
{ return false; }
|
||||
public:
|
||||
ClangEditorDocumentParser(const QString &filePath);
|
||||
|
||||
virtual bool hightlighterHandlesDiagnostics() const
|
||||
{ return true; }
|
||||
void update(CppTools::WorkingCopy workingCopy) QTC_OVERRIDE;
|
||||
|
||||
virtual bool hightlighterHandlesIfdefedOutBlocks() const;
|
||||
|
||||
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
|
||||
const CPlusPlus::Document::Ptr &doc, const CPlusPlus::Snapshot &snapshot) const;
|
||||
QList<Diagnostic> diagnostics() const;
|
||||
QList<SemanticMarker::Range> ifdefedOutBlocks() const;
|
||||
SemanticMarker::Ptr semanticMarker() const;
|
||||
|
||||
private:
|
||||
Internal::FastIndexer *m_fastIndexer;
|
||||
ClangCodeModel::SemanticMarker::Ptr m_semanticMarker;
|
||||
SemanticMarker::Ptr m_marker;
|
||||
QStringList m_options;
|
||||
Internal::UnsavedFiles m_unsavedFiles;
|
||||
};
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
#endif // CLANG_CLANGHIGHLIGHTINGSUPPORT_H
|
||||
#endif // CLANGEDITORDOCUMENTPARSER_H
|
||||
184
src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp
Normal file
184
src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
|
||||
#include "cppcreatemarkers.h"
|
||||
#include "diagnostic.h"
|
||||
#include "pchinfo.h"
|
||||
|
||||
#include <cpptools/cpptoolsplugin.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/QtConcurrentTools>
|
||||
|
||||
static const bool DebugTiming = qgetenv("QTC_CLANG_VERBOSE") == "1";
|
||||
|
||||
namespace {
|
||||
|
||||
typedef CPlusPlus::Document::DiagnosticMessage CppToolsDiagnostic;
|
||||
QList<CppToolsDiagnostic> toCppToolsDiagnostics(
|
||||
const QString &filePath,
|
||||
const QList<ClangCodeModel::Diagnostic> &diagnostics)
|
||||
{
|
||||
using namespace ClangCodeModel;
|
||||
|
||||
QList<CppToolsDiagnostic> converted;
|
||||
foreach (const ClangCodeModel::Diagnostic &d, diagnostics) {
|
||||
if (DebugTiming)
|
||||
qDebug() << d.severityAsString() << d.location() << d.spelling();
|
||||
|
||||
if (d.location().fileName() != filePath)
|
||||
continue;
|
||||
|
||||
// TODO: retrieve fix-its for this diagnostic
|
||||
|
||||
int level;
|
||||
switch (d.severity()) {
|
||||
case Diagnostic::Fatal: level = CppToolsDiagnostic::Fatal; break;
|
||||
case Diagnostic::Error: level = CppToolsDiagnostic::Error; break;
|
||||
case Diagnostic::Warning: level = CppToolsDiagnostic::Warning; break;
|
||||
default: continue;
|
||||
}
|
||||
converted.append(CppToolsDiagnostic(level, d.location().fileName(), d.location().line(),
|
||||
d.location().column(), d.spelling(), d.length()));
|
||||
}
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
QList<TextEditor::BlockRange> toTextEditorBlocks(
|
||||
const QList<ClangCodeModel::SemanticMarker::Range> &ranges)
|
||||
{
|
||||
QList<TextEditor::BlockRange> result;
|
||||
result.reserve(ranges.size());
|
||||
foreach (const ClangCodeModel::SemanticMarker::Range &range, ranges)
|
||||
result.append(TextEditor::BlockRange(range.first, range.last));
|
||||
return result;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(TextEditor::BaseTextDocument *document)
|
||||
: BaseEditorDocumentProcessor(document)
|
||||
, m_parser(new ClangEditorDocumentParser(document->filePath()))
|
||||
, m_parserRevision(0)
|
||||
, m_semanticHighlighter(document)
|
||||
, m_builtinProcessor(document, /*enableSemanticHighlighter=*/ false)
|
||||
{
|
||||
// Forwarding the semantic info from the builtin processor enables us to provide all
|
||||
// editor (widget) related features that are not yet implemented by the clang plugin.
|
||||
connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::cppDocumentUpdated,
|
||||
this, &ClangEditorDocumentProcessor::cppDocumentUpdated);
|
||||
connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::semanticInfoUpdated,
|
||||
this, &ClangEditorDocumentProcessor::semanticInfoUpdated);
|
||||
|
||||
m_semanticHighlighter.setHighlightingRunner(
|
||||
[this]() -> QFuture<TextEditor::HighlightingResult> {
|
||||
const int firstLine = 1;
|
||||
const int lastLine = baseTextDocument()->document()->blockCount();
|
||||
|
||||
CreateMarkers *createMarkers = CreateMarkers::create(m_parser->semanticMarker(),
|
||||
baseTextDocument()->filePath(),
|
||||
firstLine, lastLine);
|
||||
return createMarkers->start();
|
||||
});
|
||||
}
|
||||
|
||||
ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
|
||||
{
|
||||
m_parserWatcher.cancel();
|
||||
m_parserWatcher.waitForFinished();
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::run()
|
||||
{
|
||||
// Run clang parser
|
||||
const CppTools::WorkingCopy workingCopy
|
||||
= CppTools::CppModelManagerInterface::instance()->workingCopy();
|
||||
|
||||
disconnect(&m_parserWatcher, &QFutureWatcher<void>::finished,
|
||||
this, &ClangEditorDocumentProcessor::onParserFinished);
|
||||
m_parserWatcher.cancel();
|
||||
m_parserWatcher.setFuture(QFuture<void>());
|
||||
|
||||
m_parserRevision = revision();
|
||||
connect(&m_parserWatcher, &QFutureWatcher<void>::finished,
|
||||
this, &ClangEditorDocumentProcessor::onParserFinished);
|
||||
const QFuture<void> future = QtConcurrent::run(&runParser, parser(), workingCopy);
|
||||
m_parserWatcher.setFuture(future);
|
||||
|
||||
// Run builtin processor
|
||||
m_builtinProcessor.run();
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::semanticRehighlight(bool force)
|
||||
{
|
||||
m_builtinProcessor.semanticRehighlight(force);
|
||||
}
|
||||
|
||||
CppTools::SemanticInfo ClangEditorDocumentProcessor::recalculateSemanticInfo()
|
||||
{
|
||||
return m_builtinProcessor.recalculateSemanticInfo();
|
||||
}
|
||||
|
||||
CppTools::BaseEditorDocumentParser *ClangEditorDocumentProcessor::parser()
|
||||
{
|
||||
return m_parser.data();
|
||||
}
|
||||
|
||||
bool ClangEditorDocumentProcessor::isParserRunning() const
|
||||
{
|
||||
return m_parserWatcher.isRunning();
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::onParserFinished()
|
||||
{
|
||||
if (revision() != m_parserRevision)
|
||||
return;
|
||||
|
||||
// Emit ifdefed out blocks
|
||||
const auto ifdefoutBlocks = toTextEditorBlocks(m_parser->ifdefedOutBlocks());
|
||||
emit ifdefedOutBlocksUpdated(revision(), ifdefoutBlocks);
|
||||
|
||||
// Emit code warnings
|
||||
const auto diagnostics = toCppToolsDiagnostics(filePath(), m_parser->diagnostics());
|
||||
const auto codeWarnings = toTextEditorSelections(diagnostics, textDocument());
|
||||
emit codeWarningsUpdated(revision(), codeWarnings);
|
||||
|
||||
// Run semantic highlighter
|
||||
m_semanticHighlighter.run();
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
74
src/plugins/clangcodemodel/clangeditordocumentprocessor.h
Normal file
74
src/plugins/clangcodemodel/clangeditordocumentprocessor.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CLANGEDITORDOCUMENTPROCESSOR_H
|
||||
#define CLANGEDITORDOCUMENTPROCESSOR_H
|
||||
|
||||
#include "clangeditordocumentparser.h"
|
||||
|
||||
#include <cpptools/baseeditordocumentprocessor.h>
|
||||
#include <cpptools/builtineditordocumentprocessor.h>
|
||||
#include <cpptools/semantichighlighter.h>
|
||||
|
||||
#include <utils/qtcoverride.h>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
class ClangEditorDocumentProcessor : public CppTools::BaseEditorDocumentProcessor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClangEditorDocumentProcessor(TextEditor::BaseTextDocument *document);
|
||||
~ClangEditorDocumentProcessor();
|
||||
|
||||
// BaseEditorDocumentProcessor interface
|
||||
void run() QTC_OVERRIDE;
|
||||
void semanticRehighlight(bool force) QTC_OVERRIDE;
|
||||
CppTools::SemanticInfo recalculateSemanticInfo() QTC_OVERRIDE;
|
||||
CppTools::BaseEditorDocumentParser *parser() QTC_OVERRIDE;
|
||||
bool isParserRunning() const QTC_OVERRIDE;
|
||||
|
||||
private slots:
|
||||
void onParserFinished();
|
||||
|
||||
private:
|
||||
QScopedPointer<ClangEditorDocumentParser> m_parser;
|
||||
QFutureWatcher<void> m_parserWatcher;
|
||||
unsigned m_parserRevision;
|
||||
|
||||
CppTools::SemanticHighlighter m_semanticHighlighter;
|
||||
CppTools::BuiltinEditorDocumentProcessor m_builtinProcessor;
|
||||
};
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
#endif // CLANGEDITORDOCUMENTPROCESSOR_H
|
||||
@@ -1,96 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** 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 Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clanghighlightingsupport.h"
|
||||
|
||||
#include <texteditor/basetextdocument.h>
|
||||
|
||||
#include <QTextBlock>
|
||||
#include <QTextEdit>
|
||||
#include "pchmanager.h"
|
||||
|
||||
using namespace ClangCodeModel;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
using namespace CppTools;
|
||||
|
||||
ClangHighlightingSupport::ClangHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument,
|
||||
FastIndexer *fastIndexer)
|
||||
: CppHighlightingSupport(baseTextDocument)
|
||||
, m_fastIndexer(fastIndexer)
|
||||
, m_semanticMarker(new ClangCodeModel::SemanticMarker)
|
||||
{
|
||||
}
|
||||
|
||||
ClangHighlightingSupport::~ClangHighlightingSupport()
|
||||
{
|
||||
}
|
||||
|
||||
bool ClangHighlightingSupport::hightlighterHandlesIfdefedOutBlocks() const
|
||||
{
|
||||
#if CINDEX_VERSION_MINOR >= 21
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
QFuture<TextEditor::HighlightingResult> ClangHighlightingSupport::highlightingFuture(
|
||||
const CPlusPlus::Document::Ptr &doc,
|
||||
const CPlusPlus::Snapshot &snapshot) const
|
||||
{
|
||||
Q_UNUSED(doc);
|
||||
Q_UNUSED(snapshot);
|
||||
|
||||
int firstLine = 1;
|
||||
int lastLine = baseTextDocument()->document()->blockCount();
|
||||
|
||||
const QString fileName = baseTextDocument()->filePath();
|
||||
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
|
||||
QList<ProjectPart::Ptr> parts = modelManager->projectPart(fileName);
|
||||
if (parts.isEmpty())
|
||||
parts += modelManager->fallbackProjectPart();
|
||||
QStringList options;
|
||||
PchInfo::Ptr pchInfo;
|
||||
foreach (const ProjectPart::Ptr &part, parts) {
|
||||
if (part.isNull())
|
||||
continue;
|
||||
options = Utils::createClangOptions(part, fileName);
|
||||
pchInfo = PchManager::instance()->pchInfo(part);
|
||||
if (!pchInfo.isNull())
|
||||
options.append(ClangCodeModel::Utils::createPCHInclusionOptions(pchInfo->fileName()));
|
||||
if (!options.isEmpty())
|
||||
break;
|
||||
}
|
||||
|
||||
CreateMarkers *createMarkers = CreateMarkers::create(m_semanticMarker,
|
||||
fileName, options,
|
||||
firstLine, lastLine,
|
||||
m_fastIndexer, pchInfo);
|
||||
return createMarkers->start();
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangcompletion.h"
|
||||
#include "clanghighlightingsupport.h"
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "clangmodelmanagersupport.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -36,9 +36,8 @@
|
||||
using namespace ClangCodeModel;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
|
||||
ModelManagerSupport::ModelManagerSupport(FastIndexer *fastIndexer)
|
||||
ModelManagerSupport::ModelManagerSupport()
|
||||
: m_completionAssistProvider(new ClangCompletionAssistProvider)
|
||||
, m_fastIndexer(fastIndexer)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -63,8 +62,8 @@ CppTools::CppCompletionAssistProvider *ModelManagerSupport::completionAssistProv
|
||||
return m_completionAssistProvider.data();
|
||||
}
|
||||
|
||||
CppTools::CppHighlightingSupport *ModelManagerSupport::highlightingSupport(
|
||||
CppTools::BaseEditorDocumentProcessor *ModelManagerSupport::editorDocumentProcessor(
|
||||
TextEditor::BaseTextDocument *baseTextDocument)
|
||||
{
|
||||
return new ClangHighlightingSupport(baseTextDocument, m_fastIndexer);
|
||||
return new ClangCodeModel::ClangEditorDocumentProcessor(baseTextDocument);
|
||||
}
|
||||
|
||||
@@ -37,26 +37,23 @@
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
class FastIndexer;
|
||||
|
||||
class ModelManagerSupport: public CppTools::ModelManagerSupport
|
||||
{
|
||||
Q_DISABLE_COPY(ModelManagerSupport)
|
||||
|
||||
public:
|
||||
ModelManagerSupport(FastIndexer *fastIndexer);
|
||||
ModelManagerSupport();
|
||||
virtual ~ModelManagerSupport();
|
||||
|
||||
virtual QString id() const;
|
||||
virtual QString displayName() const;
|
||||
|
||||
virtual CppTools::CppCompletionAssistProvider *completionAssistProvider();
|
||||
virtual CppTools::CppHighlightingSupport *highlightingSupport(
|
||||
TextEditor::BaseTextDocument *baseTextDocument);
|
||||
virtual CppTools::BaseEditorDocumentProcessor *editorDocumentProcessor(
|
||||
TextEditor::BaseTextDocument *baseTextDocument);
|
||||
|
||||
private:
|
||||
QScopedPointer<CppTools::CppCompletionAssistProvider> m_completionAssistProvider;
|
||||
FastIndexer *m_fastIndexer;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -30,11 +30,7 @@
|
||||
#include "clangutils.h"
|
||||
#include "cppcreatemarkers.h"
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -51,119 +47,52 @@ using namespace CppTools;
|
||||
|
||||
CreateMarkers *CreateMarkers::create(SemanticMarker::Ptr semanticMarker,
|
||||
const QString &fileName,
|
||||
const QStringList &options,
|
||||
unsigned firstLine, unsigned lastLine,
|
||||
FastIndexer *fastIndexer,
|
||||
const Internal::PchInfo::Ptr &pchInfo)
|
||||
unsigned firstLine, unsigned lastLine)
|
||||
{
|
||||
if (semanticMarker.isNull())
|
||||
return 0;
|
||||
else
|
||||
return new CreateMarkers(semanticMarker, fileName, options, firstLine, lastLine, fastIndexer, pchInfo);
|
||||
return new CreateMarkers(semanticMarker, fileName, firstLine, lastLine);
|
||||
}
|
||||
|
||||
CreateMarkers::CreateMarkers(SemanticMarker::Ptr semanticMarker,
|
||||
const QString &fileName,
|
||||
const QStringList &options,
|
||||
unsigned firstLine, unsigned lastLine,
|
||||
FastIndexer *fastIndexer,
|
||||
const Internal::PchInfo::Ptr &pchInfo)
|
||||
unsigned firstLine, unsigned lastLine)
|
||||
: m_marker(semanticMarker)
|
||||
, m_pchInfo(pchInfo)
|
||||
, m_fileName(fileName)
|
||||
, m_options(options)
|
||||
, m_firstLine(firstLine)
|
||||
, m_lastLine(lastLine)
|
||||
, m_fastIndexer(fastIndexer)
|
||||
{
|
||||
Q_ASSERT(!semanticMarker.isNull());
|
||||
|
||||
m_flushRequested = false;
|
||||
m_flushLine = 0;
|
||||
|
||||
m_unsavedFiles = Utils::createUnsavedFiles(CppModelManagerInterface::instance()->workingCopy());
|
||||
}
|
||||
|
||||
CreateMarkers::~CreateMarkers()
|
||||
{ }
|
||||
|
||||
static QString commandLine(const QStringList &options, const QString &fileName)
|
||||
{
|
||||
const QStringList allOptions = QStringList(options)
|
||||
<< QLatin1String("-fsyntax-only") << fileName;
|
||||
QStringList allOptionsQuoted;
|
||||
foreach (const QString &option, allOptions)
|
||||
allOptionsQuoted.append(QLatin1Char('\'') + option + QLatin1Char('\''));
|
||||
return ::Utils::HostOsInfo::withExecutableSuffix(QLatin1String("clang"))
|
||||
+ QLatin1Char(' ') + allOptionsQuoted.join(QLatin1Char(' '));
|
||||
}
|
||||
|
||||
void CreateMarkers::run()
|
||||
{
|
||||
QMutexLocker lock(m_marker->mutex());
|
||||
if (isCanceled())
|
||||
return;
|
||||
|
||||
m_options += QLatin1String("-fspell-checking");
|
||||
|
||||
QTime t;
|
||||
if (DebugTiming) {
|
||||
qDebug() << "*** Highlighting from" << m_firstLine << "to" << m_lastLine << "of" << m_fileName;
|
||||
qDebug("***** Options (cmd line equivalent): %s",
|
||||
commandLine(m_options, m_fileName).toUtf8().constData());
|
||||
t.start();
|
||||
}
|
||||
|
||||
m_usages.clear();
|
||||
m_marker->setFileName(m_fileName);
|
||||
m_marker->setCompilationOptions(m_options);
|
||||
|
||||
m_marker->reparse(m_unsavedFiles);
|
||||
|
||||
if (DebugTiming)
|
||||
qDebug() << "*** Reparse for highlighting took" << t.elapsed() << "ms.";
|
||||
|
||||
m_pchInfo.clear();
|
||||
|
||||
typedef CPlusPlus::Document::DiagnosticMessage OtherDiagnostic;
|
||||
QList<OtherDiagnostic> msgs;
|
||||
foreach (const ClangCodeModel::Diagnostic &d, m_marker->diagnostics()) {
|
||||
if (DebugTiming)
|
||||
qDebug() << d.severityAsString() << d.location() << d.spelling();
|
||||
|
||||
if (d.location().fileName() != m_marker->fileName())
|
||||
continue;
|
||||
|
||||
// TODO: retrieve fix-its for this diagnostic
|
||||
|
||||
int level;
|
||||
switch (d.severity()) {
|
||||
case Diagnostic::Fatal: level = OtherDiagnostic::Fatal; break;
|
||||
case Diagnostic::Error: level = OtherDiagnostic::Error; break;
|
||||
case Diagnostic::Warning: level = OtherDiagnostic::Warning; break;
|
||||
default: continue;
|
||||
}
|
||||
msgs.append(OtherDiagnostic(level, d.location().fileName(), d.location().line(),
|
||||
d.location().column(), d.spelling(), d.length()));
|
||||
}
|
||||
if (isCanceled()) {
|
||||
reportFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
CppModelManagerInterface *mmi = CppModelManagerInterface::instance();
|
||||
static const QString key = QLatin1String("ClangCodeModel.Diagnostics");
|
||||
mmi->setExtraDiagnostics(m_marker->fileName(), key, msgs);
|
||||
#if CINDEX_VERSION_MINOR >= 21
|
||||
mmi->setIfdefedOutBlocks(m_marker->fileName(), m_marker->ifdefedOutBlocks());
|
||||
#endif
|
||||
|
||||
if (isCanceled()) {
|
||||
reportFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
QList<ClangCodeModel::SourceMarker> markers = m_marker->sourceMarkersInRange(m_firstLine, m_lastLine);
|
||||
const QList<ClangCodeModel::SourceMarker> markers
|
||||
= m_marker->sourceMarkersInRange(m_firstLine, m_lastLine);
|
||||
foreach (const ClangCodeModel::SourceMarker &m, markers)
|
||||
addUse(SourceMarker(m.location().line(), m.location().column(), m.length(), m.kind()));
|
||||
|
||||
@@ -179,12 +108,6 @@ void CreateMarkers::run()
|
||||
qDebug() << "*** Highlighting took" << t.elapsed() << "ms in total.";
|
||||
t.restart();
|
||||
}
|
||||
|
||||
if (m_fastIndexer)
|
||||
m_fastIndexer->indexNow(m_marker->unit());
|
||||
|
||||
if (DebugTiming)
|
||||
qDebug() << "*** Fast re-indexing took" << t.elapsed() << "ms in total.";
|
||||
}
|
||||
|
||||
void CreateMarkers::addUse(const SourceMarker &marker)
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QFuture>
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
@@ -70,35 +69,23 @@ public:
|
||||
}
|
||||
|
||||
static CreateMarkers *create(ClangCodeModel::SemanticMarker::Ptr semanticMarker,
|
||||
const QString &fileName,
|
||||
const QStringList &options,
|
||||
unsigned firstLine, unsigned lastLine,
|
||||
Internal::FastIndexer *fastIndexer,
|
||||
const Internal::PchInfo::Ptr &pchInfo);
|
||||
const QString &fileName, unsigned firstLine, unsigned lastLine);
|
||||
|
||||
void addUse(const SourceMarker &marker);
|
||||
void flush();
|
||||
|
||||
protected:
|
||||
CreateMarkers(ClangCodeModel::SemanticMarker::Ptr semanticMarker,
|
||||
const QString &fileName, const QStringList &options,
|
||||
unsigned firstLine, unsigned lastLine,
|
||||
Internal::FastIndexer *fastIndexer,
|
||||
const Internal::PchInfo::Ptr &pchInfo);
|
||||
const QString &fileName, unsigned firstLine, unsigned lastLine);
|
||||
|
||||
private:
|
||||
ClangCodeModel::SemanticMarker::Ptr m_marker;
|
||||
Internal::PchInfo::Ptr m_pchInfo;
|
||||
QString m_fileName;
|
||||
QStringList m_options;
|
||||
unsigned m_firstLine;
|
||||
unsigned m_lastLine;
|
||||
Internal::FastIndexer *m_fastIndexer;
|
||||
QVector<SourceMarker> m_usages;
|
||||
bool m_flushRequested;
|
||||
unsigned m_flushLine;
|
||||
|
||||
ClangCodeModel::Internal::UnsavedFiles m_unsavedFiles;
|
||||
};
|
||||
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "utils_p.h"
|
||||
#include "cxraii.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace ClangCodeModel;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
|
||||
@@ -74,7 +76,7 @@ void SemanticMarker::setFileName(const QString &fileName)
|
||||
|
||||
void SemanticMarker::setCompilationOptions(const QStringList &options)
|
||||
{
|
||||
Q_ASSERT(m_unit);
|
||||
QTC_ASSERT(m_unit, return);
|
||||
|
||||
if (m_unit->compilationOptions() == options)
|
||||
return;
|
||||
@@ -84,7 +86,7 @@ void SemanticMarker::setCompilationOptions(const QStringList &options)
|
||||
|
||||
void SemanticMarker::reparse(const UnsavedFiles &unsavedFiles)
|
||||
{
|
||||
Q_ASSERT(m_unit);
|
||||
QTC_ASSERT(m_unit, return);
|
||||
|
||||
m_unit->setUnsavedFiles(unsavedFiles);
|
||||
if (m_unit->isLoaded())
|
||||
@@ -169,9 +171,9 @@ QList<Diagnostic> SemanticMarker::diagnostics() const
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
QList<TextEditor::BlockRange> SemanticMarker::ifdefedOutBlocks() const
|
||||
QList<SemanticMarker::Range> SemanticMarker::ifdefedOutBlocks() const
|
||||
{
|
||||
QList<TextEditor::BlockRange> blocks;
|
||||
QList<Range> blocks;
|
||||
|
||||
if (!m_unit || !m_unit->isLoaded())
|
||||
return blocks;
|
||||
@@ -188,7 +190,7 @@ QList<TextEditor::BlockRange> SemanticMarker::ifdefedOutBlocks() const
|
||||
const SourceLocation &spellEnd = Internal::getSpellingLocation(clang_getRangeEnd(r));
|
||||
const int begin = spellBegin.offset() + 1;
|
||||
const int end = spellEnd.offset() - spellEnd.column();
|
||||
blocks.append(TextEditor::BlockRange(begin, end));
|
||||
blocks.append(Range(begin, end));
|
||||
}
|
||||
clang_disposeSourceRangeList(skippedRanges);
|
||||
#endif
|
||||
@@ -322,9 +324,8 @@ static const QSet<QString> ObjcPseudoKeywords = QSet<QString>()
|
||||
QList<SourceMarker> SemanticMarker::sourceMarkersInRange(unsigned firstLine,
|
||||
unsigned lastLine)
|
||||
{
|
||||
Q_ASSERT(m_unit);
|
||||
|
||||
QList<SourceMarker> result;
|
||||
QTC_ASSERT(m_unit, return result);
|
||||
|
||||
if (!m_unit->isLoaded())
|
||||
return result;
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
#include "sourcemarker.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <texteditor/basetexteditor.h>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QScopedPointer>
|
||||
#include <QSharedPointer>
|
||||
@@ -53,6 +51,16 @@ class CLANG_EXPORT SemanticMarker
|
||||
public:
|
||||
typedef QSharedPointer<SemanticMarker> Ptr;
|
||||
|
||||
class Range
|
||||
{
|
||||
Range();
|
||||
public:
|
||||
Range(int first, int last) : first(first), last(last) {}
|
||||
|
||||
int first;
|
||||
int last;
|
||||
};
|
||||
|
||||
public:
|
||||
SemanticMarker();
|
||||
~SemanticMarker();
|
||||
@@ -69,7 +77,7 @@ public:
|
||||
|
||||
QList<Diagnostic> diagnostics() const;
|
||||
|
||||
QList<TextEditor::BlockRange> ifdefedOutBlocks() const;
|
||||
QList<Range> ifdefedOutBlocks() const;
|
||||
|
||||
QList<SourceMarker> sourceMarkersInRange(unsigned firstLine,
|
||||
unsigned lastLine);
|
||||
|
||||
Reference in New Issue
Block a user