This commit is contained in:
Jan Jurzitza 2023-01-26 16:26:30 +01:00 committed by GitHub
commit 79921d6855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 11 deletions

View File

@ -1097,6 +1097,7 @@ private:
DSymbol* acSymbol = GCAllocator.instance.make!DSymbol(istring(name), kind); DSymbol* acSymbol = GCAllocator.instance.make!DSymbol(istring(name), kind);
acSymbol.location = location; acSymbol.location = location;
acSymbol.symbolFile = symbolFile; acSymbol.symbolFile = symbolFile;
acSymbol.callTip = istring(name);
symbolsAllocated++; symbolsAllocated++;
return GCAllocator.instance.make!SemanticSymbol(acSymbol); return GCAllocator.instance.make!SemanticSymbol(acSymbol);
} }
@ -1126,9 +1127,7 @@ private:
foreach (suffix; type.typeSuffixes) foreach (suffix; type.typeSuffixes)
{ {
if (suffix.star != tok!"") if (suffix.type)
continue;
else if (suffix.type)
lookup.breadcrumbs.insert(ASSOC_ARRAY_SYMBOL_NAME); lookup.breadcrumbs.insert(ASSOC_ARRAY_SYMBOL_NAME);
else if (suffix.array) else if (suffix.array)
lookup.breadcrumbs.insert(ARRAY_SYMBOL_NAME); lookup.breadcrumbs.insert(ARRAY_SYMBOL_NAME);

View File

@ -174,19 +174,27 @@ do
// Create symbols for the type suffixes such as array and // Create symbols for the type suffixes such as array and
// associative array // associative array
// Build calltip, for the symbol
string callTip;
foreach (b; lookup.breadcrumbs[])
{
if (b == ARRAY_SYMBOL_NAME)
callTip ~= "[]";
else if (b == ASSOC_ARRAY_SYMBOL_NAME)
callTip ~= "[...]";
else
callTip ~= b;
}
while (!lookup.breadcrumbs.empty) while (!lookup.breadcrumbs.empty)
{ {
auto back = lookup.breadcrumbs.back; auto back = lookup.breadcrumbs.back;
immutable bool isArr = back == ARRAY_SYMBOL_NAME; immutable bool isArr = back == ARRAY_SYMBOL_NAME;
immutable bool isAssoc = back == ASSOC_ARRAY_SYMBOL_NAME; immutable bool isAssoc = back == ASSOC_ARRAY_SYMBOL_NAME;
immutable bool isFunction = back == FUNCTION_SYMBOL_NAME; immutable bool isFunction = back == FUNCTION_SYMBOL_NAME;
if (back == POINTER_SYMBOL_NAME) immutable bool isPointer = back == POINTER_SYMBOL_NAME;
{ if (!isArr && !isAssoc && !isFunction && !isPointer)
lastSuffix.isPointer = true;
lookup.breadcrumbs.popBack();
continue;
}
if (!isArr && !isAssoc && !isFunction)
break; break;
immutable qualifier = isAssoc ? SymbolQualifier.assocArray : immutable qualifier = isAssoc ? SymbolQualifier.assocArray :
(isFunction ? SymbolQualifier.func : SymbolQualifier.array); (isFunction ? SymbolQualifier.func : SymbolQualifier.array);
@ -198,8 +206,16 @@ do
lookup.breadcrumbs.popBack(); lookup.breadcrumbs.popBack();
lastSuffix.callTip = lookup.breadcrumbs.back(); lastSuffix.callTip = lookup.breadcrumbs.back();
} }
else if (isPointer)
{
lastSuffix.callTip = istring(callTip);
lastSuffix.isPointer = true;
}
else else
{
lastSuffix.addChildren(isArr ? arraySymbols[] : assocArraySymbols[], false); lastSuffix.addChildren(isArr ? arraySymbols[] : assocArraySymbols[], false);
lastSuffix.callTip = istring(callTip);
}
if (suffix is null) if (suffix is null)
suffix = lastSuffix; suffix = lastSuffix;
@ -245,9 +261,27 @@ do
if (symbols.length > 0) if (symbols.length > 0)
currentSymbol = symbols[0]; currentSymbol = symbols[0];
else else
{
// we can't resolve the type, so it's either enum/auto or a template
// let's handle that
// if there was known suffix, it's the type, use that
if (lastSuffix)
{
symbol.type = lastSuffix;
}
// other wise if the symbol has no type, then use the breadcrumb and make a symbol
// out of it, eg: 'T'
else if (!symbol.type)
{
symbol.type = GCAllocator.instance.make!DSymbol(part, CompletionKind.dummy, null);
symbol.ownType = true;
}
return; return;
} }
} }
}
else else
{ {
if (currentSymbol.kind == CompletionKind.aliasName) if (currentSymbol.kind == CompletionKind.aliasName)
@ -276,6 +310,65 @@ do
suffix.ownType = false; suffix.ownType = false;
symbol.type = lastSuffix; symbol.type = lastSuffix;
symbol.ownType = true; symbol.ownType = true;
// if that's a pointer, then add the symbols since we built a new one
if (lastSuffix.isPointer)
{
// add symbols based on what pointer is pointing to
bool isPtr = false;
bool ptrType = false;
bool ptrArray = false;
bool ptrAA = false;
auto index = callTip.length;
while(index--)
{
auto c = callTip[index];
if (c == '*')
isPtr = true;
else
{
if ((c == ')') && isPtr)
{
break;
}
else if (c == ']' && isPtr)
{
if (c > 1)
{
// TODO: if we ever put the length for static array
// this will need to be updated to support that
if(callTip[index -1] == '[')
{
ptrArray = true;
break;
}
// TODO: if we ever put the type name for AA
// this will need to be updated to support that
if(callTip[index -1] == '.')
{
ptrAA = true;
break;
}
}
}
else
{
ptrType = true;
break;
}
}
}
if (ptrType)
lastSuffix.addChildren(currentSymbol.parts[], false);
else if (ptrArray)
lastSuffix.addChildren(arraySymbols[], false);
else if (ptrAA)
lastSuffix.addChildren(assocArraySymbols[], false);
}
if (currentSymbol is null && !remainingImports.empty) if (currentSymbol is null && !remainingImports.empty)
{ {
// info("Deferring type resolution for ", symbol.name); // info("Deferring type resolution for ", symbol.name);

View File

@ -342,7 +342,7 @@ struct DSymbol
*/ */
alias PartsAllocator = GCAllocator; // NOTE using `Mallocator` here fails when analysing Phobos alias PartsAllocator = GCAllocator; // NOTE using `Mallocator` here fails when analysing Phobos
alias Parts = TTree!(SymbolOwnership, PartsAllocator, true, "a < b"); alias Parts = TTree!(SymbolOwnership, PartsAllocator, true, "a < b");
private Parts parts; package Parts parts;
/** /**
* DSymbol's name * DSymbol's name