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 @@ -85,7 +85,7 @@ public void Setup()
var documentMappingService = BuildRazorDocumentMappingService();

var optionsMonitor = Mock.Of<RazorLSPOptionsMonitor>(MockBehavior.Strict);
var translateDiagnosticsService = new RazorTranslateDiagnosticsService(documentMappingService, loggerFactory);
var translateDiagnosticsService = new RazorTranslateDiagnosticsService(documentMappingService, languageServerFeatureOptions, loggerFactory);
DocumentPullDiagnosticsEndpoint = new VSDocumentDiagnosticsEndpoint(translateDiagnosticsService, optionsMonitor, languageServer, telemetryReporter: null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Razor.Diagnostics;
Expand All @@ -28,13 +29,11 @@ namespace Microsoft.CodeAnalysis.Razor.Diagnostics;
/// Contains several methods for mapping and filtering Razor and C# diagnostics. It allows for
/// translating code diagnostics from one representation into another, such as from C# to Razor.
/// </summary>
/// <param name="documentMappingService">The <see cref="IDocumentMappingService"/>.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
/// <exception cref="ArgumentNullException"/>
internal class RazorTranslateDiagnosticsService(IDocumentMappingService documentMappingService, ILoggerFactory loggerFactory)
internal class RazorTranslateDiagnosticsService(IDocumentMappingService documentMappingService, LanguageServerFeatureOptions featureOptions, ILoggerFactory loggerFactory)
{
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<RazorTranslateDiagnosticsService>();
private readonly IDocumentMappingService _documentMappingService = documentMappingService;
private readonly LanguageServerFeatureOptions _featureOptions = featureOptions;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<RazorTranslateDiagnosticsService>();

private static readonly FrozenSet<string> s_cSharpDiagnosticsToIgnore = new HashSet<string>(
[
Expand Down Expand Up @@ -521,7 +520,8 @@ private static bool CheckIfDocumentHasRazorDiagnostic(RazorCodeDocument codeDocu

private bool TryGetOriginalDiagnosticRange(LspDiagnostic diagnostic, RazorCodeDocument codeDocument, [NotNullWhen(true)] out LspRange? originalRange)
{
if (IsRudeEditDiagnostic(diagnostic))
// In cohosting, Enc diagnostics aren't special
if (!_featureOptions.UseRazorCohostServer && IsRudeEditDiagnostic(diagnostic))
{
if (TryRemapRudeEditRange(diagnostic.Range, codeDocument, out originalRange))
{
Expand Down Expand Up @@ -560,9 +560,9 @@ private static bool IsRudeEditDiagnostic(LspDiagnostic diagnostic)

private bool TryRemapRudeEditRange(LspRange diagnosticRange, RazorCodeDocument codeDocument, [NotNullWhen(true)] out LspRange? remappedRange)
{
// This is a rude edit diagnostic that has already been mapped to the Razor document. The mapping isn't absolutely correct though,
// it's based on the runtime code generation of the Razor document therefore we need to re-map the already mapped diagnostic in a
// semi-intelligent way.
// This is a rude edit diagnostic that has already been mapped to the Razor document if cohosting is off.
// The mapping isn't absolutely correct though, it's based on the runtime code generation of the Razor document
// therefore we need to re-map the already mapped diagnostic in a semi-intelligent way.

var syntaxRoot = codeDocument.GetRequiredSyntaxRoot();
var sourceText = codeDocument.Source.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using Microsoft.CodeAnalysis.Razor.Diagnostics;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Workspaces;

namespace Microsoft.CodeAnalysis.Remote.Razor.Diagnostics;

[Export(typeof(RazorTranslateDiagnosticsService)), Shared]
[method: ImportingConstructor]
internal sealed class RemoteRazorTranslateDiagnosticsService(
IDocumentMappingService documentMappingService,
ILoggerFactory loggerFactory) : RazorTranslateDiagnosticsService(documentMappingService, loggerFactory)
LanguageServerFeatureOptions featureOptions,
ILoggerFactory loggerFactory) : RazorTranslateDiagnosticsService(documentMappingService, featureOptions, loggerFactory)
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private async Task ValidateDiagnosticsAsync(string input, string? filePath = nul
var documentContext = CreateDocumentContext(uri, codeDocument);
var requestContext = new RazorRequestContext(documentContext, null!, "lsp/method", uri: null);

var translateDiagnosticsService = new RazorTranslateDiagnosticsService(DocumentMappingService, LoggerFactory);
var translateDiagnosticsService = new RazorTranslateDiagnosticsService(DocumentMappingService, LanguageServerFeatureOptions, LoggerFactory);
var optionsMonitor = TestRazorLSPOptionsMonitor.Create();
var diagnosticsEndPoint = new DocumentDiagnosticsEndpoint(translateDiagnosticsService, languageServer, telemetryReporter: null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private async Task ValidateDiagnosticsAsync(string input, string? filePath = nul
var documentContext = CreateDocumentContext(uri, codeDocument);
var requestContext = new RazorRequestContext(documentContext, null!, "lsp/method", uri: null);

var translateDiagnosticsService = new RazorTranslateDiagnosticsService(DocumentMappingService, LoggerFactory);
var translateDiagnosticsService = new RazorTranslateDiagnosticsService(DocumentMappingService, LanguageServerFeatureOptions, LoggerFactory);
var optionsMonitor = TestRazorLSPOptionsMonitor.Create();
var diagnosticsEndPoint = new VSDocumentDiagnosticsEndpoint(translateDiagnosticsService, optionsMonitor, languageServer, telemetryReporter: null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis.Razor.Diagnostics;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Moq;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -17,9 +19,11 @@ public sealed class VSDocumentDiagnosticsEndpointTest(ITestOutputHelper testOutp
public void ApplyCapabilities_AddsExpectedCapabilities()
{
// Arrange
var languageServerFeatureOptions = new TestLanguageServerFeatureOptions();
var documentMappingService = new LspDocumentMappingService(FilePathService, new TestDocumentContextFactory(), LoggerFactory);
var razorTranslate = new Mock<RazorTranslateDiagnosticsService>(MockBehavior.Strict,
documentMappingService,
languageServerFeatureOptions,
LoggerFactory);
var optionsMonitor = TestRazorLSPOptionsMonitor.Create();
var clientConnection = new Mock<IClientConnection>(MockBehavior.Strict);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ private protected async Task<TestLanguageServer> CreateLanguageServerAsync(
DocumentContextFactory = new TestDocumentContextFactory(razorFilePath, codeDocument);

LanguageServerFeatureOptions = Mock.Of<LanguageServerFeatureOptions>(options =>
options.SupportsFileManipulation == true,
options.SupportsFileManipulation == true &&
options.UseRazorCohostServer == false,
MockBehavior.Strict);

DocumentMappingService = new LspDocumentMappingService(FilePathService, DocumentContextFactory, LoggerFactory);
Expand Down
Loading