Skip to content
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

Fix exception when the list only contains a suggestion mode item #67132

Merged
merged 1 commit into from
Mar 2, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
Expand All @@ -19,7 +18,6 @@
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text.Adornments;
using Roslyn.Utilities;
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;

Expand Down Expand Up @@ -90,12 +88,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 fake suggestion mode item.
SuggestionMode = list.SuggestionModeItem is not null,
IsIncomplete = isIncomplete,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it's ok if there are no items in teh list and no suggestion item for us to return this guy?

}
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