Clang: Add revision and completion management

Reparsing a document is expensive so we should avoid it by all means. In
this patch we prevent that the same document is send again. It isn't send
too in advance of a code completion if there was no changes before the
the completion position.

Change-Id: I0bb786ba1d4e7ce08611a518cb32f8cf8f4d0037
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Marco Bubke
2015-09-28 17:42:43 +02:00
parent 803cca4086
commit b412eb81ea
18 changed files with 540 additions and 22 deletions

View File

@@ -64,7 +64,8 @@ HEADERS += \
stringtable.h \
symbolfinder.h \
symbolsfindfilter.h \
typehierarchybuilder.h
typehierarchybuilder.h \
senddocumenttracker.h
SOURCES += \
abstracteditorsupport.cpp \
@@ -126,7 +127,8 @@ SOURCES += \
stringtable.cpp \
symbolfinder.cpp \
symbolsfindfilter.cpp \
typehierarchybuilder.cpp
typehierarchybuilder.cpp \
senddocumenttracker.cpp
FORMS += \
completionsettingspage.ui \

View File

@@ -84,6 +84,7 @@ QtcPlugin {
"insertionpointlocator.cpp", "insertionpointlocator.h",
"searchsymbols.cpp", "searchsymbols.h",
"semantichighlighter.cpp", "semantichighlighter.h",
"senddocumenttracker.cpp", "senddocumenttracker.h",
"stringtable.cpp", "stringtable.h",
"symbolfinder.cpp", "symbolfinder.h",
"symbolsfindfilter.cpp", "symbolsfindfilter.h",

View File

@@ -0,0 +1,3 @@
HEADERS += $$PWD/senddocumenttracker.h
SOURCES += $$PWD/senddocumenttracker.cpp

View File

@@ -58,4 +58,9 @@ void CppEditorDocumentHandle::setNeedsRefresh(bool needsRefresh)
m_needsRefresh = needsRefresh;
}
SendDocumentTracker &CppEditorDocumentHandle::sendTracker(const QString &projectPartId)
{
return m_documentRevisionManagements[projectPartId];
}
} // namespace CppTools

View File

@@ -32,6 +32,10 @@
#define EDITORDOCUMENTHANDLE_H
#include "cpptools_global.h"
#include "senddocumenttracker.h"
#include <QMap>
#include <QString>
namespace CppTools {
class BaseEditorDocumentProcessor;
@@ -55,7 +59,10 @@ public:
virtual void resetProcessor() = 0;
SendDocumentTracker &sendTracker(const QString &projectPartId);
private:
QMap<QString, SendDocumentTracker> m_documentRevisionManagements;
bool m_needsRefresh;
};

View File

@@ -0,0 +1,89 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/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 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.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "senddocumenttracker.h"
#include <algorithm>
namespace CppTools {
void SendDocumentTracker::setLastSentRevision(int revision)
{
m_lastSentRevision = revision;
m_contentChangeStartPosition = std::numeric_limits<int>::max();
}
int SendDocumentTracker::lastSentRevision() const
{
return m_lastSentRevision;
}
void SendDocumentTracker::setLastCompletionPosition(int lastCompletionPosition)
{
m_lastCompletionPosition = lastCompletionPosition;
}
int SendDocumentTracker::lastCompletionPosition() const
{
return m_lastCompletionPosition;
}
void SendDocumentTracker::applyContentChange(int startPosition)
{
if (startPosition < m_lastCompletionPosition)
m_lastCompletionPosition = -1;
m_contentChangeStartPosition = std::min(startPosition, m_contentChangeStartPosition);
}
bool SendDocumentTracker::shouldSendCompletion(int newCompletionPosition) const
{
return m_lastCompletionPosition != newCompletionPosition;
}
bool SendDocumentTracker::shouldSendRevision(uint newRevision) const
{
return m_lastSentRevision != int(newRevision);
}
bool SendDocumentTracker::shouldSendRevisionWithCompletionPosition(int newRevision, int newCompletionPosition) const
{
if (shouldSendRevision(newRevision))
return changedBeforeCompletionPosition(newCompletionPosition);
return false;
}
bool SendDocumentTracker::changedBeforeCompletionPosition(int newCompletionPosition) const
{
return m_contentChangeStartPosition < newCompletionPosition;
}
} // namespace CppTools

View File

@@ -0,0 +1,66 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/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 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.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CPPTOOLS_SENDDOCUMENTTRACKER_H
#define CPPTOOLS_SENDDOCUMENTTRACKER_H
#include "cpptools_global.h"
#include <limits>
namespace CppTools {
class CPPTOOLS_EXPORT SendDocumentTracker
{
public:
void setLastSentRevision(int lastSentRevision);
int lastSentRevision() const;
void setLastCompletionPosition(int lastCompletionPosition);
int lastCompletionPosition() const;
void applyContentChange(int startPosition);
bool shouldSendCompletion(int newCompletionPosition) const;
bool shouldSendRevision(uint newRevision) const;
bool shouldSendRevisionWithCompletionPosition(int newRevision, int newCompletionPosition) const;
private:
bool changedBeforeCompletionPosition(int newCompletionPosition) const;
private:
int m_lastSentRevision = -1;
int m_lastCompletionPosition = -1;
int m_contentChangeStartPosition = std::numeric_limits<int>::max();
};
} // namespace CppTools
#endif // CPPTOOLS_SENDDOCUMENTTRACKER_H