Get type's symbol recursively to handle cases with auto as variable

This commit is contained in:
RUSshy 2021-08-31 14:41:19 +02:00 committed by GitHub
parent 02acaa534b
commit c419dbe193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -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