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:
75
src/plugins/clangcodemodel/clanguiheaderondiskmanager.cpp
Normal file
75
src/plugins/clangcodemodel/clanguiheaderondiskmanager.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://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 https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clanguiheaderondiskmanager.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
UiHeaderOnDiskManager::UiHeaderOnDiskManager()
|
||||
: m_temporaryDir(QDir::tempPath() + QStringLiteral("/qtc-clang-uiheader-XXXXXX"))
|
||||
{
|
||||
QTC_CHECK(m_temporaryDir.isValid());
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::createIfNeeded(const QString &filePath)
|
||||
{
|
||||
const QString mappedPath = mapPath(filePath);
|
||||
if (!QFileInfo::exists(mappedPath)) {
|
||||
const bool fileCreated = QFile(mappedPath).open(QFile::WriteOnly); // touch file
|
||||
QTC_CHECK(fileCreated);
|
||||
}
|
||||
|
||||
return mappedPath;
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::remove(const QString &filePath)
|
||||
{
|
||||
const QString mappedPath = mapPath(filePath);
|
||||
if (QFileInfo::exists(mappedPath)) {
|
||||
const bool fileRemoved = QFile::remove(mappedPath);
|
||||
QTC_CHECK(fileRemoved);
|
||||
}
|
||||
|
||||
return mappedPath;
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::directoryPath() const
|
||||
{
|
||||
return m_temporaryDir.path();
|
||||
}
|
||||
|
||||
QString UiHeaderOnDiskManager::mapPath(const QString &filePath) const
|
||||
{
|
||||
return directoryPath() + '/' + QFileInfo(filePath).fileName();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
Reference in New Issue
Block a user