From 7f1df9d0b31413e59846cc955d2a955d3f361e2a Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 30 Apr 2025 14:17:45 -0700 Subject: Initial support for immutable lambda expressions. (#6914) * Initial support for immutable lambda expressions. * More diagnostics, and langauge server fix. * Language server fix. * Fix bug identified in review. * Add expected result. * Update expected result. --- source/slang/slang-language-server-ast-lookup.cpp | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'source/slang/slang-language-server-ast-lookup.cpp') diff --git a/source/slang/slang-language-server-ast-lookup.cpp b/source/slang/slang-language-server-ast-lookup.cpp index 7375756f5..b08388aee 100644 --- a/source/slang/slang-language-server-ast-lookup.cpp +++ b/source/slang/slang-language-server-ast-lookup.cpp @@ -62,9 +62,10 @@ static Index _getDeclNameLength(Name* name, Decl* optionalDecl = nullptr) return 0; } // HACK: our __subscript functions currently have a name "operator[]". + // and our operator() functions have a name "()". // Since this isn't the name that actually appears in user's code, // we need to shorten its reported length to 1 for now. - if (name->text.startsWith("operator")) + if (name->text.startsWith("operator") || name->text.startsWith("()")) { return 1; } @@ -75,7 +76,7 @@ bool _isLocInRange(ASTLookupContext* context, SourceLoc loc, Int length) { auto humaneLoc = context->sourceManager->getHumaneLoc(loc, SourceLocType::Actual); return humaneLoc.line == context->line && context->col >= humaneLoc.column && - context->col <= humaneLoc.column + length && + context->col < humaneLoc.column + length && humaneLoc.pathInfo.foundPath.getUnownedSlice().endsWithCaseInsensitive( context->sourceFileName); } @@ -87,7 +88,7 @@ bool _isLocInRange(ASTLookupContext* context, SourceLoc start, SourceLoc end) Loc s{startLoc.line, startLoc.column}; Loc e{endLoc.line, endLoc.column}; Loc c{context->line, context->col}; - return s <= c && c <= e && + return s <= c && c < e && startLoc.pathInfo.foundPath.getUnownedSlice().endsWithCaseInsensitive( context->sourceFileName); } @@ -667,17 +668,27 @@ bool _findAstNodeImpl(ASTLookupContext& context, SyntaxNode* node) { if (_isLocInRange(&context, decl->nameAndLoc.loc, _getDeclNameLength(decl->getName()))) { + bool isRealDeclName = true; for (auto modifier : decl->modifiers) { if (as(modifier)) - return false; + { + isRealDeclName = false; + break; + } if (as(modifier)) - return false; + { + isRealDeclName = false; + break; + } + } + if (isRealDeclName) + { + ASTLookupResult result; + result.path = context.nodePath; + context.results.add(_Move(result)); + return true; } - ASTLookupResult result; - result.path = context.nodePath; - context.results.add(_Move(result)); - return true; } } if (auto funcDecl = as(node)) -- cgit v1.2.3