Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSymbol: RUSShyTwo: Properly construct a callTip for pointers and symbols with breadcrumbs (T, [], *, etc) #680

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions dsymbol/src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ private:
DSymbol* acSymbol = GCAllocator.instance.make!DSymbol(istring(name), kind);
acSymbol.location = location;
acSymbol.symbolFile = symbolFile;
acSymbol.callTip = istring(name);
symbolsAllocated++;
return GCAllocator.instance.make!SemanticSymbol(acSymbol);
}
Expand Down Expand Up @@ -1126,9 +1127,7 @@ private:

foreach (suffix; type.typeSuffixes)
{
if (suffix.star != tok!"")
continue;
else if (suffix.type)
if (suffix.type)
lookup.breadcrumbs.insert(ASSOC_ARRAY_SYMBOL_NAME);
else if (suffix.array)
lookup.breadcrumbs.insert(ARRAY_SYMBOL_NAME);
Expand Down
107 changes: 100 additions & 7 deletions dsymbol/src/dsymbol/conversion/second.d
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,27 @@ do

// Create symbols for the type suffixes such as array and
// 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)
{
auto back = lookup.breadcrumbs.back;
immutable bool isArr = back == ARRAY_SYMBOL_NAME;
immutable bool isAssoc = back == ASSOC_ARRAY_SYMBOL_NAME;
immutable bool isFunction = back == FUNCTION_SYMBOL_NAME;
if (back == POINTER_SYMBOL_NAME)
{
lastSuffix.isPointer = true;
lookup.breadcrumbs.popBack();
continue;
}
if (!isArr && !isAssoc && !isFunction)
immutable bool isPointer = back == POINTER_SYMBOL_NAME;
if (!isArr && !isAssoc && !isFunction && !isPointer)
break;
immutable qualifier = isAssoc ? SymbolQualifier.assocArray :
(isFunction ? SymbolQualifier.func : SymbolQualifier.array);
Expand All @@ -197,8 +205,16 @@ do
lookup.breadcrumbs.popBack();
lastSuffix.callTip = lookup.breadcrumbs.back();
}
else if (isPointer)
{
lastSuffix.callTip = istring(callTip);
lastSuffix.isPointer = true;
}
else
{
lastSuffix.addChildren(isArr ? arraySymbols[] : assocArraySymbols[], false);
lastSuffix.callTip = istring(callTip);
}

if (suffix is null)
suffix = lastSuffix;
Expand Down Expand Up @@ -244,7 +260,25 @@ do
if (symbols.length > 0)
currentSymbol = symbols[0];
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;
}
}
}
else
Expand Down Expand Up @@ -275,6 +309,65 @@ do
suffix.ownType = false;
symbol.type = lastSuffix;
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)
{
// info("Deferring type resolution for ", symbol.name);
Expand Down
2 changes: 1 addition & 1 deletion dsymbol/src/dsymbol/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ struct DSymbol
*/
alias PartsAllocator = GCAllocator; // NOTE using `Mallocator` here fails when analysing Phobos
alias Parts = TTree!(SymbolOwnership, PartsAllocator, true, "a < b");
private Parts parts;
package Parts parts;

/**
* DSymbol's name
Expand Down