Skip to content

Commit e38fb89

Browse files
committed
Update tests to validate proper wrapping and unwrapping
1 parent b75e20e commit e38fb89

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentCompletionResolveEndpointTest.cs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@ This is a Razor document.
2525
<div st$$></div>
2626
2727
The end.
28-
""");
28+
""",
29+
supportsVisualStudioExtensions: true);
2930
}
3031

31-
private async Task VerifyCompletionItemResolveAsync(TestCode input)
32+
[Fact]
33+
public async Task HtmlResolve_VSCode()
34+
{
35+
await VerifyCompletionItemResolveAsync(
36+
input: """
37+
This is a Razor document.
38+
39+
<div st$$></div>
40+
41+
The end.
42+
""",
43+
supportsVisualStudioExtensions: false);
44+
}
45+
46+
private async Task VerifyCompletionItemResolveAsync(TestCode input, bool supportsVisualStudioExtensions)
3247
{
3348
var document = CreateProjectAndRazorDocument(input.Text);
3449

@@ -54,22 +69,50 @@ private async Task VerifyCompletionItemResolveAsync(TestCode input)
5469
OriginalCompletionListData: null,
5570
ProjectedKind: RazorLanguageKind.Html);
5671

57-
var request = new VSInternalCompletionItem()
72+
var list = new RazorVSInternalCompletionList
5873
{
59-
Data = JsonSerializer.SerializeToElement(context),
60-
Label = "TestItem"
74+
Data = supportsVisualStudioExtensions ? JsonSerializer.SerializeToElement(context) : null,
75+
ItemDefaults = new()
76+
{
77+
Data = supportsVisualStudioExtensions ? null : JsonSerializer.SerializeToElement(context),
78+
},
79+
Items = [new VSInternalCompletionItem()
80+
{
81+
Label = "TestItem"
82+
}]
6183
};
62-
var list = new RazorVSInternalCompletionList
84+
85+
var clientCapabilities = new VSInternalClientCapabilities
6386
{
64-
Items = [request]
87+
SupportsVisualStudioExtensions = supportsVisualStudioExtensions,
88+
TextDocument = new TextDocumentClientCapabilities()
89+
{
90+
Completion = new VSInternalCompletionSetting()
91+
{
92+
CompletionList = new()
93+
{
94+
Data = supportsVisualStudioExtensions
95+
},
96+
CompletionListSetting = new()
97+
{
98+
ItemDefaults = supportsVisualStudioExtensions ? null : ["data"]
99+
}
100+
}
101+
}
65102
};
66103

67104
var resultId = completionListCache.Add(list, context);
68-
list.SetResultId(resultId, clientCapabilities: new());
69-
RazorCompletionResolveData.Wrap(list, textDocumentIdentifier.TextDocumentIdentifier, clientCapabilities: new());
105+
list.SetResultId(resultId, clientCapabilities);
106+
RazorCompletionResolveData.Wrap(list, textDocumentIdentifier.TextDocumentIdentifier, clientCapabilities);
107+
108+
var request = list.Items[0];
109+
// Simulate the LSP client, which would receive all of the items and the list data, and send the item back to us with
110+
// data filled in.
111+
request.Data = JsonSerializer.SerializeToElement(list.Data ?? list.ItemDefaults.Data, JsonHelpers.JsonSerializerOptions);
70112

71-
// We expect data to be a JsonElement, so for tests we have to _not_ strongly type
72-
request.Data = JsonSerializer.SerializeToElement(request.Data, JsonHelpers.JsonSerializerOptions);
113+
var tdi = endpoint.GetTestAccessor().GetRazorTextDocumentIdentifier(request);
114+
Assert.NotNull(tdi);
115+
Assert.Equal(document.CreateUri(), tdi.Value.Uri);
73116

74117
var result = await endpoint.GetTestAccessor().HandleRequestAsync(request, document, DisposalToken);
75118

0 commit comments

Comments
 (0)