CppEditor: Switch to FilePath in IndexItem

... and fix fallout.

Change-Id: I45d27146806bdcb5ceb728b710eca51c7cd32ee2
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-11-23 17:11:20 +01:00
parent dbdabf9c27
commit 038771051d
12 changed files with 34 additions and 44 deletions

View File

@@ -409,8 +409,7 @@ public:
QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const;
Utils::FilePaths filesDependingOn(const Utils::FilePath &fileName) const;
Utils::FilePaths filesDependingOn(const QString &fileName) const
{ return filesDependingOn(Utils::FilePath::fromString(fileName)); }
void updateDependencyTable() const;
void updateDependencyTable(QFutureInterfaceBase &futureInterface) const;

View File

@@ -19,6 +19,7 @@
#include <tuple>
using namespace LanguageServerProtocol;
using namespace Utils;
namespace ClangCodeModel {
namespace Internal {
@@ -157,9 +158,7 @@ QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
for (const auto &entry : std::as_const(matches)) {
const CppEditor::IndexItem::Ptr item
= qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
locations.insert(std::make_tuple(Utils::FilePath::fromString(item->fileName()),
item->line(),
item->column()));
locations.insert(std::make_tuple(item->filePath(), item->line(), item->column()));
}
for (const auto &entry : lspMatches) {
if (!entry.internalData.canConvert<Utils::Link>())

View File

@@ -112,8 +112,7 @@ void CppCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection,
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt(
{Utils::FilePath::fromString(info->fileName()), info->line(), info->column()});
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()});
}
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)

View File

@@ -120,9 +120,7 @@ void CppLocatorFilter::accept(const Core::LocatorFilterEntry &selection,
Q_UNUSED(selectionStart)
Q_UNUSED(selectionLength)
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
Core::EditorManager::openEditorAt({Utils::FilePath::fromString(info->fileName()),
info->line(),
info->column()},
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()},
{},
Core::EditorManager::AllowExternalEditor);
}
@@ -145,7 +143,7 @@ Core::LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::P
filterEntry.extraInfo = info->symbolScope().isEmpty()
? info->shortNativeFilePath()
: info->symbolScope();
filterEntry.filePath = Utils::FilePath::fromString(info->fileName());
filterEntry.filePath = info->filePath();
return filterEntry;
}
@@ -170,7 +168,7 @@ Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem:
if (extraInfo.isEmpty()) {
extraInfo = info->shortNativeFilePath();
} else {
extraInfo.append(" (" + Utils::FilePath::fromString(info->fileName()).fileName() + ')');
extraInfo.append(" (" + info->filePath().fileName() + ')');
}
Core::LocatorFilterEntry filterEntry(this, name + info->symbolType(), id, info->icon());

View File

@@ -570,15 +570,11 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
continue;
}
Link link;
if (entry.internalData.canConvert<Link>()) {
if (entry.internalData.canConvert<Link>())
link = qvariant_cast<Link>(entry.internalData);
} else {
const auto item = qvariant_cast<IndexItem::Ptr>(entry.internalData);
if (item) {
link = Link(FilePath::fromString(item->fileName()), item->line(),
item->column());
}
}
else if (const auto item = qvariant_cast<IndexItem::Ptr>(entry.internalData))
link = Link(item->filePath(), item->line(), item->column());
if (link.hasValidTarget() && link.targetFilePath.isReadableFile()
&& (folder.isEmpty() || link.targetFilePath.isChildOf(folder))
&& SessionManager::projectForFile(link.targetFilePath)) {

View File

@@ -2071,17 +2071,17 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
indexItems << info;
Snapshot localForwardHeaders = forwardHeaders;
localForwardHeaders.insert(interface.snapshot().document(info->fileName()));
Utils::FilePaths headerAndItsForwardingHeaders;
headerAndItsForwardingHeaders << Utils::FilePath::fromString(info->fileName());
headerAndItsForwardingHeaders += localForwardHeaders.filesDependingOn(info->fileName());
localForwardHeaders.insert(interface.snapshot().document(info->filePath()));
FilePaths headerAndItsForwardingHeaders;
headerAndItsForwardingHeaders << info->filePath();
headerAndItsForwardingHeaders += localForwardHeaders.filesDependingOn(info->filePath());
for (const Utils::FilePath &header : std::as_const(headerAndItsForwardingHeaders)) {
for (const FilePath &header : std::as_const(headerAndItsForwardingHeaders)) {
const QString include = findShortestInclude(currentDocumentFilePath,
header.toString(),
headerPaths);
if (include.size() > 2) {
const QString headerFileName = Utils::FilePath::fromString(info->fileName()).fileName();
const QString headerFileName = info->filePath().fileName();
QTC_ASSERT(!headerFileName.isEmpty(), break);
int priority = 0;

View File

@@ -134,15 +134,14 @@ bool CppToolsJsExtension::hasQObjectParent(const QString &klassName) const
// Find class in AST.
const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy();
QByteArray source = workingCopy.source(item->fileName());
QByteArray source = workingCopy.source(item->filePath());
if (source.isEmpty()) {
QFile file(item->fileName());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
std::optional<QByteArray> contents = item->filePath().fileContents();
if (!contents)
return false;
source = file.readAll();
source = *contents;
}
const auto doc = snapshot.preprocessedDocument(source,
Utils::FilePath::fromString(item->fileName()));
const auto doc = snapshot.preprocessedDocument(source, item->filePath());
if (!doc)
return false;
doc->check();

View File

@@ -3,7 +3,7 @@
#include "indexitem.h"
#include <utils/fileutils.h>
using namespace Utils;
namespace CppEditor {
@@ -17,7 +17,7 @@ IndexItem::Ptr IndexItem::create(const QString &symbolName, const QString &symbo
ptr->m_symbolType = symbolType;
ptr->m_symbolScope = symbolScope;
ptr->m_type = type;
ptr->m_fileName = fileName;
ptr->m_filePath = FilePath::fromString(fileName);
ptr->m_line = line;
ptr->m_column = column;
ptr->m_icon = icon;
@@ -29,7 +29,7 @@ IndexItem::Ptr IndexItem::create(const QString &fileName, int sizeHint)
{
Ptr ptr(new IndexItem);
ptr->m_fileName = fileName;
ptr->m_filePath = FilePath::fromString(fileName);
ptr->m_type = Declaration;
ptr->m_line = 0;
ptr->m_column = 0;
@@ -66,7 +66,7 @@ QString IndexItem::representDeclaration() const
QString IndexItem::shortNativeFilePath() const
{
return Utils::FilePath::fromString(m_fileName).shortNativePath();
return m_filePath.shortNativePath();
}
void IndexItem::squeeze()
@@ -76,4 +76,4 @@ void IndexItem::squeeze()
m_children[i]->squeeze();
}
} // CppEditor namespace
} // CppEditor

View File

@@ -5,6 +5,8 @@
#include "cppeditor_global.h"
#include <utils/filepath.h>
#include <QIcon>
#include <QSharedPointer>
#include <QMetaType>
@@ -57,7 +59,7 @@ public:
QString symbolName() const { return m_symbolName; }
QString symbolType() const { return m_symbolType; }
QString symbolScope() const { return m_symbolScope; }
QString fileName() const { return m_fileName; }
const Utils::FilePath &filePath() const { return m_filePath; }
QIcon icon() const { return m_icon; }
ItemType type() const { return m_type; }
int line() const { return m_line; }
@@ -99,7 +101,7 @@ private:
QString m_symbolName; // as found in the code, therefore might be qualified
QString m_symbolType;
QString m_symbolScope;
QString m_fileName;
Utils::FilePath m_filePath;
QIcon m_icon;
ItemType m_type = All;
int m_line = 0;

View File

@@ -46,7 +46,7 @@ IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope
QTC_ASSERT(_parent, return IndexItem::Ptr());
QTC_ASSERT(root, return IndexItem::Ptr());
QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->filePath()),
QTC_ASSERT(_parent->filePath().toString() == Internal::StringTable::insert(doc->filePath()),
return IndexItem::Ptr());
for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)

View File

@@ -154,9 +154,7 @@ void SymbolsFindFilter::openEditor(const SearchResultItem &item)
if (!item.userData().canConvert<IndexItem::Ptr>())
return;
IndexItem::Ptr info = item.userData().value<IndexItem::Ptr>();
EditorManager::openEditorAt({FilePath::fromString(info->fileName()),
info->line(),
info->column()},
EditorManager::openEditorAt({info->filePath(), info->line(), info->column()},
{},
Core::EditorManager::AllowExternalEditor);
}

View File

@@ -136,7 +136,7 @@ void ElementTasks::openClassDefinition(const qmt::MElement *element)
if (info->scopedSymbolName() != qualifiedClassName)
continue;
if (Core::EditorManager::instance()->openEditorAt(
{Utils::FilePath::fromString(info->fileName()), info->line(), info->column()})) {
{info->filePath(), info->line(), info->column()})) {
return;
}
}