2013-12-10 14:37:32 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-08 12:00:22 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-12-10 14:37:32 +01:00
|
|
|
** 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
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-12-10 14:37:32 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-12-10 14:37:32 +01:00
|
|
|
**
|
|
|
|
|
** 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 "clangindexer.h"
|
|
|
|
|
#include "clangutils.h"
|
|
|
|
|
#include "indexer.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2014-09-15 00:12:27 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2013-12-10 14:37:32 +01:00
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
|
|
using namespace ClangCodeModel;
|
|
|
|
|
using namespace ClangCodeModel::Internal;
|
|
|
|
|
|
|
|
|
|
ClangIndexingSupport::ClangIndexingSupport(ClangIndexer *indexer)
|
|
|
|
|
: m_indexer(indexer)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangIndexingSupport::~ClangIndexingSupport()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 11:22:02 +02:00
|
|
|
QFuture<void> ClangIndexingSupport::refreshSourceFiles(
|
|
|
|
|
const QSet<QString> &sourceFiles,
|
|
|
|
|
CppTools::CppModelManager::ProgressNotificationMode mode)
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2014-09-05 11:22:02 +02:00
|
|
|
Q_UNUSED(mode);
|
|
|
|
|
|
2013-12-10 14:37:32 +01:00
|
|
|
return m_indexer->refreshSourceFiles(sourceFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppTools::SymbolSearcher *ClangIndexingSupport::createSymbolSearcher(CppTools::SymbolSearcher::Parameters parameters, QSet<QString> fileNames)
|
|
|
|
|
{
|
2014-09-05 11:22:02 +02:00
|
|
|
Q_UNUSED(parameters);
|
|
|
|
|
Q_UNUSED(fileNames)
|
|
|
|
|
// return new ClangSymbolSearcher(m_indexer, parameters, fileNames);
|
|
|
|
|
return 0;
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangIndexer::ClangIndexer()
|
|
|
|
|
: QObject(0)
|
|
|
|
|
, m_indexingSupport(new ClangIndexingSupport(this))
|
|
|
|
|
, m_isLoadingSession(false)
|
|
|
|
|
, m_clangIndexer(new Indexer(this))
|
|
|
|
|
{
|
2014-10-21 15:56:48 +02:00
|
|
|
connect(m_clangIndexer, SIGNAL(indexingStarted(QFuture<void>,Internal::ProgressNotificationMode)),
|
|
|
|
|
this, SLOT(onIndexingStarted(QFuture<void>,Internal::ProgressNotificationMode)));
|
2013-12-10 14:37:32 +01:00
|
|
|
|
2014-02-04 15:15:03 +01:00
|
|
|
QObject *session = ProjectExplorer::SessionManager::instance();
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
connect(session, SIGNAL(aboutToLoadSession(QString)),
|
|
|
|
|
this, SLOT(onAboutToLoadSession(QString)));
|
|
|
|
|
connect(session, SIGNAL(sessionLoaded(QString)),
|
|
|
|
|
this, SLOT(onSessionLoaded(QString)));
|
|
|
|
|
connect(session, SIGNAL(aboutToSaveSession()),
|
|
|
|
|
this, SLOT(onAboutToSaveSession()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangIndexer::~ClangIndexer()
|
|
|
|
|
{
|
|
|
|
|
m_clangIndexer->cancel(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppTools::CppIndexingSupport *ClangIndexer::indexingSupport()
|
|
|
|
|
{
|
|
|
|
|
return m_indexingSupport.data();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 11:22:02 +02:00
|
|
|
QFuture<void> ClangIndexer::refreshSourceFiles(const QSet<QString> &sourceFiles)
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
|
|
|
|
typedef CppTools::ProjectPart ProjectPart;
|
2014-09-05 11:22:02 +02:00
|
|
|
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
if (m_clangIndexer->isBusy())
|
|
|
|
|
m_clangIndexer->cancel(true);
|
|
|
|
|
|
|
|
|
|
foreach (const QString &file, sourceFiles) {
|
2014-09-05 11:22:02 +02:00
|
|
|
if (m_clangIndexer->isTracking(file))
|
2013-12-10 14:37:32 +01:00
|
|
|
continue; // we get notified separately about open files.
|
2014-09-05 11:22:02 +02:00
|
|
|
const QList<ProjectPart::Ptr> &parts = modelManager->projectPart(file);
|
2013-12-10 14:37:32 +01:00
|
|
|
if (!parts.isEmpty())
|
|
|
|
|
m_clangIndexer->addFile(file, parts.at(0));
|
|
|
|
|
else
|
|
|
|
|
m_clangIndexer->addFile(file, ProjectPart::Ptr());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_isLoadingSession)
|
|
|
|
|
m_clangIndexer->regenerate();
|
|
|
|
|
|
|
|
|
|
return QFuture<void>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangIndexer::match(ClangSymbolSearcher *searcher) const
|
|
|
|
|
{
|
|
|
|
|
m_clangIndexer->match(searcher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangIndexer::onAboutToLoadSession(const QString &sessionName)
|
|
|
|
|
{
|
|
|
|
|
m_isLoadingSession = true;
|
|
|
|
|
|
|
|
|
|
if (sessionName == QLatin1String("default"))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString path = Core::ICore::instance()->userResourcePath() + QLatin1String("/codemodel/");
|
|
|
|
|
if (QFile::exists(path) || QDir().mkpath(path))
|
|
|
|
|
m_clangIndexer->initialize(path + sessionName + QLatin1String(".qci"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangIndexer::onSessionLoaded(QString)
|
|
|
|
|
{
|
|
|
|
|
m_isLoadingSession = false;
|
|
|
|
|
m_clangIndexer->regenerate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangIndexer::onAboutToSaveSession()
|
|
|
|
|
{
|
|
|
|
|
m_clangIndexer->finalize();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 12:48:03 +01:00
|
|
|
void ClangIndexer::indexNow(Unit::Ptr unit)
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
|
|
|
|
typedef CppTools::ProjectPart ProjectPart;
|
|
|
|
|
|
2014-01-10 12:48:03 +01:00
|
|
|
QString file = unit->fileName();
|
2014-09-15 00:12:27 +02:00
|
|
|
CppTools::CppModelManager *mmi = CppTools::CppModelManager::instance();
|
2013-12-10 14:37:32 +01:00
|
|
|
const QList<ProjectPart::Ptr> &parts = mmi->projectPart(file);
|
|
|
|
|
ProjectPart::Ptr part;
|
|
|
|
|
if (!parts.isEmpty())
|
|
|
|
|
part = parts.at(0);
|
|
|
|
|
if (!m_isLoadingSession)
|
|
|
|
|
m_clangIndexer->runQuickIndexing(unit, part);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangIndexer::onIndexingStarted(QFuture<void> indexingFuture)
|
|
|
|
|
{
|
2014-09-05 11:22:02 +02:00
|
|
|
Core::ProgressManager::addTask(indexingFuture, QCoreApplication::translate(
|
|
|
|
|
"ClangCodeModel::Internal::ClangIndexer",
|
|
|
|
|
"Parsing C/C++/ObjC Files"),
|
|
|
|
|
"ClangCodeMode.Task.Indexing");
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|