Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
8519ca11
Commit
8519ca11
authored
Jul 16, 2010
by
Christian Kamm
Browse files
QmlJS: Allow 'follow symbol' to jump to the target of a file import.
Task-number: QTCREATORBUG-1736
parent
37efd0e1
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/libs/qmljs/qmljsbind.cpp
View file @
8519ca11
...
...
@@ -181,6 +181,7 @@ bool Bind::visit(AST::Program *)
bool
Bind
::
visit
(
UiImport
*
ast
)
{
ImportInfo
info
;
info
.
ast
=
ast
;
if
(
ast
->
versionToken
.
isValid
())
{
const
QString
versionString
=
_doc
->
source
().
mid
(
ast
->
versionToken
.
offset
,
ast
->
versionToken
.
length
);
...
...
src/libs/qmljs/qmljsbind.h
View file @
8519ca11
...
...
@@ -54,6 +54,7 @@ public:
struct
ImportInfo
{
QString
name
;
ComponentVersion
version
;
AST
::
UiImport
*
ast
;
};
QList
<
ImportInfo
>
fileImports
()
const
;
...
...
src/plugins/qmljseditor/qmljseditor.cpp
View file @
8519ca11
...
...
@@ -35,6 +35,7 @@
#include
"qmloutlinemodel.h"
#include
<qmljs/qmljsindenter.h>
#include
<qmljs/qmljsbind.h>
#include
<qmljs/qmljscheck.h>
#include
<qmljs/qmljsdocument.h>
#include
<qmljs/qmljsicontextpane.h>
...
...
@@ -525,6 +526,12 @@ QList<AST::Node *> SemanticInfo::astPath(int cursorPosition) const
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
{
if
(
!
document
)
...
...
@@ -532,6 +539,19 @@ AST::Node *SemanticInfo::nodeUnderCursor(int pos) const
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
;
nodes
.
accept
(
document
->
ast
());
...
...
@@ -1226,6 +1246,19 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
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
));
const
Interpreter
::
Value
*
value
=
lookupContext
->
evaluate
(
node
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment