forked from qt-creator/qt-creator
QmlJS: Allow 'follow symbol' to jump to the target of a file import.
Task-number: QTCREATORBUG-1736
This commit is contained in:
@@ -181,6 +181,7 @@ bool Bind::visit(AST::Program *)
|
|||||||
bool Bind::visit(UiImport *ast)
|
bool Bind::visit(UiImport *ast)
|
||||||
{
|
{
|
||||||
ImportInfo info;
|
ImportInfo info;
|
||||||
|
info.ast = ast;
|
||||||
|
|
||||||
if (ast->versionToken.isValid()) {
|
if (ast->versionToken.isValid()) {
|
||||||
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
|
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
|
||||||
|
@@ -54,6 +54,7 @@ public:
|
|||||||
struct ImportInfo {
|
struct ImportInfo {
|
||||||
QString name;
|
QString name;
|
||||||
ComponentVersion version;
|
ComponentVersion version;
|
||||||
|
AST::UiImport *ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<ImportInfo> fileImports() const;
|
QList<ImportInfo> fileImports() const;
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include "qmloutlinemodel.h"
|
#include "qmloutlinemodel.h"
|
||||||
|
|
||||||
#include <qmljs/qmljsindenter.h>
|
#include <qmljs/qmljsindenter.h>
|
||||||
|
#include <qmljs/qmljsbind.h>
|
||||||
#include <qmljs/qmljscheck.h>
|
#include <qmljs/qmljscheck.h>
|
||||||
#include <qmljs/qmljsdocument.h>
|
#include <qmljs/qmljsdocument.h>
|
||||||
#include <qmljs/qmljsicontextpane.h>
|
#include <qmljs/qmljsicontextpane.h>
|
||||||
@@ -525,6 +526,12 @@ QList<AST::Node *> SemanticInfo::astPath(int cursorPosition) const
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool importContainsCursor(UiImport *importAst, unsigned cursorPosition)
|
||||||
|
{
|
||||||
|
return cursorPosition >= importAst->firstSourceLocation().begin()
|
||||||
|
&& cursorPosition <= importAst->lastSourceLocation().end();
|
||||||
|
}
|
||||||
|
|
||||||
AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
|
AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
|
||||||
{
|
{
|
||||||
if (! document)
|
if (! document)
|
||||||
@@ -532,6 +539,19 @@ AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
|
|||||||
|
|
||||||
const unsigned cursorPosition = pos;
|
const unsigned cursorPosition = pos;
|
||||||
|
|
||||||
|
foreach (const Bind::ImportInfo &import, document->bind()->fileImports()) {
|
||||||
|
if (importContainsCursor(import.ast, cursorPosition))
|
||||||
|
return import.ast;
|
||||||
|
}
|
||||||
|
foreach (const Bind::ImportInfo &import, document->bind()->directoryImports()) {
|
||||||
|
if (importContainsCursor(import.ast, cursorPosition))
|
||||||
|
return import.ast;
|
||||||
|
}
|
||||||
|
foreach (const Bind::ImportInfo &import, document->bind()->libraryImports()) {
|
||||||
|
if (importContainsCursor(import.ast, cursorPosition))
|
||||||
|
return import.ast;
|
||||||
|
}
|
||||||
|
|
||||||
CollectASTNodes nodes;
|
CollectASTNodes nodes;
|
||||||
nodes.accept(document->ast());
|
nodes.accept(document->ast());
|
||||||
|
|
||||||
@@ -1226,6 +1246,19 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
|
|||||||
|
|
||||||
AST::Node *node = semanticInfo.nodeUnderCursor(cursorPosition);
|
AST::Node *node = semanticInfo.nodeUnderCursor(cursorPosition);
|
||||||
|
|
||||||
|
if (AST::UiImport *importAst = cast<AST::UiImport *>(node)) {
|
||||||
|
// if it's a file import, link to the file
|
||||||
|
foreach (const Bind::ImportInfo &import, semanticInfo.document->bind()->fileImports()) {
|
||||||
|
if (import.ast == importAst) {
|
||||||
|
BaseTextEditor::Link link(import.name);
|
||||||
|
link.begin = importAst->firstSourceLocation().begin();
|
||||||
|
link.end = importAst->lastSourceLocation().end();
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Link();
|
||||||
|
}
|
||||||
|
|
||||||
LookupContext::Ptr lookupContext = LookupContext::create(semanticInfo.document, semanticInfo.snapshot, semanticInfo.astPath(cursorPosition));
|
LookupContext::Ptr lookupContext = LookupContext::create(semanticInfo.document, semanticInfo.snapshot, semanticInfo.astPath(cursorPosition));
|
||||||
const Interpreter::Value *value = lookupContext->evaluate(node);
|
const Interpreter::Value *value = lookupContext->evaluate(node);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user