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 CompletionResolve tests #67983

Merged
merged 1 commit into from
Apr 26, 2023
Merged
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 @@ -10,7 +10,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageServer.Handler;
using Microsoft.CodeAnalysis.LanguageServer.Handler.Completion;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.Options;
Expand Down Expand Up @@ -65,7 +64,7 @@ void M()
label: "A").ConfigureAwait(false);

var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A"));
var expected = CreateResolvedCompletionItem(clientCompletionItem, description, "class A", null);
var expected = CreateResolvedCompletionItem(clientCompletionItem, description, null);

var results = (LSP.VSInternalCompletionItem)await RunResolveCompletionItemAsync(
testLspServer, clientCompletionItem).ConfigureAwait(false);
Expand All @@ -87,7 +86,7 @@ void M()
var clientCompletionItem = await GetCompletionItemToResolveAsync<LSP.VSInternalCompletionItem>(testLspServer, label: "A").ConfigureAwait(false);

var description = new ClassifiedTextElement(CreateClassifiedTextRunForClass("A"));
var expected = CreateResolvedCompletionItem(clientCompletionItem, description, "class A", null);
var expected = CreateResolvedCompletionItem(clientCompletionItem, description, null);

var results = (LSP.VSInternalCompletionItem)await RunResolveCompletionItemAsync(
testLspServer, clientCompletionItem).ConfigureAwait(false);
Expand Down Expand Up @@ -182,7 +181,7 @@ class B : A

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

var selectedItem = CodeAnalysis.Completion.CompletionItem.Create(displayText: "M");
var selectedItem = CodeAnalysis.Completion.CompletionItem.Create(displayText: "M", isComplexTextEdit: true);
var textEdit = await EditorLspCompletionResultCreationService.GenerateTextEditAsync(
document, new TestCaretOutOfScopeCompletionService(testLspServer.TestWorkspace.Services.SolutionServices), selectedItem, snippetsSupported: true, CancellationToken.None).ConfigureAwait(false);

Expand Down Expand Up @@ -353,24 +352,49 @@ void M()
completionItem, CancellationToken.None);
}

private static LSP.VSInternalCompletionItem CreateResolvedCompletionItem(
private static VSInternalCompletionItem Clone(VSInternalCompletionItem completionItem)
{
return new VSInternalCompletionItem()
{
Label = completionItem.Label,
Kind = completionItem.Kind,
Detail = completionItem.Detail,
Documentation = completionItem.Documentation,
Preselect = completionItem.Preselect,
SortText = completionItem.SortText,
FilterText = completionItem.FilterText,
InsertText = completionItem.InsertText,
InsertTextFormat = completionItem.InsertTextFormat,
TextEdit = completionItem.TextEdit,
AdditionalTextEdits = completionItem.AdditionalTextEdits,
CommitCharacters = completionItem.CommitCharacters,
Command = completionItem.Command,
Data = completionItem.Data,
Icon = completionItem.Icon,
Description = completionItem.Description,
VsCommitCharacters = completionItem.VsCommitCharacters,
VsResolveTextEditOnCommit = completionItem.VsResolveTextEditOnCommit,
};
}

private static VSInternalCompletionItem CreateResolvedCompletionItem(
VSInternalCompletionItem completionItem,
ClassifiedTextElement description,
string detail,
string documentation)
{
completionItem.Detail = detail;
var expectedCompletionItem = Clone(completionItem);

if (documentation != null)
{
completionItem.Documentation = new LSP.MarkupContent()
expectedCompletionItem.Documentation = new MarkupContent()
{
Kind = LSP.MarkupKind.PlainText,
Value = documentation
};
}

completionItem.Description = description;
return completionItem;
expectedCompletionItem.Description = description;
return expectedCompletionItem;
}

private static ClassifiedTextRun[] CreateClassifiedTextRunForClass(string className)
Expand Down