2013-08-23 15:07:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2013-08-23 15:07:19 +02:00
|
|
|
**
|
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-08-23 15:07:19 +02: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-08-23 15:07:19 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-08-23 15:07:19 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "cpplocatordata.h"
|
2014-02-25 16:16:11 +01:00
|
|
|
#include "cpptoolsplugin.h"
|
2013-08-23 15:07:19 +02:00
|
|
|
|
|
|
|
using namespace CppTools;
|
|
|
|
using namespace CppTools::Internal;
|
|
|
|
|
2014-03-14 13:54:31 +01:00
|
|
|
enum { MaxPendingDocuments = 10 };
|
2013-08-23 15:07:19 +02:00
|
|
|
|
2014-03-14 13:54:31 +01:00
|
|
|
CppLocatorData::CppLocatorData()
|
|
|
|
: m_strings(&CppToolsPlugin::stringTable())
|
|
|
|
, m_search(CppToolsPlugin::stringTable())
|
2013-08-23 15:07:19 +02:00
|
|
|
, m_pendingDocumentsMutex(QMutex::Recursive)
|
|
|
|
{
|
2014-03-14 13:54:31 +01:00
|
|
|
m_search.setSymbolsToSearchFor(SymbolSearcher::Enums |
|
|
|
|
SymbolSearcher::Classes |
|
|
|
|
SymbolSearcher::Functions);
|
2013-08-23 15:07:19 +02:00
|
|
|
m_pendingDocuments.reserve(MaxPendingDocuments);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
|
|
|
|
|
|
|
int i = 0, ei = m_pendingDocuments.size();
|
|
|
|
for (; i < ei; ++i) {
|
|
|
|
const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i);
|
2015-01-19 11:35:19 +01:00
|
|
|
if (doc->fileName() == document->fileName() && doc->revision() <= document->revision()) {
|
2013-08-23 15:07:19 +02:00
|
|
|
m_pendingDocuments[i] = document;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-05 11:04:49 +01:00
|
|
|
if (i == ei && QFileInfo(document->fileName()).suffix() != QLatin1String("moc"))
|
2013-08-23 15:07:19 +02:00
|
|
|
m_pendingDocuments.append(document);
|
|
|
|
|
|
|
|
flushPendingDocument(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CppLocatorData::onAboutToRemoveFiles(const QStringList &files)
|
|
|
|
{
|
2014-03-14 13:54:31 +01:00
|
|
|
if (files.isEmpty())
|
|
|
|
return;
|
2013-08-23 15:07:19 +02:00
|
|
|
|
2014-03-14 13:54:31 +01:00
|
|
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
2013-08-23 15:07:19 +02:00
|
|
|
|
|
|
|
foreach (const QString &file, files) {
|
2014-03-14 13:54:31 +01:00
|
|
|
m_infosByFile.remove(file);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_pendingDocuments.size(); ++i) {
|
|
|
|
if (m_pendingDocuments.at(i)->fileName() == file) {
|
|
|
|
m_pendingDocuments.remove(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-23 15:07:19 +02:00
|
|
|
}
|
2014-02-25 16:16:11 +01:00
|
|
|
|
2014-03-14 13:54:31 +01:00
|
|
|
m_strings->scheduleGC();
|
|
|
|
flushPendingDocument(false);
|
2013-08-23 15:07:19 +02:00
|
|
|
}
|
|
|
|
|
2014-03-14 13:54:31 +01:00
|
|
|
void CppLocatorData::flushPendingDocument(bool force) const
|
2013-08-23 15:07:19 +02:00
|
|
|
{
|
2014-03-14 13:54:31 +01:00
|
|
|
// TODO: move this off the UI thread and into a future.
|
2013-08-23 15:07:19 +02:00
|
|
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
|
|
|
if (!force && m_pendingDocuments.size() < MaxPendingDocuments)
|
|
|
|
return;
|
2014-03-14 13:54:31 +01:00
|
|
|
if (m_pendingDocuments.isEmpty())
|
|
|
|
return;
|
2013-08-23 15:07:19 +02:00
|
|
|
|
2014-03-14 13:54:31 +01:00
|
|
|
foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments)
|
|
|
|
m_infosByFile.insert(findOrInsertFilePath(doc->fileName()), m_search(doc));
|
2013-08-23 15:07:19 +02:00
|
|
|
|
|
|
|
m_pendingDocuments.clear();
|
|
|
|
m_pendingDocuments.reserve(MaxPendingDocuments);
|
|
|
|
}
|
|
|
|
|
2014-04-14 16:52:01 +02:00
|
|
|
QList<IndexItem::Ptr> CppLocatorData::allIndexItems(
|
|
|
|
const QHash<QString, QList<IndexItem::Ptr>> &items) const
|
2013-08-23 15:07:19 +02:00
|
|
|
{
|
2014-04-14 16:52:01 +02:00
|
|
|
QList<IndexItem::Ptr> result;
|
|
|
|
QHashIterator<QString, QList<IndexItem::Ptr> > it(items);
|
2013-08-23 15:07:19 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
result.append(it.value());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|