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

Suppress completion after error tokens #752

Merged
merged 13 commits into from
Mar 14, 2019
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
11 changes: 6 additions & 5 deletions src/LanguageServer/Impl/Completion/CompletionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public CompletionResult GetCompletions(IDocumentAnalysis analysis, SourceLocatio
// no completions on integer ., the user is typing a float
return CompletionResult.Empty;
case ConstantExpression ce2 when ce2.Value is string:
// no completions in strings
// no completions in strings
case null when context.Ast.IsInsideComment(context.Location):
case null when context.Ast.IsInsideString(context.Location):
return CompletionResult.Empty;
Expand Down Expand Up @@ -82,10 +82,11 @@ public CompletionResult GetCompletions(IDocumentAnalysis analysis, SourceLocatio
return result;
default: {
var result = ErrorExpressionCompletion.GetCompletions(scope, statement, expression, context);
return result == CompletionResult.Empty
? TopLevelCompletion.GetCompletions(statement, scope, context)
: result;
}
if (result == null) {
return CompletionResult.Empty;
}
return result == CompletionResult.Empty ? TopLevelCompletion.GetCompletions(statement, scope, context) : result;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public static CompletionResult GetCompletions(ScopeStatement scope, Node stateme
case TokenKind.KeywordAs:
return lastToken.Key.Start <= context.Position && context.Position <= lastToken.Key.End ? null : CompletionResult.Empty;

case TokenKind.Error:
return null;

default:
return CompletionResult.Empty;
}
Expand Down
9 changes: 9 additions & 0 deletions src/LanguageServer/Test/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,15 @@ public async Task NoCompletionInString() {
result.Should().HaveNoCompletion();
}

[TestMethod, Priority(0)]
public async Task NoCompletionInOpenString() {

var analysis = await GetAnalysisAsync("'''.");
var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion);
var result = cs.GetCompletions(analysis, new SourceLocation(1, 5));
result.Should().HaveNoCompletion();
}

[TestMethod, Priority(0)]
public async Task NoCompletionInComment() {

Expand Down