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
460c47f5
Commit
460c47f5
authored
Feb 01, 2010
by
Roberto Raggi
Browse files
Introduced SemanticInfo::declaringMember(pos).
parent
d533958a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmljseditor/qmlcodecompletion.cpp
View file @
460c47f5
...
...
@@ -637,19 +637,7 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
Interpreter
::
ObjectValue
*
scope
=
interp
.
globalObject
();
if
(
isQmlFile
)
{
AST
::
UiObjectMember
*
declaringMember
=
0
;
const
int
cursorPosition
=
editor
->
position
();
for
(
int
i
=
semanticInfo
.
ranges
.
size
()
-
1
;
i
!=
-
1
;
--
i
)
{
const
Range
&
range
=
semanticInfo
.
ranges
.
at
(
i
);
if
(
range
.
begin
.
isNull
()
||
range
.
end
.
isNull
())
{
continue
;
}
else
if
(
cursorPosition
>=
range
.
begin
.
position
()
&&
cursorPosition
<=
range
.
end
.
position
())
{
declaringMember
=
range
.
ast
;
break
;
}
}
AST
::
UiObjectMember
*
declaringMember
=
semanticInfo
.
declaringMember
(
editor
->
position
());
scope
=
Bind
::
scopeChainAt
(
qmlDocument
,
snapshot
,
&
interp
,
declaringMember
);
}
...
...
src/plugins/qmljseditor/qmljseditor.cpp
View file @
460c47f5
...
...
@@ -33,14 +33,14 @@
#include
"qmljseditorplugin.h"
#include
"qmlmodelmanager.h"
#include
"qmlexpressionundercursor.h"
#include
<qmljs/qmljsindenter.h>
#include
<qmljs/qmljsinterpreter.h>
#include
<qmljs/qmljsbind.h>
#include
<qmljs/qmljscheck.h>
#include
<qmljs/qmljsdocument.h>
#include
<qmljs/parser/qmljsastvisitor_p.h>
#include
<qmljs/parser/qmljsast_p.h>
#include
<qmljs/parser/qmljsengine_p.h>
#include
<qmljs/qmljsdocument.h>
#include
<coreplugin/actionmanager/actionmanager.h>
#include
<coreplugin/icore.h>
...
...
@@ -424,9 +424,63 @@ protected:
}
};
class
CollectASTNodes
:
protected
AST
::
Visitor
{
public:
QList
<
AST
::
UiQualifiedId
*>
qualifiedIds
;
QList
<
AST
::
IdentifierExpression
*>
identifiers
;
QList
<
AST
::
FieldMemberExpression
*>
fieldMembers
;
void
accept
(
AST
::
Node
*
node
)
{
if
(
node
)
node
->
accept
(
this
);
}
protected:
using
AST
::
Visitor
::
visit
;
virtual
bool
visit
(
AST
::
UiQualifiedId
*
ast
)
{
qualifiedIds
.
append
(
ast
);
return
false
;
}
virtual
bool
visit
(
AST
::
IdentifierExpression
*
ast
)
{
identifiers
.
append
(
ast
);
return
false
;
}
virtual
bool
visit
(
AST
::
FieldMemberExpression
*
ast
)
{
fieldMembers
.
append
(
ast
);
return
true
;
}
};
}
// end of anonymous namespace
AST
::
UiObjectMember
*
SemanticInfo
::
declaringMember
(
int
cursorPosition
)
const
{
AST
::
UiObjectMember
*
declaringMember
=
0
;
for
(
int
i
=
ranges
.
size
()
-
1
;
i
!=
-
1
;
--
i
)
{
const
Range
&
range
=
ranges
.
at
(
i
);
if
(
range
.
begin
.
isNull
()
||
range
.
end
.
isNull
())
{
continue
;
}
else
if
(
cursorPosition
>=
range
.
begin
.
position
()
&&
cursorPosition
<=
range
.
end
.
position
())
{
declaringMember
=
range
.
ast
;
break
;
}
}
return
declaringMember
;
}
int
SemanticInfo
::
revision
()
const
{
if
(
document
)
...
...
@@ -538,6 +592,7 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
// create the ranges and update the semantic info.
CreateRanges
createRanges
;
SemanticInfo
sem
;
sem
.
snapshot
=
m_modelManager
->
snapshot
();
sem
.
document
=
doc
;
sem
.
ranges
=
createRanges
(
document
(),
doc
);
...
...
@@ -780,41 +835,6 @@ void QmlJSTextEditor::createToolBar(QmlJSEditorEditable *editable)
TextEditor
::
BaseTextEditor
::
Link
QmlJSTextEditor
::
findLinkAt
(
const
QTextCursor
&
cursor
,
bool
/*resolveTarget*/
)
{
Link
link
;
if
(
!
m_modelManager
)
return
link
;
const
Snapshot
snapshot
=
m_modelManager
->
snapshot
();
Document
::
Ptr
doc
=
snapshot
.
document
(
file
()
->
fileName
());
if
(
!
doc
)
return
link
;
QTextCursor
expressionCursor
(
cursor
);
{
// correct the position by moving to the end of an identifier (if we're hovering over one):
int
pos
=
cursor
.
position
();
forever
{
const
QChar
ch
=
characterAt
(
pos
);
if
(
ch
.
isLetterOrNumber
()
||
ch
==
QLatin1Char
(
'_'
))
++
pos
;
else
break
;
}
expressionCursor
.
setPosition
(
pos
);
}
QmlExpressionUnderCursor
expressionUnderCursor
;
if
(
expressionUnderCursor
(
expressionCursor
))
{
link
.
pos
=
expressionUnderCursor
.
expressionOffset
();
link
.
length
=
expressionUnderCursor
.
expressionLength
();
// link.fileName = target->fileName();
// link.line = target->line();
// link.column = target->column();
// if (link.column > 0)
// --link.column;
}
return
link
;
}
...
...
src/plugins/qmljseditor/qmljseditor.h
View file @
460c47f5
...
...
@@ -105,8 +105,12 @@ public:
int
revision
()
const
;
// Returns the declaring member
QmlJS
::
AST
::
UiObjectMember
*
declaringMember
(
int
cursorPosition
)
const
;
public:
// attributes
QmlJS
::
Document
::
Ptr
document
;
QmlJS
::
Snapshot
snapshot
;
QList
<
Range
>
ranges
;
QHash
<
QString
,
QList
<
QmlJS
::
AST
::
SourceLocation
>
>
idLocations
;
QList
<
Declaration
>
declarations
;
...
...
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