From c419dbe193892d5d29ccf74c7a0220a20c2ce671 Mon Sep 17 00:00:00 2001 From: RUSshy <18348637+RUSshy@users.noreply.github.com> Date: Tue, 31 Aug 2021 14:41:19 +0200 Subject: [PATCH] Get type's symbol recursively to handle cases with auto as variable --- src/dcd/server/autocomplete/util.d | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dcd/server/autocomplete/util.d b/src/dcd/server/autocomplete/util.d index 9bc6439..73eb545 100644 --- a/src/dcd/server/autocomplete/util.d +++ b/src/dcd/server/autocomplete/util.d @@ -757,7 +757,23 @@ AutocompleteResponse.Completion makeSymbolCompletionInfo(const DSymbol* symbol, { string definition; if ((kind == CompletionKind.variableName || kind == CompletionKind.memberVariableName) && symbol.type) - definition = symbol.type.name ~ ' ' ~ symbol.name; + { + DSymbol* s = cast(DSymbol*)symbol; + + // if using auto as variable declaration, then the type will be the function name + // so let's get what the function symbol points to to get the actual type + // + // MyData myfunction() {} + // auto data = myfunction(); <-- this gives 'myfunction' as type + // + // with this recurtion we now get the proper type: 'MyData' + // + // TODO: should probably move it at the call site + // TODO: should probably make it fully recursive, + if(s.type) s = s.type; + + definition = s.type.name ~ ' ' ~ s.name; + } else if (kind == CompletionKind.enumMember) definition = symbol.name; // TODO: add enum value to definition string else