forked from qt-creator/qt-creator
qmljs: avoid linking to files in the build directory
cmake creates a consistent uri structure in the build directory. We use that as import path, but when we find a type in them we should refer back to the original file, as editing those is dangerous because any edit are lost with the next build. To find the original file we use the qrc, as the qrc path is mostly the same of as the uri path. It is possible to add prefixes which would make an exact match fail, so we compare the paths from the right to the left and find the longest match. To acheive this: * QrcParser keeps a reversedResources, so the match from right can be done efficiently, and provides a longestReverseMatches method * the model manager keeps a list of all common prefixes of the application paths (build directories), and identify all files in build directories * the method fileToSource identifies the files in the build directory and tries to find the corresponding source file, warning if he cannot find it * fileToSource is used for follow Symbol and find usages We could use fileToSource much more aggressively, to use to in editor content for the files in the build directory, increasing the consistency, but that is a more dangerous change for later. Fixes: QTCREATORBUG-27173 Change-Id: Iea61b9825e5f6e433a7390cf2de9564b792458a5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -28,10 +28,11 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <coreplugin/progressmanager/futureprogress.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <texteditor/basefilefind.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/filesearch.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
@@ -745,6 +746,7 @@ public:
|
||||
future->waitForResume();
|
||||
if (future->isCanceled())
|
||||
return usages;
|
||||
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
|
||||
Document::Ptr doc = context->snapshot().document(fileName);
|
||||
if (!doc)
|
||||
return usages;
|
||||
@@ -753,7 +755,7 @@ public:
|
||||
FindUsages findUsages(doc, context);
|
||||
const FindUsages::Result results = findUsages(name, scope);
|
||||
for (const SourceLocation &loc : results)
|
||||
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
usages.append(Usage(modelManager->fileToSource(Utils::FilePath::fromString(fileName)).toString(), matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
return usages;
|
||||
@@ -896,8 +898,9 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
|
||||
QStringList files;
|
||||
for (const Document::Ptr &doc : qAsConst(snapshot)) {
|
||||
// ### skip files that don't contain the name token
|
||||
files.append(doc->fileName());
|
||||
files.append(modelManager->fileToSource(Utils::FilePath::fromString(doc->fileName())).toString());
|
||||
}
|
||||
files = Utils::filteredUnique(files);
|
||||
|
||||
future.setProgressRange(0, files.size());
|
||||
|
||||
@@ -976,11 +979,23 @@ QList<FindReferences::Usage> FindReferences::findUsageOfType(const QString &file
|
||||
|
||||
QmlJS::Snapshot snapshot = modelManager->snapshot();
|
||||
|
||||
QSet<QString> docDone;
|
||||
for (const QmlJS::Document::Ptr &doc : qAsConst(snapshot)) {
|
||||
FindTypeUsages findUsages(doc, context);
|
||||
QString sourceFile = modelManager->fileToSource(Utils::FilePath::fromString(doc->fileName())).toString();
|
||||
if (docDone.contains(sourceFile))
|
||||
continue;
|
||||
docDone.insert(sourceFile);
|
||||
QmlJS::Document::Ptr sourceDoc = doc;
|
||||
if (sourceFile != doc->fileName())
|
||||
sourceDoc = snapshot.document(sourceFile);
|
||||
FindTypeUsages findUsages(sourceDoc, context);
|
||||
const FindTypeUsages::Result results = findUsages(typeName, targetValue);
|
||||
for (const SourceLocation &loc : results) {
|
||||
usages.append(Usage(doc->fileName(), matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
|
||||
usages.append(Usage(sourceFile,
|
||||
matchingLine(loc.offset, doc->source()),
|
||||
loc.startLine,
|
||||
loc.startColumn - 1,
|
||||
loc.length));
|
||||
}
|
||||
}
|
||||
return usages;
|
||||
|
||||
Reference in New Issue
Block a user