From 584b245c8b7d4d8f12c2802b889cbb7321ad8fb0 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Mon, 4 Dec 2023 12:45:04 +0100 Subject: [PATCH] support `.Type` syntax for module type lookup --- dsymbol/src/dsymbol/builtin/names.d | 9 +++++++++ dsymbol/src/dsymbol/conversion/first.d | 4 ++++ dsymbol/src/dsymbol/conversion/second.d | 9 ++++++++- tests/tc_casts/file.d | 8 ++++++++ tests/tc_casts/run.sh | 3 +++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dsymbol/src/dsymbol/builtin/names.d b/dsymbol/src/dsymbol/builtin/names.d index 9b87334..5bd5fb4 100644 --- a/dsymbol/src/dsymbol/builtin/names.d +++ b/dsymbol/src/dsymbol/builtin/names.d @@ -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. * diff --git a/dsymbol/src/dsymbol/conversion/first.d b/dsymbol/src/dsymbol/conversion/first.d index 26f366f..6cad7ff 100644 --- a/dsymbol/src/dsymbol/conversion/first.d +++ b/dsymbol/src/dsymbol/conversion/first.d @@ -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 diff --git a/dsymbol/src/dsymbol/conversion/second.d b/dsymbol/src/dsymbol/conversion/second.d index d1220b0..bac4b50 100644 --- a/dsymbol/src/dsymbol/conversion/second.d +++ b/dsymbol/src/dsymbol/conversion/second.d @@ -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 diff --git a/tests/tc_casts/file.d b/tests/tc_casts/file.d index 3fa9bce..43834b1 100644 --- a/tests/tc_casts/file.d +++ b/tests/tc_casts/file.d @@ -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. +} diff --git a/tests/tc_casts/run.sh b/tests/tc_casts/run.sh index bacdbad..a45085f 100755 --- a/tests/tc_casts/run.sh +++ b/tests/tc_casts/run.sh @@ -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