Skip to content

[code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range #6087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,6 @@ class CodeCompletionExpr : public Expr {
Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Ty),
Range(Range) {}

CodeCompletionExpr(CharSourceRange Range, Type Ty = Type()) :
Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Ty),
Range(SourceRange(Range.getStart(), Range.getEnd())) {}

SourceRange getSourceRange() const { return Range; }

static bool classof(const Expr *E) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
#include "swift/Parse/Tokens.def"

case tok::code_complete:
Result = makeParserResult(new (Context) CodeCompletionExpr(Tok.getRange()));
Result = makeParserResult(new (Context) CodeCompletionExpr(Tok.getLoc()));
Result.setHasCodeCompletion();
if (CodeCompletion &&
// We cannot code complete anything after var/let.
Expand Down Expand Up @@ -2747,7 +2747,7 @@ Parser::parseExprCallSuffix(ParserResult<Expr> fn, bool isExprBasic) {
// callback.
if (peekToken().is(tok::code_complete) && CodeCompletion) {
consumeToken(tok::l_paren);
auto CCE = new (Context) CodeCompletionExpr(Tok.getRange());
auto CCE = new (Context) CodeCompletionExpr(Tok.getLoc());
auto Result = makeParserResult(
CallExpr::create(Context, fn.get(), SourceLoc(),
{ CCE },
Expand Down
4 changes: 3 additions & 1 deletion lib/Parse/ParsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,9 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
if (!Ty.isNull()) {
// Attempt to diagnose initializer calls incorrectly written
// as typed patterns, such as "var x: [Int]()".
if (Tok.isFollowingLParen()) {
// Disable this tentative parse when in code-completion mode, otherwise
// code-completion may enter the delayed-decl state twice.
if (Tok.isFollowingLParen() && !L->isCodeCompletion()) {
BacktrackingScope backtrack(*this);

// Create a local context if needed so we can parse trailing closures.
Expand Down
5 changes: 2 additions & 3 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,10 +1224,9 @@ ParserStatus Parser::parseStmtCondition(StmtCondition &Condition,

// Handle code completion after the #.
if (Tok.is(tok::pound) && peekToken().is(tok::code_complete)) {
auto PoundPos = consumeToken();
consumeToken(); // '#' token.
auto CodeCompletionPos = consumeToken();
auto Expr = new (Context) CodeCompletionExpr(CharSourceRange(SourceMgr,
PoundPos, CodeCompletionPos));
auto Expr = new (Context) CodeCompletionExpr(CodeCompletionPos);
if (CodeCompletion)
CodeCompletion->completeAfterPound(Expr, ParentKind);
result.push_back(Expr);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
let:n(f{var _=#^A^#
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
{let:e(var d#^A^#