forked from qt-creator/qt-creator
Clang: Work around libclang not accepting not existing unsaved files
Feeding libclang with unsaved files (e.g. in-memory generated ui_*.h)
that do not exist on disk leads to regeneration of the preamble on every
parse/reparse/completion and thus renders the clang code model useless.
We could check the existence in the file system for every unsaved file
just before every parse/reparse/completion. Obviously this does not
scale (e.g. qtcreator.pro generates about 200 unsaves files) and would
also slow down the responsiveness of the completion, especially for the
dot-to-arrow correction case.
We could also set up a file system watcher. However, implementing the
"file got created" case is not trivial because QFileSystemWatcher does
not support it out of the box.
Instead, set up a custom include directory and create empty files in it
that represent the unsaved files and pass that include directory to
libclang as the last one. While this fixes the performance problems, it
also comes with at least two problems:
* Because ui_*.h files are "relocated" to the same directory, two or
more "foo.ui" in the same session will be problematic.
* Because of the custom include directory, problems might arise for
projects that include the ui_*.h as "some/relative/path/ui_foo.h"
instead of "ui_foo.h". This should be the less common case.
Task-number: QTCREATORBUG-17245
Change-Id: I6e40e87c3ef095086eb22c972dd8c1a6459a8245
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
using namespace ClangCodeModel;
|
||||
using namespace ClangCodeModel::Internal;
|
||||
|
||||
static ModelManagerSupportClang *m_instance_forTestsOnly = 0;
|
||||
static ModelManagerSupportClang *m_instance = 0;
|
||||
|
||||
static CppTools::CppModelManager *cppModelManager()
|
||||
{
|
||||
@@ -60,8 +60,8 @@ static CppTools::CppModelManager *cppModelManager()
|
||||
ModelManagerSupportClang::ModelManagerSupportClang()
|
||||
: m_completionAssistProvider(m_ipcCommunicator)
|
||||
{
|
||||
QTC_CHECK(!m_instance_forTestsOnly);
|
||||
m_instance_forTestsOnly = this;
|
||||
QTC_CHECK(!m_instance);
|
||||
m_instance = this;
|
||||
|
||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||
connect(editorManager, &Core::EditorManager::editorOpened,
|
||||
@@ -88,7 +88,7 @@ ModelManagerSupportClang::ModelManagerSupportClang()
|
||||
|
||||
ModelManagerSupportClang::~ModelManagerSupportClang()
|
||||
{
|
||||
m_instance_forTestsOnly = 0;
|
||||
m_instance = 0;
|
||||
}
|
||||
|
||||
CppTools::CppCompletionAssistProvider *ModelManagerSupportClang::completionAssistProvider()
|
||||
@@ -244,15 +244,19 @@ void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QStr
|
||||
const QByteArray &content)
|
||||
{
|
||||
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||
m_ipcCommunicator.updateUnsavedFile(filePath, content, 0);
|
||||
|
||||
const QString mappedPath = m_uiHeaderOnDiskManager.createIfNeeded(filePath);
|
||||
m_ipcCommunicator.updateUnsavedFile(mappedPath, content, 0);
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &filePath)
|
||||
{
|
||||
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||
|
||||
if (!cppModelManager()->cppEditorDocument(filePath)) {
|
||||
const QString mappedPath = m_uiHeaderOnDiskManager.remove(filePath);
|
||||
const QString projectPartId = Utils::projectPartIdForFile(filePath);
|
||||
m_ipcCommunicator.unregisterUnsavedFilesForEditor({{filePath, projectPartId}});
|
||||
m_ipcCommunicator.unregisterUnsavedFilesForEditor({{mappedPath, projectPartId}});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,18 +351,26 @@ void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
ModelManagerSupportClang *ModelManagerSupportClang::instance_forTestsOnly()
|
||||
ModelManagerSupportClang *ModelManagerSupportClang::instance()
|
||||
{
|
||||
return m_instance_forTestsOnly;
|
||||
return m_instance;
|
||||
}
|
||||
#endif
|
||||
|
||||
IpcCommunicator &ModelManagerSupportClang::ipcCommunicator()
|
||||
{
|
||||
return m_ipcCommunicator;
|
||||
}
|
||||
|
||||
QString ModelManagerSupportClang::dummyUiHeaderOnDiskPath(const QString &filePath) const
|
||||
{
|
||||
return m_uiHeaderOnDiskManager.mapPath(filePath);
|
||||
}
|
||||
|
||||
QString ModelManagerSupportClang::dummyUiHeaderOnDiskDirPath() const
|
||||
{
|
||||
return m_uiHeaderOnDiskManager.directoryPath();
|
||||
}
|
||||
|
||||
QString ModelManagerSupportProviderClang::id() const
|
||||
{
|
||||
return QLatin1String(Constants::CLANG_MODELMANAGERSUPPORT_ID);
|
||||
|
||||
Reference in New Issue
Block a user