From b7638b8fffe78ade657f361cadc08dffc8c10acf Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 27 Jun 2022 15:36:00 -0700 Subject: Language server fixes and improvements (#2304) * Language server: Inlay hints. * Signature help for base exprs that is not a declref. * Fix checking of jvp operator. * Fix. * Add clang-format based auto formatting. * Fix clang error. * Fix clang-format discovery logic. * Fine tune auto formatting and completion experience. * Update macos workflow. * Fixes to configurations. * Fix parser recovery to trigger completion for index exprs. * Typo fix. Co-authored-by: Yong He --- source/slang/slang-parser.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index d168bf55c..a2a249f7e 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -98,6 +98,8 @@ namespace Slang Scope* outerScope = nullptr; Scope* currentScope = nullptr; + bool hasSeenCompletionToken = false; + TokenReader tokenReader; DiagnosticSink* sink; SourceLoc lastErrorLoc; @@ -1126,6 +1128,8 @@ namespace Slang static NameLoc expectIdentifier(Parser* parser) { + if (!parser->hasSeenCompletionToken && parser->LookAheadToken(TokenType::CompletionRequest)) + parser->hasSeenCompletionToken = true; return NameLoc(parser->ReadToken(TokenType::Identifier)); } @@ -4335,6 +4339,24 @@ namespace Slang // Expr* type = ParseType(); + if (type && hasSeenCompletionToken) + { + // If we encountered a completion token, just return the parsed expr + // as an ExprStmt. + for (auto tokenPos = startPos.tokenReaderCursor; + tokenPos && tokenPos < tokenReader.getCursor().tokenReaderCursor; + ++tokenPos) + { + if (tokenPos && tokenPos->type == TokenType::CompletionRequest) + { + auto exprStmt = astBuilder->create(); + exprStmt->loc = type->loc; + exprStmt->expression = type; + return exprStmt; + } + } + } + // We don't actually care about the type, though, so // don't retain it // @@ -5635,6 +5657,17 @@ namespace Slang return constExpr; } case TokenType::CompletionRequest: + { + VarExpr* varExpr = parser->astBuilder->create(); + varExpr->scope = parser->currentScope; + parser->FillPosition(varExpr); + auto nameAndLoc = NameLoc(peekToken(parser)); + varExpr->name = nameAndLoc.name; + parser->hasSeenCompletionToken = true; + // Don't consume the token, instead we skip directly. + parser->ReadToken(TokenType::Identifier); + return varExpr; + } case TokenType::Identifier: { // We will perform name lookup here so that we can find syntax -- cgit v1.2.3