Changeset View
Changeset View
Standalone View
Standalone View
codecompletion/items/functionitem.cpp
Show All 16 Lines | |||||
17 | *************************************************************************************/ | 17 | *************************************************************************************/ | ||
18 | 18 | | |||
19 | #include "functionitem.h" | 19 | #include "functionitem.h" | ||
20 | 20 | | |||
21 | #include <KTextEditor/View> | 21 | #include <KTextEditor/View> | ||
22 | #include <KTextEditor/Document> | 22 | #include <KTextEditor/Document> | ||
23 | #include <language/duchain/declaration.h> | 23 | #include <language/duchain/declaration.h> | ||
24 | #include <language/codecompletion/codecompletionmodel.h> | 24 | #include <language/codecompletion/codecompletionmodel.h> | ||
25 | #include <language/duchain/duchainutils.h> | ||||
25 | 26 | | |||
26 | #include "types/gofunctiontype.h" | 27 | #include "types/gofunctiontype.h" | ||
27 | #include "declarations/functiondeclaration.h" | 28 | #include "declarations/functiondeclaration.h" | ||
28 | 29 | | |||
29 | namespace go | 30 | namespace go | ||
30 | { | 31 | { | ||
31 | 32 | | |||
32 | FunctionCompletionItem::FunctionCompletionItem(DeclarationPointer decl, int depth, int atArgument): | 33 | FunctionCompletionItem::FunctionCompletionItem(DeclarationPointer decl, int depth, int atArgument): | ||
33 | CompletionItem(decl, QExplicitlySharedDataPointer<KDevelop::CodeCompletionContext>(), 0), | 34 | CompletionItem(decl, QExplicitlySharedDataPointer<KDevelop::CodeCompletionContext>(), 0), | ||
34 | m_depth(depth), m_atArgument(atArgument) | 35 | m_depth(depth), m_atArgument(atArgument) | ||
35 | { | 36 | { | ||
36 | auto function = decl.dynamicCast<GoFunctionDeclaration>(); | 37 | auto function = decl.dynamicCast<GoFunctionDeclaration>(); | ||
37 | GoFunctionType::Ptr type(fastCast<GoFunctionType*>(decl->abstractType().constData())); | 38 | GoFunctionType::Ptr type(fastCast<GoFunctionType*>(decl->abstractType().constData())); | ||
38 | if(!type) | 39 | if(!type) | ||
39 | return; | 40 | return; | ||
40 | 41 | | |||
41 | bool variadicArgs = false; | 42 | bool variadicArgs = false; | ||
42 | if(type->modifiers() == go::GoFunctionType::VariadicArgument) | 43 | if(type->modifiers() == go::GoFunctionType::VariadicArgument) | ||
43 | variadicArgs = true; | 44 | variadicArgs = true; | ||
44 | 45 | | |||
45 | DUContext* argsContext = 0; | 46 | DUContext* argsContext = nullptr; | ||
46 | if(function) | 47 | if(function) | ||
47 | argsContext = function->internalContext(); | 48 | { | ||
49 | DUChainReadLocker lock; | ||||
50 | argsContext = DUChainUtils::getArgumentContext(function.data()); | ||||
brauch: use DUChainUtils::getArgumentContext | |||||
51 | } | ||||
48 | m_arguments = "("; | 52 | m_arguments = "("; | ||
49 | if(argsContext) | 53 | if(argsContext) | ||
50 | { | 54 | { | ||
51 | DUChainReadLocker lock; | 55 | DUChainReadLocker lock; | ||
52 | auto args = argsContext->allDeclarations(CursorInRevision::invalid(), decl->topContext(), false); | 56 | auto args = argsContext->allDeclarations(CursorInRevision::invalid(), decl->topContext(), false); | ||
53 | //highlight last argument if it is variadic | 57 | //highlight last argument if it is variadic | ||
54 | if(variadicArgs && m_atArgument >= args.size()) | 58 | if(variadicArgs && m_atArgument >= args.size()) | ||
55 | m_atArgument = args.size() - 1; | 59 | m_atArgument = args.size() - 1; | ||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |
use DUChainUtils::getArgumentContext