diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-03-26 12:37:40 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-03-26 13:01:39 +0100 |
commit | 86e400c9dc6c5ab3a56f0c3608a6aa4a05e67099 (patch) | |
tree | b6222e710406e03a3a7f3b90ad206385a93601bc /src/libs/cplusplus/ExpressionUnderCursor.cpp | |
parent | 208adbaacae89c50913dbba5901cd255725a6091 (diff) | |
download | qt-creator-86e400c9dc6c5ab3a56f0c3608a6aa4a05e67099.tar.gz |
Trigger function argument widget on comma
Done with Roberto Raggi.
Diffstat (limited to 'src/libs/cplusplus/ExpressionUnderCursor.cpp')
-rw-r--r-- | src/libs/cplusplus/ExpressionUnderCursor.cpp | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/src/libs/cplusplus/ExpressionUnderCursor.cpp b/src/libs/cplusplus/ExpressionUnderCursor.cpp index 257d14443e..9cbaeb9753 100644 --- a/src/libs/cplusplus/ExpressionUnderCursor.cpp +++ b/src/libs/cplusplus/ExpressionUnderCursor.cpp @@ -190,7 +190,10 @@ int ExpressionUnderCursor::previousBlockState(const QTextBlock &block) return 0; } -QString ExpressionUnderCursor::operator()(const QTextCursor &cursor) +void ExpressionUnderCursor::init(const QTextCursor &cursor, + QList<SimpleToken> *tokens, + QString *text, + int *startPosition) { enum { MAX_BLOCK_COUNT = 5 }; @@ -203,8 +206,6 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor) initialBlock = initialBlock.previous(); } - QString text; - QTextBlock it = initialBlock; for (; it.isValid(); it = it.next()) { QString textBlock = it.text(); @@ -212,18 +213,29 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor) if (it == block) textBlock = textBlock.left(cursor.position() - cursor.block().position()); - text += textBlock; + text->append(textBlock); if (it == block) break; - text += QLatin1Char('\n'); + text->append(QLatin1Char('\n')); } SimpleLexer tokenize; tokenize.setSkipComments(true); - QList<SimpleToken> tokens = tokenize(text, previousBlockState(initialBlock)); - tokens.prepend(SimpleToken()); // sentinel + tokens->append(tokenize(*text, previousBlockState(initialBlock))); + tokens->prepend(SimpleToken()); // sentinel + + if (startPosition) + *startPosition = initialBlock.position(); +} + +QString ExpressionUnderCursor::operator()(const QTextCursor &cursor) +{ + QList<SimpleToken> tokens; + QString text; + + init(cursor, &tokens, &text); _jumpedComma = false; @@ -236,3 +248,28 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor) - tokens.at(i).position()); } +int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) +{ + QList<SimpleToken> tokens; + QString text; + int startPosition; + + init(cursor, &tokens, &text, &startPosition); + + int index = tokens.size(); + + forever { + const SimpleToken &tk = tokens.at(index - 1); + + if (tk.is(T_EOF_SYMBOL)) + break; + else if (tk.is(T_LPAREN)) + return startPosition + tk.position(); + else if (tk.is(T_RPAREN)) + index = startOfMatchingBrace(tokens, index); + else + --index; + } + + return -1; +} |