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

Send a TextDocumentidentifier for razor dynamic file requests/responses #74727

Merged
merged 2 commits into from
Aug 13, 2024
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 @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer.LanguageServer;
using Microsoft.CodeAnalysis.Text;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace;
Expand All @@ -20,22 +21,22 @@ internal class RazorDynamicFileInfoProvider : IDynamicFileInfoProvider

private class ProvideDynamicFileParams
{
[JsonPropertyName("razorFiles")]
public required Uri[] RazorFiles { get; set; }
[JsonPropertyName("razorDocument")]
public required TextDocumentIdentifier RazorDocument { get; set; }
}

private class ProvideDynamicFileResponse
{
[JsonPropertyName("generatedFiles")]
public required Uri[] GeneratedFiles { get; set; }
[JsonPropertyName("csharpDocument")]
public required TextDocumentIdentifier CSharpDocument { get; set; }
}

private const string RemoveRazorDynamicFileInfoMethodName = "razor/removeDynamicFileInfo";

private class RemoveDynamicFileParams
{
[JsonPropertyName("razorFiles")]
public required Uri[] RazorFiles { get; set; }
[JsonPropertyName("csharpDocument")]
public required TextDocumentIdentifier CSharpDocument { get; set; }
}

#pragma warning disable CS0067 // We won't fire the Updated event -- we expect Razor to send us textual changes via didChange instead
Expand All @@ -55,7 +56,13 @@ public RazorDynamicFileInfoProvider(Lazy<RazorWorkspaceListenerInitializer> razo
{
_razorWorkspaceListenerInitializer.Value.NotifyDynamicFile(projectId);

var requestParams = new ProvideDynamicFileParams { RazorFiles = [ProtocolConversions.CreateAbsoluteUri(filePath)] };
var requestParams = new ProvideDynamicFileParams
{
RazorDocument = new()
{
Uri = ProtocolConversions.CreateAbsoluteUri(filePath)
}
};

Contract.ThrowIfNull(LanguageServerHost.Instance, "We don't have an LSP channel yet to send this request through.");
var clientLanguageServerManager = LanguageServerHost.Instance.GetRequiredLspService<IClientLanguageServerManager>();
Expand All @@ -64,7 +71,7 @@ public RazorDynamicFileInfoProvider(Lazy<RazorWorkspaceListenerInitializer> razo
ProvideRazorDynamicFileInfoMethodName, requestParams, cancellationToken);

// Since we only sent one file over, we should get either zero or one URI back
var responseUri = response.GeneratedFiles.SingleOrDefault();
var responseUri = response.CSharpDocument?.Uri;

if (responseUri == null)
{
Expand All @@ -79,7 +86,13 @@ public RazorDynamicFileInfoProvider(Lazy<RazorWorkspaceListenerInitializer> razo

public Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
{
var notificationParams = new RemoveDynamicFileParams { RazorFiles = [ProtocolConversions.CreateAbsoluteUri(filePath)] };
var notificationParams = new RemoveDynamicFileParams
{
CSharpDocument = new()
{
Uri = ProtocolConversions.CreateAbsoluteUri(filePath)
}
};

Contract.ThrowIfNull(LanguageServerHost.Instance, "We don't have an LSP channel yet to send this request through.");
var clientLanguageServerManager = LanguageServerHost.Instance.GetRequiredLspService<IClientLanguageServerManager>();
Expand Down
Loading