Changeset View
Changeset View
Standalone View
Standalone View
codecompletion/items/functiondeclaration.cpp
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | |||||
132 | { | 132 | { | ||
133 | m_doNotCall = doNotCall; | 133 | m_doNotCall = doNotCall; | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | void FunctionDeclarationCompletionItem::executed(KTextEditor::View* view, const KTextEditor::Range& word) | 136 | void FunctionDeclarationCompletionItem::executed(KTextEditor::View* view, const KTextEditor::Range& word) | ||
137 | { | 137 | { | ||
138 | qCDebug(KDEV_PYTHON_CODECOMPLETION) << "FunctionDeclarationCompletionItem executed"; | 138 | qCDebug(KDEV_PYTHON_CODECOMPLETION) << "FunctionDeclarationCompletionItem executed"; | ||
139 | KTextEditor::Document* document = view->document(); | 139 | KTextEditor::Document* document = view->document(); | ||
140 | DeclarationPointer resolvedDecl(Helper::resolveAliasDeclaration(declaration().data())); | 140 | auto resolvedDecl = Helper::resolveAliasDeclaration(declaration().data()); | ||
141 | DUChainReadLocker lock; | 141 | DUChainReadLocker lock; | ||
142 | QPair<FunctionDeclarationPointer, bool> fdecl = Helper::functionDeclarationForCalledDeclaration(resolvedDecl); | 142 | auto functionDecl = Helper::functionForCalled(resolvedDecl).declaration; | ||
143 | lock.unlock(); | 143 | lock.unlock(); | ||
144 | if ( ! fdecl.first && (! resolvedDecl || ! resolvedDecl->abstractType() | 144 | if ( ! functionDecl && (! resolvedDecl || ! resolvedDecl->abstractType() | ||
145 | || resolvedDecl->abstractType()->whichType() != AbstractType::TypeStructure) ) { | 145 | || resolvedDecl->abstractType()->whichType() != AbstractType::TypeStructure) ) { | ||
146 | qCritical(KDEV_PYTHON_CODECOMPLETION) << "ERROR: could not get declaration data, not executing completion item!"; | 146 | qCritical(KDEV_PYTHON_CODECOMPLETION) << "ERROR: could not get declaration data, not executing completion item!"; | ||
147 | return; | 147 | return; | ||
148 | } | 148 | } | ||
149 | QString suffix = "()"; | 149 | QString suffix = "()"; | ||
150 | KTextEditor::Range checkPrefix(word.start().line(), 0, word.start().line(), word.start().column()); | 150 | KTextEditor::Range checkPrefix(word.start().line(), 0, word.start().line(), word.start().column()); | ||
151 | KTextEditor::Range checkSuffix(word.end().line(), word.end().column(), word.end().line(), document->lineLength(word.end().line())); | 151 | KTextEditor::Range checkSuffix(word.end().line(), word.end().column(), word.end().line(), document->lineLength(word.end().line())); | ||
152 | if ( m_doNotCall || document->text(checkSuffix).trimmed().startsWith('(') | 152 | if ( m_doNotCall || document->text(checkSuffix).trimmed().startsWith('(') | ||
153 | || document->text(checkPrefix).trimmed().endsWith('@') | 153 | || document->text(checkPrefix).trimmed().endsWith('@') | ||
154 | || (fdecl.first && Helper::findDecoratorByName(fdecl.first.data(), QLatin1String("property"))) ) | 154 | || (functionDecl && Helper::findDecoratorByName(functionDecl, QLatin1String("property"))) ) | ||
155 | { | 155 | { | ||
156 | // don't insert brackets if they're already there, | 156 | // don't insert brackets if they're already there, | ||
157 | // the item is a decorator, or if it's an import item. | 157 | // the item is a decorator, or if it's an import item. | ||
158 | suffix.clear(); | 158 | suffix.clear(); | ||
159 | } | 159 | } | ||
160 | // place cursor behind bracktes by default | 160 | // place cursor behind bracktes by default | ||
161 | int skip = 2; | 161 | int skip = 2; | ||
162 | if ( fdecl.first ) { | 162 | if ( functionDecl ) { | ||
163 | bool needsArguments = false; | 163 | bool needsArguments = false; | ||
164 | int argumentCount = fdecl.first->type<FunctionType>()->arguments().length(); | 164 | int argumentCount = functionDecl->type<FunctionType>()->arguments().length(); | ||
165 | if ( fdecl.first->context()->type() == KDevelop::DUContext::Class ) { | 165 | if ( functionDecl->context()->type() == KDevelop::DUContext::Class ) { | ||
166 | // it's a member function, so it has the implicit self | 166 | // it's a member function, so it has the implicit self | ||
167 | // TODO static methods | 167 | // TODO static methods | ||
168 | needsArguments = argumentCount > 1; | 168 | needsArguments = argumentCount > 1; | ||
169 | } | 169 | } | ||
170 | else { | 170 | else { | ||
171 | // it's a free function | 171 | // it's a free function | ||
172 | needsArguments = argumentCount > 0; | 172 | needsArguments = argumentCount > 0; | ||
173 | } | 173 | } | ||
Show All 12 Lines |