forked from qt-creator/qt-creator
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:
@@ -409,8 +409,7 @@ public:
|
|||||||
QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const;
|
QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const;
|
||||||
|
|
||||||
Utils::FilePaths filesDependingOn(const Utils::FilePath &fileName) 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() const;
|
||||||
void updateDependencyTable(QFutureInterfaceBase &futureInterface) const;
|
void updateDependencyTable(QFutureInterfaceBase &futureInterface) const;
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
using namespace LanguageServerProtocol;
|
using namespace LanguageServerProtocol;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -157,9 +158,7 @@ QList<Core::LocatorFilterEntry> ClangGlobalSymbolFilter::matchesFor(
|
|||||||
for (const auto &entry : std::as_const(matches)) {
|
for (const auto &entry : std::as_const(matches)) {
|
||||||
const CppEditor::IndexItem::Ptr item
|
const CppEditor::IndexItem::Ptr item
|
||||||
= qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
|
= qvariant_cast<CppEditor::IndexItem::Ptr>(entry.internalData);
|
||||||
locations.insert(std::make_tuple(Utils::FilePath::fromString(item->fileName()),
|
locations.insert(std::make_tuple(item->filePath(), item->line(), item->column()));
|
||||||
item->line(),
|
|
||||||
item->column()));
|
|
||||||
}
|
}
|
||||||
for (const auto &entry : lspMatches) {
|
for (const auto &entry : lspMatches) {
|
||||||
if (!entry.internalData.canConvert<Utils::Link>())
|
if (!entry.internalData.canConvert<Utils::Link>())
|
||||||
|
@@ -112,8 +112,7 @@ void CppCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection,
|
|||||||
Q_UNUSED(selectionStart)
|
Q_UNUSED(selectionStart)
|
||||||
Q_UNUSED(selectionLength)
|
Q_UNUSED(selectionLength)
|
||||||
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
|
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
|
||||||
Core::EditorManager::openEditorAt(
|
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()});
|
||||||
{Utils::FilePath::fromString(info->fileName()), info->line(), info->column()});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
|
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
|
||||||
|
@@ -120,9 +120,7 @@ void CppLocatorFilter::accept(const Core::LocatorFilterEntry &selection,
|
|||||||
Q_UNUSED(selectionStart)
|
Q_UNUSED(selectionStart)
|
||||||
Q_UNUSED(selectionLength)
|
Q_UNUSED(selectionLength)
|
||||||
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
|
IndexItem::Ptr info = qvariant_cast<IndexItem::Ptr>(selection.internalData);
|
||||||
Core::EditorManager::openEditorAt({Utils::FilePath::fromString(info->fileName()),
|
Core::EditorManager::openEditorAt({info->filePath(), info->line(), info->column()},
|
||||||
info->line(),
|
|
||||||
info->column()},
|
|
||||||
{},
|
{},
|
||||||
Core::EditorManager::AllowExternalEditor);
|
Core::EditorManager::AllowExternalEditor);
|
||||||
}
|
}
|
||||||
@@ -145,7 +143,7 @@ Core::LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::P
|
|||||||
filterEntry.extraInfo = info->symbolScope().isEmpty()
|
filterEntry.extraInfo = info->symbolScope().isEmpty()
|
||||||
? info->shortNativeFilePath()
|
? info->shortNativeFilePath()
|
||||||
: info->symbolScope();
|
: info->symbolScope();
|
||||||
filterEntry.filePath = Utils::FilePath::fromString(info->fileName());
|
filterEntry.filePath = info->filePath();
|
||||||
return filterEntry;
|
return filterEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +168,7 @@ Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem:
|
|||||||
if (extraInfo.isEmpty()) {
|
if (extraInfo.isEmpty()) {
|
||||||
extraInfo = info->shortNativeFilePath();
|
extraInfo = info->shortNativeFilePath();
|
||||||
} else {
|
} else {
|
||||||
extraInfo.append(" (" + Utils::FilePath::fromString(info->fileName()).fileName() + ')');
|
extraInfo.append(" (" + info->filePath().fileName() + ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LocatorFilterEntry filterEntry(this, name + info->symbolType(), id, info->icon());
|
Core::LocatorFilterEntry filterEntry(this, name + info->symbolType(), id, info->icon());
|
||||||
|
@@ -570,15 +570,11 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Link link;
|
Link link;
|
||||||
if (entry.internalData.canConvert<Link>()) {
|
if (entry.internalData.canConvert<Link>())
|
||||||
link = qvariant_cast<Link>(entry.internalData);
|
link = qvariant_cast<Link>(entry.internalData);
|
||||||
} else {
|
else if (const auto item = qvariant_cast<IndexItem::Ptr>(entry.internalData))
|
||||||
const auto item = qvariant_cast<IndexItem::Ptr>(entry.internalData);
|
link = Link(item->filePath(), item->line(), item->column());
|
||||||
if (item) {
|
|
||||||
link = Link(FilePath::fromString(item->fileName()), item->line(),
|
|
||||||
item->column());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (link.hasValidTarget() && link.targetFilePath.isReadableFile()
|
if (link.hasValidTarget() && link.targetFilePath.isReadableFile()
|
||||||
&& (folder.isEmpty() || link.targetFilePath.isChildOf(folder))
|
&& (folder.isEmpty() || link.targetFilePath.isChildOf(folder))
|
||||||
&& SessionManager::projectForFile(link.targetFilePath)) {
|
&& SessionManager::projectForFile(link.targetFilePath)) {
|
||||||
|
@@ -2071,17 +2071,17 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
|||||||
indexItems << info;
|
indexItems << info;
|
||||||
|
|
||||||
Snapshot localForwardHeaders = forwardHeaders;
|
Snapshot localForwardHeaders = forwardHeaders;
|
||||||
localForwardHeaders.insert(interface.snapshot().document(info->fileName()));
|
localForwardHeaders.insert(interface.snapshot().document(info->filePath()));
|
||||||
Utils::FilePaths headerAndItsForwardingHeaders;
|
FilePaths headerAndItsForwardingHeaders;
|
||||||
headerAndItsForwardingHeaders << Utils::FilePath::fromString(info->fileName());
|
headerAndItsForwardingHeaders << info->filePath();
|
||||||
headerAndItsForwardingHeaders += localForwardHeaders.filesDependingOn(info->fileName());
|
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,
|
const QString include = findShortestInclude(currentDocumentFilePath,
|
||||||
header.toString(),
|
header.toString(),
|
||||||
headerPaths);
|
headerPaths);
|
||||||
if (include.size() > 2) {
|
if (include.size() > 2) {
|
||||||
const QString headerFileName = Utils::FilePath::fromString(info->fileName()).fileName();
|
const QString headerFileName = info->filePath().fileName();
|
||||||
QTC_ASSERT(!headerFileName.isEmpty(), break);
|
QTC_ASSERT(!headerFileName.isEmpty(), break);
|
||||||
|
|
||||||
int priority = 0;
|
int priority = 0;
|
||||||
|
@@ -134,15 +134,14 @@ bool CppToolsJsExtension::hasQObjectParent(const QString &klassName) const
|
|||||||
// Find class in AST.
|
// Find class in AST.
|
||||||
const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
|
const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
|
||||||
const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy();
|
const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy();
|
||||||
QByteArray source = workingCopy.source(item->fileName());
|
QByteArray source = workingCopy.source(item->filePath());
|
||||||
if (source.isEmpty()) {
|
if (source.isEmpty()) {
|
||||||
QFile file(item->fileName());
|
std::optional<QByteArray> contents = item->filePath().fileContents();
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!contents)
|
||||||
return false;
|
return false;
|
||||||
source = file.readAll();
|
source = *contents;
|
||||||
}
|
}
|
||||||
const auto doc = snapshot.preprocessedDocument(source,
|
const auto doc = snapshot.preprocessedDocument(source, item->filePath());
|
||||||
Utils::FilePath::fromString(item->fileName()));
|
|
||||||
if (!doc)
|
if (!doc)
|
||||||
return false;
|
return false;
|
||||||
doc->check();
|
doc->check();
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "indexitem.h"
|
#include "indexitem.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ IndexItem::Ptr IndexItem::create(const QString &symbolName, const QString &symbo
|
|||||||
ptr->m_symbolType = symbolType;
|
ptr->m_symbolType = symbolType;
|
||||||
ptr->m_symbolScope = symbolScope;
|
ptr->m_symbolScope = symbolScope;
|
||||||
ptr->m_type = type;
|
ptr->m_type = type;
|
||||||
ptr->m_fileName = fileName;
|
ptr->m_filePath = FilePath::fromString(fileName);
|
||||||
ptr->m_line = line;
|
ptr->m_line = line;
|
||||||
ptr->m_column = column;
|
ptr->m_column = column;
|
||||||
ptr->m_icon = icon;
|
ptr->m_icon = icon;
|
||||||
@@ -29,7 +29,7 @@ IndexItem::Ptr IndexItem::create(const QString &fileName, int sizeHint)
|
|||||||
{
|
{
|
||||||
Ptr ptr(new IndexItem);
|
Ptr ptr(new IndexItem);
|
||||||
|
|
||||||
ptr->m_fileName = fileName;
|
ptr->m_filePath = FilePath::fromString(fileName);
|
||||||
ptr->m_type = Declaration;
|
ptr->m_type = Declaration;
|
||||||
ptr->m_line = 0;
|
ptr->m_line = 0;
|
||||||
ptr->m_column = 0;
|
ptr->m_column = 0;
|
||||||
@@ -66,7 +66,7 @@ QString IndexItem::representDeclaration() const
|
|||||||
|
|
||||||
QString IndexItem::shortNativeFilePath() const
|
QString IndexItem::shortNativeFilePath() const
|
||||||
{
|
{
|
||||||
return Utils::FilePath::fromString(m_fileName).shortNativePath();
|
return m_filePath.shortNativePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexItem::squeeze()
|
void IndexItem::squeeze()
|
||||||
@@ -76,4 +76,4 @@ void IndexItem::squeeze()
|
|||||||
m_children[i]->squeeze();
|
m_children[i]->squeeze();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // CppEditor namespace
|
} // CppEditor
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "cppeditor_global.h"
|
#include "cppeditor_global.h"
|
||||||
|
|
||||||
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
@@ -57,7 +59,7 @@ public:
|
|||||||
QString symbolName() const { return m_symbolName; }
|
QString symbolName() const { return m_symbolName; }
|
||||||
QString symbolType() const { return m_symbolType; }
|
QString symbolType() const { return m_symbolType; }
|
||||||
QString symbolScope() const { return m_symbolScope; }
|
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; }
|
QIcon icon() const { return m_icon; }
|
||||||
ItemType type() const { return m_type; }
|
ItemType type() const { return m_type; }
|
||||||
int line() const { return m_line; }
|
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_symbolName; // as found in the code, therefore might be qualified
|
||||||
QString m_symbolType;
|
QString m_symbolType;
|
||||||
QString m_symbolScope;
|
QString m_symbolScope;
|
||||||
QString m_fileName;
|
Utils::FilePath m_filePath;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
ItemType m_type = All;
|
ItemType m_type = All;
|
||||||
int m_line = 0;
|
int m_line = 0;
|
||||||
|
@@ -46,7 +46,7 @@ IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope
|
|||||||
|
|
||||||
QTC_ASSERT(_parent, return IndexItem::Ptr());
|
QTC_ASSERT(_parent, return IndexItem::Ptr());
|
||||||
QTC_ASSERT(root, 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());
|
return IndexItem::Ptr());
|
||||||
|
|
||||||
for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)
|
for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)
|
||||||
|
@@ -154,9 +154,7 @@ void SymbolsFindFilter::openEditor(const SearchResultItem &item)
|
|||||||
if (!item.userData().canConvert<IndexItem::Ptr>())
|
if (!item.userData().canConvert<IndexItem::Ptr>())
|
||||||
return;
|
return;
|
||||||
IndexItem::Ptr info = item.userData().value<IndexItem::Ptr>();
|
IndexItem::Ptr info = item.userData().value<IndexItem::Ptr>();
|
||||||
EditorManager::openEditorAt({FilePath::fromString(info->fileName()),
|
EditorManager::openEditorAt({info->filePath(), info->line(), info->column()},
|
||||||
info->line(),
|
|
||||||
info->column()},
|
|
||||||
{},
|
{},
|
||||||
Core::EditorManager::AllowExternalEditor);
|
Core::EditorManager::AllowExternalEditor);
|
||||||
}
|
}
|
||||||
|
@@ -136,7 +136,7 @@ void ElementTasks::openClassDefinition(const qmt::MElement *element)
|
|||||||
if (info->scopedSymbolName() != qualifiedClassName)
|
if (info->scopedSymbolName() != qualifiedClassName)
|
||||||
continue;
|
continue;
|
||||||
if (Core::EditorManager::instance()->openEditorAt(
|
if (Core::EditorManager::instance()->openEditorAt(
|
||||||
{Utils::FilePath::fromString(info->fileName()), info->line(), info->column()})) {
|
{info->filePath(), info->line(), info->column()})) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user