From b4fc380af5e390ca11892f9e657e653f6869c21b Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 3 Jul 2025 15:20:23 -0700 Subject: Language Server Enhancements (#7604) * Language Server: auto-select the best candidate in signature help. * Fix constructor call highlighting + goto definition. * Add test. * format code * Improve ctor signature help. * Add tests. * Fix decl path printing for extension children. * Allow goto definition to show core module source. * c++ compile fix. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-check-overload.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-check-overload.cpp') diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 6c0a7f184..41aba2674 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -2249,6 +2249,24 @@ DeclRef SemanticsVisitor::inferGenericArguments( return trySolveConstraintSystem(&constraints, genericDeclRef, knownGenericArgs, outBaseCost); } +LookupResult SemanticsVisitor::lookupConstructorsInType(Type* type, Scope* sourceScope) +{ + // Look up all the initializers on `type` by looking up + // its members named `$init`. All `__init` declarations are stored + // with the name `$init` internally to avoid potential conflicts + // if a user decided to name a field/method `__init`. + LookupOptions options = + LookupOptions(uint8_t(LookupOptions::IgnoreInheritance) | uint8_t(LookupOptions::NoDeref)); + return lookUpMember( + m_astBuilder, + this, + getName("$init"), + type, + sourceScope, + LookupMask::Default, + options); +} + void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveContext& context) { // The code being checked is trying to apply `type` like a function. @@ -2272,16 +2290,7 @@ void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveCont // from a value of the same type. There is no need in Slang for // "copy constructors" but the core module currently has to define // some just to make code that does, e.g., `float(1.0f)` work.) - LookupOptions options = - LookupOptions(uint8_t(LookupOptions::IgnoreInheritance) | uint8_t(LookupOptions::NoDeref)); - LookupResult initializers = lookUpMember( - m_astBuilder, - this, - getName("$init"), - type, - context.sourceScope, - LookupMask::Default, - options); + LookupResult initializers = lookupConstructorsInType(type, context.sourceScope); AddOverloadCandidates(initializers, context); } @@ -2702,6 +2711,12 @@ Expr* SemanticsVisitor::ResolveInvoke(InvokeExpr* expr) expr->arguments[0], &tempSink, &conversionCost); + if (auto resultInvokeExpr = as(resultExpr)) + { + resultInvokeExpr->originalFunctionExpr = expr->functionExpr; + resultInvokeExpr->argumentDelimeterLocs = expr->argumentDelimeterLocs; + resultInvokeExpr->loc = expr->loc; + } if (coerceResult) return resultExpr; typeOverloadChecked = true; -- cgit v1.2.3