Skip to content

Commit

Permalink
Fix exception when the list only contains a suggestion mode item
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Mar 1, 2023
1 parent 894751f commit 1e2ab52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -90,12 +91,15 @@ public CompletionHandler(
return null;

var (list, isIncomplete, resultId) = completionListResult.Value;
if (list.IsEmpty)

if (list.ItemsList.Count == 0)
{
return new LSP.VSInternalCompletionList
{
Items = Array.Empty<LSP.CompletionItem>(),
SuggestionMode = list.SuggestionModeItem != null,
// If we have a suggestion mode item, we just need to keep the list in suggestion mode.
// We don't need to return the suggestion mode item.
SuggestionMode = list.SuggestionModeItem is not null,
IsIncomplete = isIncomplete,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,33 @@ void M()
Assert.Empty(results.Items);
}

[Fact, WorkItem(1755138, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1755138")]
public async Task TestOnlyHasSuggestionModeItemAsync()
{
var markup =
@"using System.Threading.Tasks;
class A
{
void M()
{
Task.Run(abcdefg{|caret:|}
}
}";
await using var testLspServer = await CreateTestLspServerAsync(markup, s_vsCompletionCapabilities);
var completionParams = CreateCompletionParams(
testLspServer.GetLocations("caret").Single(),
invokeKind: LSP.VSInternalCompletionInvokeKind.Typing,
triggerCharacter: "g",
triggerKind: LSP.CompletionTriggerKind.TriggerForIncompleteCompletions);

var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First();

var results = await RunGetCompletionsAsync(testLspServer, completionParams).ConfigureAwait(false);
var list = (LSP.VSInternalCompletionList)results;
Assert.Empty(list.Items);
Assert.True(list.SuggestionMode);
}

internal static Task<LSP.CompletionList> RunGetCompletionsAsync(TestLspServer testLspServer, LSP.CompletionParams completionParams)
{
return testLspServer.ExecuteRequestAsync<LSP.CompletionParams, LSP.CompletionList>(LSP.Methods.TextDocumentCompletionName,
Expand Down

0 comments on commit 1e2ab52

Please sign in to comment.