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 @@ -73,7 +73,7 @@ public void Setup()
var filePathService = new RemoteFilePathService();
var snapshotManager = new RemoteSnapshotManager(filePathService, NoOpTelemetryReporter.Instance);
var documentSnapshot = snapshotManager.GetSnapshot(document);
_documentContext = new DocumentContext(s_documentUri, documentSnapshot, projectContext: null);
_documentContext = new DocumentContext(s_documentUri, documentSnapshot);

var hostServicesProvider = new RemoteHostServicesProvider();
hostServicesProvider.SetWorkspaceProvider(new WorkspaceProvider(_workspace));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ public ImmutableArray<Registration> GetRegistrations(VSInternalClientCapabilitie

var rewrittenResponse = DelegatedCompletionHelper.RewriteHtmlResponse(result, razorCompletionOptions);

var razorDocumentIdentifier = new TextDocumentIdentifierAndVersion(completionParams.TextDocument, Version: 0);
var resolutionContext = new DelegatedCompletionResolutionContext(razorDocumentIdentifier, RazorLanguageKind.Html, rewrittenResponse.Data ?? rewrittenResponse.ItemDefaults?.Data, ProvisionalTextEdit: null);
var resolutionContext = new DelegatedCompletionResolutionContext(RazorLanguageKind.Html, rewrittenResponse.Data ?? rewrittenResponse.ItemDefaults?.Data, ProvisionalTextEdit: null);
var resultId = _completionListCache.Add(rewrittenResponse, resolutionContext);
rewrittenResponse.SetResultId(resultId, _clientCapabilitiesService.ClientCapabilities);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class CreateComponentCodeActionResolver(LanguageServerFeatureOptions la
return null;
}

if (!documentContext.FileKind.IsComponent())
if (!documentContext.Snapshot.FileKind.IsComponent())
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class PromoteUsingCodeActionResolver(IFileSystem fileSystem) : IRazorCo

var sourceText = await documentContext.GetSourceTextAsync(cancellationToken).ConfigureAwait(false);

var importsFileName = PromoteUsingCodeActionProvider.GetImportsFileName(documentContext.FileKind);
var importsFileName = PromoteUsingCodeActionProvider.GetImportsFileName(documentContext.Snapshot.FileKind);

var file = FilePathNormalizer.Normalize(documentContext.Uri.GetAbsoluteOrUNCPath());
var folder = Path.GetDirectoryName(file).AssumeNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ public static async Task<VSInternalCompletionItem> FormatCSharpCompletionItemAsy
}
else
{
args[0] = documentContext.GetTextDocumentIdentifier();
args[0] = new TextDocumentIdentifier()
{
DocumentUri = new(documentContext.Uri),
};
args[1] = formattedTextEdit;
if (nextCursorPosition >= 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<ImmutableArray<TextChange>> GetDocumentFormattingChangesAsync(
}
}

var logger = _formattingLoggerFactory.CreateLogger(documentContext.FilePath, range is null ? "Full" : "Range");
var logger = _formattingLoggerFactory.CreateLogger(documentContext.Snapshot.FilePath, range is null ? "Full" : "Range");
logger?.LogObject("Options", options);
logger?.LogObject("HtmlChanges", htmlChanges.SelectAsArray(e => e.ToRazorTextChange()));
logger?.LogObject("Range", range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,17 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;

internal class DocumentContext(Uri uri, IDocumentSnapshot snapshot, VSProjectContext? projectContext)
internal class DocumentContext(Uri uri, IDocumentSnapshot snapshot)
{
private readonly VSProjectContext? _projectContext = projectContext;
private RazorCodeDocument? _codeDocument;
private SourceText? _sourceText;

public Uri Uri { get; } = uri;
public IDocumentSnapshot Snapshot { get; } = snapshot;
public string FilePath => Snapshot.FilePath;
public RazorFileKind FileKind => Snapshot.FileKind;

public TextDocumentIdentifier GetTextDocumentIdentifier()
=> new VSTextDocumentIdentifier()
{
DocumentUri = new(Uri),
ProjectContext = _projectContext,
};

public TextDocumentIdentifierAndVersion GetTextDocumentIdentifierAndVersion()
=> new(GetTextDocumentIdentifier(), Snapshot.Version);

private bool TryGetCodeDocument([NotNullWhen(true)] out RazorCodeDocument? codeDocument)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using Microsoft.CodeAnalysis.Razor.Completion;

namespace Microsoft.CodeAnalysis.Razor.Protocol;

internal record DelegatedCompletionResolutionContext(
[property: JsonPropertyName("projectedKind")] RazorLanguageKind ProjectedKind,
[property: JsonPropertyName("originalCompletionListData")] object? OriginalCompletionListData,
[property: JsonPropertyName("provisionalTextEdit")] TextEdit? ProvisionalTextEdit) : ICompletionResolveContext;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<RenameResult> TryGetRazorRenameEditsAsync(
CancellationToken cancellationToken)
{
// We only support renaming of .razor components, not .cshtml tag helpers
if (!documentContext.FileKind.IsComponent())
if (!documentContext.Snapshot.FileKind.IsComponent())
{
return new(Edit: null);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public bool TryGetRazorFileRenameEdit(
string newName,
[NotNullWhen(true)] out WorkspaceEdit? workspaceEdit)
{
var oldPath = documentContext.FilePath;
var oldPath = documentContext.Snapshot.FilePath;
var newPath = MakeNewPath(oldPath, newName);

using var documentChanges = new PooledArrayBuilder<SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private async ValueTask<Response> GetCompletionAsync(
documentSnapshot, positionInfo.ProvisionalTextEdit, cancellationToken).ConfigureAwait(false);

csharpCompletionList = await GetCSharpCompletionAsync(
remoteDocumentContext.GetTextDocumentIdentifierAndVersion(),
csharpGeneratedDocument,
codeDocument,
documentPositionInfo.HostDocumentIndex,
Expand Down Expand Up @@ -186,7 +185,6 @@ private async ValueTask<Response> GetCompletionAsync(
}

private async ValueTask<RazorVSInternalCompletionList?> GetCSharpCompletionAsync(
TextDocumentIdentifierAndVersion identifier,
SourceGeneratedDocument generatedDocument,
RazorCodeDocument codeDocument,
int documentIndex,
Expand Down Expand Up @@ -240,7 +238,7 @@ private async ValueTask<Response> GetCompletionAsync(
mappedPosition,
razorCompletionOptions);

var resolutionContext = new DelegatedCompletionResolutionContext(identifier, RazorLanguageKind.CSharp, rewrittenResponse.Data ?? rewrittenResponse.ItemDefaults?.Data, provisionalTextEdit);
var resolutionContext = new DelegatedCompletionResolutionContext(RazorLanguageKind.CSharp, rewrittenResponse.Data ?? rewrittenResponse.ItemDefaults?.Data, provisionalTextEdit);
var resultId = _completionListCache.Add(rewrittenResponse, resolutionContext);
rewrittenResponse.SetResultId(resultId, clientCapabilities);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override IRemoteDocumentSymbolService CreateService(in ServiceArgs arg
var codeDocument = await context.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false);
var csharpDocument = codeDocument.GetRequiredCSharpDocument();

return _documentSymbolService.GetDocumentSymbols(context.FileKind, context.Uri, csharpDocument, csharpSymbols);
return _documentSymbolService.GetDocumentSymbols(context.Snapshot.FileKind, context.Uri, csharpDocument, csharpSymbols);
}

private static DocumentSymbol[] ConvertDocumentSymbols(DocumentSymbol[] roslynDocumentSymbols)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@

namespace Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem;

internal sealed class RemoteDocumentContext : DocumentContext
internal sealed class RemoteDocumentContext(Uri uri, RemoteDocumentSnapshot snapshot) : DocumentContext(uri, snapshot)
{
public TextDocument TextDocument => Snapshot.TextDocument;

public new RemoteDocumentSnapshot Snapshot => (RemoteDocumentSnapshot)base.Snapshot;

public ISolutionQueryOperations GetSolutionQueryOperations()
=> Snapshot.ProjectSnapshot.SolutionSnapshot;

public RemoteDocumentContext(Uri uri, RemoteDocumentSnapshot snapshot)
// HACK: Need to revisit projectContext here I guess
: base(uri, snapshot, projectContext: null)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected override IRemoteRenameService CreateService(in ServiceArgs args)

private async Task<WorkspaceEdit?> GetEditsAsync(RemoteDocumentContext context, string newFileName, CancellationToken cancellationToken)
{
if (!context.FileKind.IsComponent())
if (!context.Snapshot.FileKind.IsComponent())
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ private async Task VerifyCompletionItemResolveAsync(TestCode input)
new ThrowingSnippetCompletionItemResolveProvider(),
LoggerFactory);

var textDocumentIdentifier = new TextDocumentIdentifierAndVersion(new TextDocumentIdentifier { DocumentUri = document.CreateDocumentUri() }, Version: 0);

var context = new DelegatedCompletionResolutionContext(
textDocumentIdentifier,
OriginalCompletionListData: null,
ProjectedKind: RazorLanguageKind.Html,
ProvisionalTextEdit: null);
Expand All @@ -88,7 +85,7 @@ private async Task VerifyCompletionItemResolveAsync(TestCode input)

var resultId = completionListCache.Add(list, context);
list.SetResultId(resultId, clientCapabilities);
RazorCompletionResolveData.Wrap(list, textDocumentIdentifier.TextDocumentIdentifier, clientCapabilities);
RazorCompletionResolveData.Wrap(list, new TextDocumentIdentifier { DocumentUri = document.CreateDocumentUri() }, clientCapabilities);

var request = list.Items[0];
// Simulate the LSP client, which would receive all of the items and the list data, and send the item back to us with
Expand Down