diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs index 07707d9f06c..9e5c22e113b 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs @@ -85,7 +85,7 @@ public void Setup() var documentMappingService = BuildRazorDocumentMappingService(); var optionsMonitor = Mock.Of(MockBehavior.Strict); - var translateDiagnosticsService = new RazorTranslateDiagnosticsService(documentMappingService, loggerFactory); + var translateDiagnosticsService = new RazorTranslateDiagnosticsService(documentMappingService, languageServerFeatureOptions, loggerFactory); DocumentPullDiagnosticsEndpoint = new VSDocumentDiagnosticsEndpoint(translateDiagnosticsService, optionsMonitor, languageServer, telemetryReporter: null); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs index 57c508300c6..24505347767 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs @@ -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; @@ -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. /// -/// The . -/// The . -/// -internal class RazorTranslateDiagnosticsService(IDocumentMappingService documentMappingService, ILoggerFactory loggerFactory) +internal class RazorTranslateDiagnosticsService(IDocumentMappingService documentMappingService, LanguageServerFeatureOptions featureOptions, ILoggerFactory loggerFactory) { - private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private readonly IDocumentMappingService _documentMappingService = documentMappingService; + private readonly LanguageServerFeatureOptions _featureOptions = featureOptions; + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private static readonly FrozenSet s_cSharpDiagnosticsToIgnore = new HashSet( [ @@ -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)) { @@ -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; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteRazorTranslateDiagnosticsService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteRazorTranslateDiagnosticsService.cs index 2e024a0ee8d..dd5ee310709 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteRazorTranslateDiagnosticsService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RemoteRazorTranslateDiagnosticsService.cs @@ -5,6 +5,7 @@ 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; @@ -12,6 +13,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor.Diagnostics; [method: ImportingConstructor] internal sealed class RemoteRazorTranslateDiagnosticsService( IDocumentMappingService documentMappingService, - ILoggerFactory loggerFactory) : RazorTranslateDiagnosticsService(documentMappingService, loggerFactory) + LanguageServerFeatureOptions featureOptions, + ILoggerFactory loggerFactory) : RazorTranslateDiagnosticsService(documentMappingService, featureOptions, loggerFactory) { } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/DiagnosticsEndToEndTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/DiagnosticsEndToEndTest.cs index c85d7d31c3c..725584aa2b3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/DiagnosticsEndToEndTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/DiagnosticsEndToEndTest.cs @@ -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); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSCSharpDiagnosticsEndToEndTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSCSharpDiagnosticsEndToEndTest.cs index 2bc01b97ddc..921f90476f3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSCSharpDiagnosticsEndToEndTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSCSharpDiagnosticsEndToEndTest.cs @@ -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); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSDocumentDiagnosticsEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSDocumentDiagnosticsEndpointTest.cs index 5eb210fef6a..06f56e99976 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSDocumentDiagnosticsEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/VSDocumentDiagnosticsEndpointTest.cs @@ -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; @@ -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(MockBehavior.Strict, documentMappingService, + languageServerFeatureOptions, LoggerFactory); var optionsMonitor = TestRazorLSPOptionsMonitor.Create(); var clientConnection = new Mock(MockBehavior.Strict); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.cs index df57b026815..e7b71fe21df 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SingleServerDelegatingEndpointTestBase.cs @@ -57,7 +57,8 @@ private protected async Task CreateLanguageServerAsync( DocumentContextFactory = new TestDocumentContextFactory(razorFilePath, codeDocument); LanguageServerFeatureOptions = Mock.Of(options => - options.SupportsFileManipulation == true, + options.SupportsFileManipulation == true && + options.UseRazorCohostServer == false, MockBehavior.Strict); DocumentMappingService = new LspDocumentMappingService(FilePathService, DocumentContextFactory, LoggerFactory);