Skip to content

Commit

Permalink
support .Type syntax for module type lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Dec 4, 2023
1 parent dcffd37 commit 584b245
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions dsymbol/src/dsymbol/builtin/names.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ package istring[24] builtinTypeNames;
* or the child type for single index access.
*/
@("*arr*") istring ARRAY_SYMBOL_NAME;
/**
* In breadcrumbs this is a single entry meaning that the type following this
* started with a dot `.`, so module scope instead of local scope is to be used
* for type resolution.
*
* Note that auto-completion does not rely on this symbol, only type / symbol
* lookup relies on this.
*/
@("*arr*") istring MODULE_SYMBOL_NAME;
/**
* Type suffix, in breadcrumbs this is a single entry.
*
Expand Down
4 changes: 4 additions & 0 deletions dsymbol/src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,10 @@ void writeIotcTo(T)(const TypeIdentifierPart tip, ref T output) nothrow
{
if (!tip.identifierOrTemplateInstance)
return;

if (tip.dot)
output.insert(MODULE_SYMBOL_NAME);

if (tip.identifierOrTemplateInstance.identifier != tok!"")
output.insert(internString(tip.identifierOrTemplateInstance.identifier.text));
else
Expand Down
9 changes: 8 additions & 1 deletion dsymbol/src/dsymbol/conversion/second.d
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ do
getSymbolFromImports(imports, part);
else
{
auto symbols = moduleScope.getSymbolsByNameAndCursor(part, symbol.location);
auto symbols = part == MODULE_SYMBOL_NAME
? {
assert(!breadcrumbs.empty);
part = breadcrumbs.front;
breadcrumbs.popFront();
return moduleScope.getSymbolsByName(part);
}()
: moduleScope.getSymbolsByNameAndCursor(part, symbol.location);
if (symbols.length > 0)
currentSymbol = symbols[0];
else
Expand Down
8 changes: 8 additions & 0 deletions tests/tc_casts/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ unittest
auto from_cast = cast(A.B.C) nonExist;
from_cast.
}

unittest
{
struct A {}

auto from_cast = cast(.A.B.C) nonExist;
from_cast.
}
3 changes: 3 additions & 0 deletions tests/tc_casts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ diff actual1.txt expected1.txt --strip-trailing-cr

../../bin/dcd-client $1 file.d -c239 > actual2.txt
diff actual2.txt expected2.txt --strip-trailing-cr

../../bin/dcd-client $1 file.d -c320 > actual3.txt
diff actual3.txt expected1.txt --strip-trailing-cr

0 comments on commit 584b245

Please sign in to comment.