Initial support of `Follow symbol under cursor' for QML/JS.

This commit is contained in:
Roberto Raggi
2010-02-08 12:50:10 +01:00
parent b02d2f9f00
commit 967ed09c29
10 changed files with 162 additions and 51 deletions

View File

@@ -910,10 +910,26 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
AST::Node *node = semanticInfo.nodeUnderCursor(cursorPosition);
Interpreter::Engine interp;
Interpreter::Context context(&interp);
context.build(semanticInfo.declaringMember(cursorPosition), semanticInfo.document, semanticInfo.snapshot);
Check check(&context);
const Interpreter::Value *value = check.reference(node);
QString fileName;
int line = 0, column = 0;
if (! (value && value->getSourceLocation(&fileName, &line, &column)))
return Link();
Link link;
link.fileName = fileName;
link.line = line;
link.column = column - 1; // adjust the column
if (AST::UiQualifiedId *q = AST::cast<AST::UiQualifiedId *>(node)) {
for (AST::UiQualifiedId *tail = q; tail; tail = tail->next) {
if (! tail->next && cursorPosition <= tail->identifierToken.end()) {
Link link;
link.begin = tail->identifierToken.begin();
link.end = tail->identifierToken.end();
return link;
@@ -921,13 +937,11 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
}
} else if (AST::IdentifierExpression *id = AST::cast<AST::IdentifierExpression *>(node)) {
Link link;
link.begin = id->firstSourceLocation().begin();
link.end = id->lastSourceLocation().end();
return link;
} else if (AST::FieldMemberExpression *mem = AST::cast<AST::FieldMemberExpression *>(node)) {
Link link;
link.begin = mem->lastSourceLocation().begin();
link.end = mem->lastSourceLocation().end();
return link;
@@ -936,6 +950,11 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
return Link();
}
void QmlJSTextEditor::followSymbolUnderCursor()
{
openLink(findLinkAt(textCursor()));
}
void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e)
{
QMenu *menu = new QMenu();