Commit d1fef743 authored by Denis Steckelmacher's avatar Denis Steckelmacher

Append brackets after JS function calls

When "item" is selected in the code-completion list, "item(|)" is inserted
into the document.
parent 53d74b38
......@@ -31,6 +31,7 @@
#include <language/duchain/types/structuretype.h>
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
using namespace QmlJS;
using namespace KDevelop;
......@@ -123,5 +124,12 @@ void CompletionItem::executed(KTextEditor::Document* document, const KTextEditor
case QmlJS::CompletionItem::Colon:
document->replaceText(word, base + ": ");
break;
case QmlJS::CompletionItem::Brackets:
document->replaceText(word, base + "()");
if (document->activeView()) {
document->activeView()->setCursorPosition(word.end() + KTextEditor::Cursor(0, 1));
}
}
}
......@@ -39,6 +39,7 @@ public:
Quotes, /*!< @brief Wrap the item in quotes: item becomes "item" */
QuotesAndBracket, /*!< @brief Wrap the item as in array subscripts: item becomes "item"] */
Colon, /*!< @brief Append a colon after the item: item becomes item: */
Brackets, /*!< @brief Append brackets after the item and put the cursor in-between them: item becomes item(|) */
};
CompletionItem(KDevelop::DeclarationPointer decl, int inheritanceDepth, Decoration decoration);
......
......@@ -121,6 +121,11 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::completionsInContext(con
continue;
} else if (declaration->qualifiedIdentifier().isEmpty()) {
continue;
} else if (decoration == CompletionItem::NoDecoration &&
declaration->abstractType() &&
declaration->abstractType()->whichType() == AbstractType::TypeFunction) {
// Decorate function calls with brackets
decoration = CompletionItem::Brackets;
} else if (flags.testFlag(CompletionHideWrappers)) {
ClassDeclaration* classDecl = dynamic_cast<ClassDeclaration*>(declaration.data());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment