forked from qt-creator/qt-creator
CppEditor: Remove Snapshot::remove(QString) overload
... and fix fallout. Change-Id: Ibbf865c3e4158fc98bb9b5372ce0633807b85576 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -381,8 +381,6 @@ public:
|
||||
|
||||
void insert(Document::Ptr doc); // ### remove
|
||||
void remove(const Utils::FilePath &fileName); // ### remove
|
||||
void remove(const QString &fileName)
|
||||
{ remove(Utils::FilePath::fromString(fileName)); }
|
||||
|
||||
const_iterator begin() const { return _documents.begin(); }
|
||||
const_iterator end() const { return _documents.end(); }
|
||||
|
@@ -8,6 +8,8 @@
|
||||
#include "cppprojectpartchooser.h"
|
||||
#include "editordocumenthandle.h"
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
/*!
|
||||
@@ -29,7 +31,7 @@ namespace CppEditor {
|
||||
\endlist
|
||||
*/
|
||||
|
||||
BaseEditorDocumentParser::BaseEditorDocumentParser(const QString &filePath)
|
||||
BaseEditorDocumentParser::BaseEditorDocumentParser(const FilePath &filePath)
|
||||
: m_filePath(filePath)
|
||||
{
|
||||
static int meta = qRegisterMetaType<ProjectPartInfo>("ProjectPartInfo");
|
||||
@@ -38,7 +40,7 @@ BaseEditorDocumentParser::BaseEditorDocumentParser(const QString &filePath)
|
||||
|
||||
BaseEditorDocumentParser::~BaseEditorDocumentParser() = default;
|
||||
|
||||
QString BaseEditorDocumentParser::filePath() const
|
||||
const FilePath &BaseEditorDocumentParser::filePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
|
@@ -58,10 +58,10 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
BaseEditorDocumentParser(const QString &filePath);
|
||||
BaseEditorDocumentParser(const Utils::FilePath &filePath);
|
||||
~BaseEditorDocumentParser() override;
|
||||
|
||||
QString filePath() const;
|
||||
const Utils::FilePath &filePath() const;
|
||||
Configuration configuration() const;
|
||||
void setConfiguration(const Configuration &configuration);
|
||||
|
||||
@@ -94,10 +94,10 @@ private:
|
||||
virtual void updateImpl(const QFutureInterface<void> &future,
|
||||
const UpdateParams &updateParams) = 0;
|
||||
|
||||
const QString m_filePath;
|
||||
const Utils::FilePath m_filePath;
|
||||
Configuration m_configuration;
|
||||
State m_state;
|
||||
mutable QMutex m_updateIsRunning;
|
||||
};
|
||||
|
||||
} // namespace CppEditor
|
||||
} // CppEditor
|
||||
|
@@ -69,7 +69,7 @@ void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
|
||||
}
|
||||
|
||||
parser->update(future, updateParams);
|
||||
CppModelManager::instance()->finishedRefreshingSourceFiles({parser->filePath()});
|
||||
CppModelManager::instance()->finishedRefreshingSourceFiles({parser->filePath().toString()});
|
||||
|
||||
future.setProgressValue(1);
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ static QByteArray overwrittenToolchainDefines(const ProjectPart &projectPart)
|
||||
return defines;
|
||||
}
|
||||
|
||||
BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath,
|
||||
BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const FilePath &filePath,
|
||||
int fileSizeLimitInMb)
|
||||
: BaseEditorDocumentParser(filePath)
|
||||
, m_fileSizeLimitInMb(fileSizeLimitInMb)
|
||||
@@ -62,7 +62,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
||||
QString projectConfigFile;
|
||||
LanguageFeatures features = LanguageFeatures::defaultFeatures();
|
||||
|
||||
baseState.projectPartInfo = determineProjectPart(filePath(),
|
||||
baseState.projectPartInfo = determineProjectPart(filePath().toString(),
|
||||
baseConfig.preferredProjectPartId,
|
||||
baseState.projectPartInfo,
|
||||
updateParams.activeProject,
|
||||
@@ -166,7 +166,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
||||
state.snapshot.remove(filePath());
|
||||
|
||||
Internal::CppSourceProcessor sourceProcessor(state.snapshot, [&](const Document::Ptr &doc) {
|
||||
const bool isInEditor = doc->filePath().toString() == filePath();
|
||||
const bool isInEditor = doc->filePath() == filePath();
|
||||
Document::Ptr otherDoc = modelManager->document(doc->filePath());
|
||||
unsigned newRev = otherDoc.isNull() ? 1U : otherDoc->revision() + 1;
|
||||
if (isInEditor)
|
||||
@@ -193,12 +193,12 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
||||
sourceProcessor.run(precompiledHeader);
|
||||
}
|
||||
if (!baseState.editorDefines.isEmpty())
|
||||
sourceProcessor.run(CppModelManager::editorConfigurationFileName());
|
||||
sourceProcessor.run(CppModelManager::editorConfigurationFileName().path());
|
||||
QStringList includedFiles = state.includedFiles;
|
||||
if (baseConfig.usePrecompiledHeaders)
|
||||
includedFiles << state.precompiledHeaders;
|
||||
includedFiles.removeDuplicates();
|
||||
sourceProcessor.run(filePath(), includedFiles);
|
||||
sourceProcessor.run(filePath().toString(), includedFiles);
|
||||
state.snapshot = sourceProcessor.snapshot();
|
||||
Snapshot newSnapshot = state.snapshot.simplified(state.snapshot.document(filePath()));
|
||||
for (Snapshot::const_iterator i = state.snapshot.begin(), ei = state.snapshot.end(); i != ei; ++i) {
|
||||
@@ -253,7 +253,7 @@ void BuiltinEditorDocumentParser::addFileAndDependencies(Snapshot *snapshot,
|
||||
QTC_ASSERT(snapshot, return);
|
||||
|
||||
toRemove->insert(fileName);
|
||||
if (fileName != Utils::FilePath::fromString(filePath())) {
|
||||
if (fileName != filePath()) {
|
||||
Utils::FilePaths deps = snapshot->filesDependingOn(fileName);
|
||||
toRemove->unite(Utils::toSet(deps));
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ class CPPEDITOR_EXPORT BuiltinEditorDocumentParser : public BaseEditorDocumentPa
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BuiltinEditorDocumentParser(const QString &filePath, int fileSizeLimitInMb = -1);
|
||||
BuiltinEditorDocumentParser(const Utils::FilePath &filePath, int fileSizeLimitInMb = -1);
|
||||
|
||||
bool releaseSourceAndAST() const;
|
||||
void setReleaseSourceAndAST(bool release);
|
||||
|
@@ -137,8 +137,7 @@ QList<TextEditor::BlockRange> toTextEditorBlocks(
|
||||
|
||||
BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(TextEditor::TextDocument *document)
|
||||
: BaseEditorDocumentProcessor(document->document(), document->filePath())
|
||||
, m_parser(new BuiltinEditorDocumentParser(document->filePath().toString(),
|
||||
indexerFileSizeLimitInMb()))
|
||||
, m_parser(new BuiltinEditorDocumentParser(document->filePath(), indexerFileSizeLimitInMb()))
|
||||
, m_codeWarningsUpdated(false)
|
||||
, m_semanticHighlighter(new SemanticHighlighter(document))
|
||||
{
|
||||
|
@@ -135,7 +135,7 @@ void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
||||
qDebug("FindErrorsIndexing: \"%s\"", qPrintable(file));
|
||||
|
||||
// Parse the file as precisely as possible
|
||||
BuiltinEditorDocumentParser parser(file);
|
||||
BuiltinEditorDocumentParser parser(FilePath::fromString(file));
|
||||
parser.setReleaseSourceAndAST(false);
|
||||
parser.update({CppModelManager::instance()->workingCopy(), nullptr,
|
||||
Utils::Language::Cxx, false});
|
||||
@@ -171,7 +171,7 @@ void index(QFutureInterface<void> &indexingFuture,
|
||||
classifyFiles(params.sourceFiles, &headers, &sources);
|
||||
|
||||
for (const QString &file : std::as_const(params.sourceFiles))
|
||||
sourceProcessor->removeFromCache(file);
|
||||
sourceProcessor->removeFromCache(FilePath::fromString(file));
|
||||
|
||||
const int sourceCount = sources.size();
|
||||
QStringList files = sources + headers;
|
||||
|
@@ -648,7 +648,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
return processLinkCallback(link); //already on definition!
|
||||
} else if (const Document::MacroUse *use = doc->findMacroUseAt(endOfToken - 1)) {
|
||||
const FilePath filePath = use->macro().filePath();
|
||||
if (filePath.path() == CppModelManager::editorConfigurationFileName()) {
|
||||
if (filePath.path() == CppModelManager::editorConfigurationFileName().path()) {
|
||||
editorWidget->showPreProcessorWidget();
|
||||
} else if (filePath.path() != CppModelManager::configurationFileName().path()) {
|
||||
const Macro ¯o = use->macro();
|
||||
|
@@ -304,9 +304,10 @@ CppSourceProcessor *CppModelManager::createSourceProcessor()
|
||||
});
|
||||
}
|
||||
|
||||
QString CppModelManager::editorConfigurationFileName()
|
||||
const FilePath &CppModelManager::editorConfigurationFileName()
|
||||
{
|
||||
return QLatin1String("<per-editor-defines>");
|
||||
static const FilePath config = FilePath::fromPathPart(u"<per-editor-defines>");
|
||||
return config;
|
||||
}
|
||||
|
||||
ModelManagerSupport *CppModelManager::modelManagerSupport(Backend backend) const
|
||||
@@ -1309,7 +1310,7 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec
|
||||
FilePath::fromString(cxxFile.path));
|
||||
for (const FilePath &filePath : filePaths)
|
||||
d->m_snapshot.remove(filePath);
|
||||
d->m_snapshot.remove(cxxFile.path);
|
||||
d->m_snapshot.remove(FilePath::fromString(cxxFile.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1325,7 +1326,7 @@ void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove
|
||||
{
|
||||
QMutexLocker snapshotLocker(&d->m_snapshotMutex);
|
||||
for (const QString &file : filesToRemove)
|
||||
d->m_snapshot.remove(file);
|
||||
d->m_snapshot.remove(FilePath::fromString(file));
|
||||
}
|
||||
|
||||
class ProjectInfoComparer
|
||||
|
@@ -211,7 +211,7 @@ public:
|
||||
|
||||
static Internal::CppSourceProcessor *createSourceProcessor();
|
||||
static const Utils::FilePath &configurationFileName();
|
||||
static QString editorConfigurationFileName();
|
||||
static const Utils::FilePath &editorConfigurationFileName();
|
||||
|
||||
void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);
|
||||
void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);
|
||||
|
@@ -1059,7 +1059,7 @@ void ModelManagerTest::testRenameIncludesInEditor()
|
||||
const QString renamedHeaderWithUnderscoredGuard(workingDir.filePath(_("foobar4000.h")));
|
||||
const QString headerWithMalformedGuard(workingDir.filePath(_("baz3.h")));
|
||||
const QString renamedHeaderWithMalformedGuard(workingDir.filePath(_("foobar5000.h")));
|
||||
const QString mainFile(workingDir.filePath(_("main.cpp")));
|
||||
const FilePath mainFile = FilePath::fromString(workingDir.filePath("main.cpp"));
|
||||
CppModelManager *modelManager = CppModelManager::instance();
|
||||
const MyTestDataDir testDir(_("testdata_project1"));
|
||||
|
||||
@@ -1088,7 +1088,7 @@ void ModelManagerTest::testRenameIncludesInEditor()
|
||||
|
||||
// Open a file in the editor
|
||||
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(Utils::FilePath::fromString(mainFile));
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(mainFile);
|
||||
QVERIFY(editor);
|
||||
EditorCloser editorCloser(editor);
|
||||
Utils::ExecuteOnDestruction saveAllFiles([](){
|
||||
@@ -1157,7 +1157,7 @@ void ModelManagerTest::testRenameIncludesInEditor()
|
||||
QCOMPARE(renamedHeaderContents, originalMalformedGuardContents);
|
||||
|
||||
// Update the c++ model manager again and check for the new includes
|
||||
TestCase::waitForProcessedEditorDocument(mainFile);
|
||||
TestCase::waitForProcessedEditorDocument(mainFile.toString());
|
||||
modelManager->updateSourceFiles(sourceFiles).waitForFinished();
|
||||
QCoreApplication::processEvents();
|
||||
snapshot = modelManager->snapshot();
|
||||
|
@@ -170,9 +170,9 @@ void CppSourceProcessor::run(const QString &fileName,
|
||||
sourceNeeded(0, fileName, IncludeGlobal, initialIncludes);
|
||||
}
|
||||
|
||||
void CppSourceProcessor::removeFromCache(const QString &fileName)
|
||||
void CppSourceProcessor::removeFromCache(const FilePath &filePath)
|
||||
{
|
||||
m_snapshot.remove(fileName);
|
||||
m_snapshot.remove(filePath);
|
||||
}
|
||||
|
||||
void CppSourceProcessor::resetEnvironment()
|
||||
@@ -213,7 +213,7 @@ bool CppSourceProcessor::getFileContents(const FilePath &absoluteFilePath,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CppSourceProcessor::checkFile(const QString &absoluteFilePath) const
|
||||
bool CppSourceProcessor::checkFile(const FilePath &absoluteFilePath) const
|
||||
{
|
||||
if (absoluteFilePath.isEmpty()
|
||||
|| m_included.contains(absoluteFilePath)
|
||||
@@ -221,8 +221,7 @@ bool CppSourceProcessor::checkFile(const QString &absoluteFilePath) const
|
||||
return true;
|
||||
}
|
||||
|
||||
const QFileInfo fileInfo(absoluteFilePath);
|
||||
return fileInfo.isFile() && fileInfo.isReadable();
|
||||
return absoluteFilePath.isReadableFile();
|
||||
}
|
||||
|
||||
QString CppSourceProcessor::cleanPath(const QString &path)
|
||||
@@ -240,14 +239,15 @@ QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType typ
|
||||
if (isInjectedFile(fileName))
|
||||
return fileName;
|
||||
|
||||
if (QFileInfo(fileName).isAbsolute())
|
||||
return checkFile(fileName) ? fileName : QString();
|
||||
const FilePath filePath = FilePath::fromString(fileName);
|
||||
if (filePath.isAbsolutePath())
|
||||
return checkFile(filePath) ? fileName : QString();
|
||||
|
||||
if (m_currentDoc) {
|
||||
if (type == IncludeLocal) {
|
||||
const QFileInfo currentFileInfo = m_currentDoc->filePath().toFileInfo();
|
||||
const QString path = cleanPath(currentFileInfo.absolutePath()) + fileName;
|
||||
if (checkFile(path))
|
||||
if (checkFile(FilePath::fromString(path)))
|
||||
return path;
|
||||
// Fall through! "16.2 Source file inclusion" from the standard states to continue
|
||||
// searching as if this would be a global include.
|
||||
@@ -291,7 +291,8 @@ QString CppSourceProcessor::resolveFile_helper(const QString &fileName,
|
||||
} else {
|
||||
path = headerPathsIt->path + fileName;
|
||||
}
|
||||
if (m_workingCopy.contains(path) || checkFile(path))
|
||||
const FilePath filePath = FilePath::fromString(path);
|
||||
if (m_workingCopy.contains(filePath) || checkFile(filePath))
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -386,7 +387,7 @@ void CppSourceProcessor::mergeEnvironment(Document::Ptr doc)
|
||||
|
||||
if (Document::Ptr includedDoc = m_snapshot.document(includedFile))
|
||||
mergeEnvironment(includedDoc);
|
||||
else if (!m_included.contains(includedFile))
|
||||
else if (!m_included.contains(FilePath::fromString(includedFile)))
|
||||
run(includedFile);
|
||||
}
|
||||
|
||||
@@ -421,10 +422,10 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (m_included.contains(absoluteFileName))
|
||||
if (m_included.contains(absoluteFilePath))
|
||||
return; // We've already seen this file.
|
||||
if (!isInjectedFile(absoluteFileName))
|
||||
m_included.insert(absoluteFileName);
|
||||
m_included.insert(absoluteFilePath);
|
||||
|
||||
// Already in snapshot? Use it!
|
||||
if (Document::Ptr document = m_snapshot.document(absoluteFileName)) {
|
||||
@@ -451,7 +452,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
|
||||
document->setEditorRevision(editorRevision);
|
||||
document->setLanguageFeatures(m_languageFeatures);
|
||||
for (const QString &include : initialIncludes) {
|
||||
m_included.insert(include);
|
||||
m_included.insert(FilePath::fromString(include));
|
||||
Document::Include inc(include, include, 0, IncludeLocal);
|
||||
document->addIncludeFile(inc);
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ public:
|
||||
void setTodo(const QSet<QString> &files);
|
||||
|
||||
void run(const QString &fileName, const QStringList &initialIncludes = QStringList());
|
||||
void removeFromCache(const QString &fileName);
|
||||
void removeFromCache(const Utils::FilePath &filePath);
|
||||
void resetEnvironment();
|
||||
|
||||
CPlusPlus::Snapshot snapshot() const { return m_snapshot; }
|
||||
@@ -61,7 +61,7 @@ private:
|
||||
|
||||
bool getFileContents(const Utils::FilePath &absoluteFilePath, QByteArray *contents,
|
||||
unsigned *revision) const;
|
||||
bool checkFile(const QString &absoluteFilePath) const;
|
||||
bool checkFile(const Utils::FilePath &absoluteFilePath) const;
|
||||
QString resolveFile(const QString &fileName, IncludeType type);
|
||||
QString resolveFile_helper(const QString &fileName,
|
||||
ProjectExplorer::HeaderPaths::Iterator headerPathsIt);
|
||||
@@ -95,7 +95,7 @@ private:
|
||||
ProjectExplorer::HeaderPaths m_headerPaths;
|
||||
CPlusPlus::LanguageFeatures m_languageFeatures;
|
||||
WorkingCopy m_workingCopy;
|
||||
QSet<QString> m_included;
|
||||
QSet<Utils::FilePath> m_included;
|
||||
CPlusPlus::Document::Ptr m_currentDoc;
|
||||
QSet<QString> m_todo;
|
||||
QSet<QString> m_processed;
|
||||
@@ -104,4 +104,4 @@ private:
|
||||
QTextCodec *m_defaultCodec;
|
||||
};
|
||||
|
||||
} // namespace CppEditor::Internal
|
||||
} // CppEditor::Internal
|
||||
|
@@ -18,15 +18,9 @@ class CPPEDITOR_EXPORT WorkingCopy
|
||||
public:
|
||||
WorkingCopy();
|
||||
|
||||
void insert(const QString &fileName, const QByteArray &source, unsigned revision = 0)
|
||||
{ insert(Utils::FilePath::fromString(fileName), source, revision); }
|
||||
|
||||
void insert(const Utils::FilePath &fileName, const QByteArray &source, unsigned revision = 0)
|
||||
{ _elements.insert(fileName, {source, revision}); }
|
||||
|
||||
bool contains(const QString &fileName) const
|
||||
{ return contains(Utils::FilePath::fromString(fileName)); }
|
||||
|
||||
bool contains(const Utils::FilePath &fileName) const
|
||||
{ return _elements.contains(fileName); }
|
||||
|
||||
|
@@ -130,7 +130,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
|
||||
QVERIFY(waitUntilAProjectIsLoaded());
|
||||
|
||||
// Collect files to process
|
||||
QStringList filesToOpen;
|
||||
FilePaths filesToOpen;
|
||||
QList<QPointer<ProjectExplorer::Project> > projects;
|
||||
const QList<ProjectInfo::ConstPtr> projectInfos = m_modelManager->projectInfos();
|
||||
|
||||
@@ -139,15 +139,15 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
|
||||
<< info->sourceFiles().size();
|
||||
const QSet<QString> sourceFiles = info->sourceFiles();
|
||||
for (const QString &sourceFile : sourceFiles)
|
||||
filesToOpen << sourceFile;
|
||||
filesToOpen << FilePath::fromString(sourceFile);
|
||||
}
|
||||
|
||||
Utils::sort(filesToOpen);
|
||||
|
||||
// Process all files from the projects
|
||||
for (const QString &filePath : std::as_const(filesToOpen)) {
|
||||
for (const FilePath &filePath : std::as_const(filesToOpen)) {
|
||||
// Skip e.g. "<configuration>"
|
||||
if (!QFileInfo::exists(filePath))
|
||||
if (!filePath.exists())
|
||||
continue;
|
||||
|
||||
qDebug() << " --" << filePath;
|
||||
@@ -159,7 +159,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
|
||||
QCOMPARE(DocumentModel::openedDocuments().size(), 0);
|
||||
BaseTextEditor *editor;
|
||||
CppEditorWidget *editorWidget;
|
||||
QVERIFY(openCppEditor(FilePath::fromString(filePath), &editor, &editorWidget));
|
||||
QVERIFY(openCppEditor(filePath, &editor, &editorWidget));
|
||||
|
||||
QCOMPARE(DocumentModel::openedDocuments().size(), 1);
|
||||
QVERIFY(m_modelManager->isCppEditor(editor));
|
||||
@@ -176,7 +176,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
|
||||
|
||||
const Snapshot snapshot = globalSnapshot();
|
||||
Document::Ptr document = snapshot.preprocessedDocument(
|
||||
editorWidget->document()->toPlainText().toUtf8(), Utils::FilePath::fromString(filePath));
|
||||
editorWidget->document()->toPlainText().toUtf8(), filePath);
|
||||
QVERIFY(document);
|
||||
document->parse();
|
||||
TranslationUnit *translationUnit = document->translationUnit();
|
||||
|
Reference in New Issue
Block a user