support `.Type` syntax for module type lookup

This commit is contained in:
WebFreak001 2023-12-04 12:45:04 +01:00 committed by Jan Jurzitza
parent dcffd378e1
commit 584b245c8b
5 changed files with 32 additions and 1 deletions

View File

@ -27,6 +27,15 @@ package istring[24] builtinTypeNames;
* or the child type for single index access. * or the child type for single index access.
*/ */
@("*arr*") istring ARRAY_SYMBOL_NAME; @("*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. * Type suffix, in breadcrumbs this is a single entry.
* *

View File

@ -1358,6 +1358,10 @@ void writeIotcTo(T)(const TypeIdentifierPart tip, ref T output) nothrow
{ {
if (!tip.identifierOrTemplateInstance) if (!tip.identifierOrTemplateInstance)
return; return;
if (tip.dot)
output.insert(MODULE_SYMBOL_NAME);
if (tip.identifierOrTemplateInstance.identifier != tok!"") if (tip.identifierOrTemplateInstance.identifier != tok!"")
output.insert(internString(tip.identifierOrTemplateInstance.identifier.text)); output.insert(internString(tip.identifierOrTemplateInstance.identifier.text));
else else

View File

@ -263,7 +263,14 @@ do
getSymbolFromImports(imports, part); getSymbolFromImports(imports, part);
else 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) if (symbols.length > 0)
currentSymbol = symbols[0]; currentSymbol = symbols[0];
else else

View File

@ -24,3 +24,11 @@ unittest
auto from_cast = cast(A.B.C) nonExist; auto from_cast = cast(A.B.C) nonExist;
from_cast. from_cast.
} }
unittest
{
struct A {}
auto from_cast = cast(.A.B.C) nonExist;
from_cast.
}

View File

@ -6,3 +6,6 @@ diff actual1.txt expected1.txt --strip-trailing-cr
../../bin/dcd-client $1 file.d -c239 > actual2.txt ../../bin/dcd-client $1 file.d -c239 > actual2.txt
diff actual2.txt expected2.txt --strip-trailing-cr 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