diff options
| author | Yong He <yonghe@outlook.com> | 2022-06-27 15:36:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-27 15:36:00 -0700 |
| commit | b7638b8fffe78ade657f361cadc08dffc8c10acf (patch) | |
| tree | e27a141cfc6a9cc77356b8cba27b41c495d4ee27 /source/slang/slang-parser.cpp | |
| parent | 62d16a23b0ecd72dc624abd7e10b373c40adaa90 (diff) | |
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
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<ExpressionStmt>(); + 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>(); + 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 |
