Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 1128d18

Browse files
author
Mikhail Arkhipov
authored
Suppress completion after error tokens (#752)
* Fix #668 (partial) * Tests * Revert "Tests" This reverts commit 7ffc9db. * Suppress completion after error tokens
1 parent fe8383e commit 1128d18

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/LanguageServer/Impl/Completion/CompletionSource.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public CompletionResult GetCompletions(IDocumentAnalysis analysis, SourceLocatio
4040
// no completions on integer ., the user is typing a float
4141
return CompletionResult.Empty;
4242
case ConstantExpression ce2 when ce2.Value is string:
43-
// no completions in strings
43+
// no completions in strings
4444
case null when context.Ast.IsInsideComment(context.Location):
4545
case null when context.Ast.IsInsideString(context.Location):
4646
return CompletionResult.Empty;
@@ -82,10 +82,11 @@ public CompletionResult GetCompletions(IDocumentAnalysis analysis, SourceLocatio
8282
return result;
8383
default: {
8484
var result = ErrorExpressionCompletion.GetCompletions(scope, statement, expression, context);
85-
return result == CompletionResult.Empty
86-
? TopLevelCompletion.GetCompletions(statement, scope, context)
87-
: result;
88-
}
85+
if (result == null) {
86+
return CompletionResult.Empty;
87+
}
88+
return result == CompletionResult.Empty ? TopLevelCompletion.GetCompletions(statement, scope, context) : result;
89+
}
8990
}
9091
}
9192
}

src/LanguageServer/Impl/Completion/ErrorExpressionCompletion.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public static CompletionResult GetCompletions(ScopeStatement scope, Node stateme
8383
case TokenKind.KeywordAs:
8484
return lastToken.Key.Start <= context.Position && context.Position <= lastToken.Key.End ? null : CompletionResult.Empty;
8585

86+
case TokenKind.Error:
87+
return null;
88+
8689
default:
8790
return CompletionResult.Empty;
8891
}

src/LanguageServer/Test/CompletionTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,15 @@ public async Task NoCompletionInString() {
854854
result.Should().HaveNoCompletion();
855855
}
856856

857+
[TestMethod, Priority(0)]
858+
public async Task NoCompletionInOpenString() {
859+
860+
var analysis = await GetAnalysisAsync("'''.");
861+
var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion);
862+
var result = cs.GetCompletions(analysis, new SourceLocation(1, 5));
863+
result.Should().HaveNoCompletion();
864+
}
865+
857866
[TestMethod, Priority(0)]
858867
public async Task NoCompletionInComment() {
859868

0 commit comments

Comments
 (0)