Skip to content
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 @@ -78,12 +78,6 @@ private async Task<VSInternalCompletionItem> PostProcessCompletionItemAsync(
return resolvedCompletionItem;
}

if (resolvedCompletionItem.TextEdit is null && resolvedCompletionItem.AdditionalTextEdits is null)
{
// Only post-processing work we have to do is formatting text edits on resolution.
return resolvedCompletionItem;
}

var identifier = context.Identifier.TextDocumentIdentifier;
if (!_documentContextFactory.TryCreate(identifier, out var documentContext))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void ValidateResolveParams(DelegatedCompletionItemResolveParams @params)
public async Task ResolveAsync_CSharp_Resolves()
{
// Arrange & Act
var resolvedItem = await ResolveCompletionItemAsync("@$$", itemToResolve: "typeof", DisposalToken);
var resolvedItem = await ResolveCompletionItemAsync("@$$", itemToResolve: "typeof", supportsVisualStudioExtensions: true, DisposalToken);

// Assert
Assert.NotNull(resolvedItem.Description);
Expand All @@ -197,23 +197,22 @@ Task FooAsync()
""";
TestFileMarkupParser.GetPosition(input, out var documentContent, out _);
var originalSourceText = SourceText.From(documentContent);
var expectedSourceText = SourceText.From(
"""
var expected = """
@{
async Task FooAsync()
{
await
}
}
""");
""";

// Act
var resolvedItem = await ResolveCompletionItemAsync(input, itemToResolve: "await", DisposalToken);
var resolvedItem = await ResolveCompletionItemAsync(input, itemToResolve: "await", supportsVisualStudioExtensions: true, DisposalToken);

// Assert
var textChange = originalSourceText.GetTextChange(resolvedItem.TextEdit.Value.First);
var actualSourceText = originalSourceText.WithChanges(textChange);
Assert.True(expectedSourceText.ContentEquals(actualSourceText));
AssertEx.EqualOrDiff(expected, actualSourceText.ToString());
}

[Fact]
Expand All @@ -232,16 +231,15 @@ Task FooAsync()

// Admittedly the result here is not perfect, but only because our tests don't implement the full LSP editor logic. The key thing
// is the addition of the using directive.
var expectedSourceText = SourceText.From(
"""
var expected = """
@using System.Text
@{
Task FooAsync()
{
String
}
}
""");
""";

var codeDocument = CreateCodeDocument(input.Text, filePath: "C:/path/to/file.razor");
// Roslyn won't send unimported types if SupportsVisualStudioExtensions is true
Expand Down Expand Up @@ -275,7 +273,37 @@ Task FooAsync()
var originalSourceText = SourceText.From(input.Text);
var textChange = originalSourceText.GetTextChange(resolvedItem.AdditionalTextEdits.Single());
var actualSourceText = originalSourceText.WithChanges(textChange);
AssertEx.EqualOrDiff(expectedSourceText.ToString(), actualSourceText.ToString());
AssertEx.EqualOrDiff(expected, actualSourceText.ToString());
}

[Fact]
public async Task ResolveAsync_CSharp_OverrideCompletion()
{
// Arrange
var input =
"""
@code {
override $$
}
""";
TestFileMarkupParser.GetPosition(input, out var documentContent, out _);
var originalSourceText = SourceText.From(documentContent);
var expected = """
@using System.Threading.Tasks
@code {
protected override Task OnInitializedAsync()
{
return base.OnInitializedAsync();
}
}
""";

// Act
var resolvedItem = await ResolveCompletionItemAsync(input, itemToResolve: "OnInitializedAsync()", supportsVisualStudioExtensions: false, DisposalToken);

var textChange = originalSourceText.GetTextChange((TextEdit)resolvedItem.Command.Arguments[1]);
var actualSourceText = originalSourceText.WithChanges(textChange);
AssertEx.EqualOrDiff(expected, actualSourceText.ToString());
}

[Fact]
Expand Down Expand Up @@ -306,11 +334,11 @@ void ValidateResolveParams(DelegatedCompletionItemResolveParams @params)
}
}

private async Task<VSInternalCompletionItem> ResolveCompletionItemAsync(string content, string itemToResolve, CancellationToken cancellationToken)
private async Task<VSInternalCompletionItem> ResolveCompletionItemAsync(string content, string itemToResolve, bool supportsVisualStudioExtensions, CancellationToken cancellationToken)
{
TestFileMarkupParser.GetPosition(content, out var documentContent, out var cursorPosition);
var codeDocument = CreateCodeDocument(documentContent, filePath: "C:/path/to/file.razor");
await using var csharpServer = await CreateCSharpServerAsync(codeDocument, supportsVisualStudioExtensions: true);
await using var csharpServer = await CreateCSharpServerAsync(codeDocument, supportsVisualStudioExtensions);

var clientConnection = CreateClientConnectionForResolve(csharpServer);
var documentContextFactory = new TestDocumentContextFactory("C:/path/to/file.razor", codeDocument);
Expand Down