Repository navigation
Remove IFilePathService and replace with simple extension methods - #84351
Conversation
…e does, and tests IFilePathService operates on Uris, but is also laregly unnecessary in a cohosting only world. In particular getting a Razor file path from anything but a virtual Html document path is quite problematic, so combining these into one method is a better shape too.
There was a problem hiding this comment.
Pull request overview
This PR removes the IFilePathService abstraction from Razor’s cohosting/remote layers and replaces its responsibilities with lightweight DocumentUri-based extension methods for detecting/remapping Razor virtual document URIs. The change propagates through cohost endpoints, remote services, tests, and a microbenchmark setup.
Changes:
- Eliminates
IFilePathService/AbstractFilePathServiceand the VS/VS Code/remote concrete implementations. - Introduces
DocumentUriExtensionsand updates cohost/remote code paths to useDocumentUri-centric virtual-document detection/remapping. - Updates unit tests and benchmark wiring to match the new
RemoteSnapshotManager/DocumentMappingServiceconstructor shapes.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Razor/src/Razor/test/Microsoft.VisualStudioCode.RazorExtension.UnitTests/CohostEndpointTestBase.cs | Removes MEF acquisition/exposure of IFilePathService in VS Code cohost test base. |
| src/Razor/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.UnitTests/Cohost/CohostUriPresentationEndpointTest.cs | Updates endpoint construction after IFilePathService removal. |
| src/Razor/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.UnitTests/Cohost/CohostTextPresentationEndpointTest.cs | Updates endpoint construction after IFilePathService removal. |
| src/Razor/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.UnitTests/Cohost/CohostEndpointTestBase.cs | Removes IFilePathService usage/initialization in devenv-style cohost tests. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Remote.Razor.UnitTests/CodeActions/HtmlCodeActionResolverTest.cs | Updates RemoteSnapshotManager construction. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Remote.Razor.UnitTests/CodeActions/HtmlCodeActionProviderTest.cs | Updates RemoteSnapshotManager construction. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.UnitTests/FilePathServiceTest.cs | Removes tests tied to the deleted AbstractFilePathService/IFilePathService. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.UnitTests/DocumentUriExtensionsTest.cs | Adds test coverage for new DocumentUriExtensions.IsRazorHtmlDocumentUri. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/RazorDocumentMappingServiceTest.cs | Updates DocumentMappingService construction after IFilePathService removal. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Endpoints/CohostGoToImplementationEndpointTest.cs | Updates endpoint construction after IFilePathService removal. |
| src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Endpoints/CohostGoToDefinitionEndpointTest.cs | Updates endpoint construction after IFilePathService removal. |
| src/Razor/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Cohosting/CohostTestBase.cs | Removes abstract FilePathService requirement from shared cohost test base. |
| src/Razor/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/VSCodeFilePathService.cs | Deletes VS Code-specific IFilePathService implementation. |
| src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/VisualStudioFilePathService.cs | Deletes Visual Studio IFilePathService implementation. |
| src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostUriPresentationEndpoint.cs | Switches virtual-HTML URI remapping to DocumentUriExtensions. |
| src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostTextPresentationEndpoint.cs | Switches virtual-HTML URI remapping to DocumentUriExtensions. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/TypeHierarchy/RemoteTypeHierarchyService.cs | Replaces virtual-C# detection with DocumentUriExtensions.IsRazorCSharpDocumentUri. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteFilePathService.cs | Deletes remote IFilePathService implementation. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteSnapshotManager.cs | Removes IFilePathService dependency and property from snapshot manager. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/FindAllReferences/RemoteFindAllReferencesService.cs | Uses DocumentUriExtensions to filter/return mapped URIs. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RazorEditService.cs | Removes IFilePathService from constructor/state. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RazorEditService_WorkspaceEdit.cs | Replaces virtual doc checks/remapping with DocumentUriExtensions. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/DocumentMappingService.cs | Removes IFilePathService and updates mapping decisions to use DocumentUriExtensions. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/IRoslynCodeActionHelpers.cs | Minor doc comment wording update. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/CSharp/CSharpCodeActionResolver.cs | Replaces virtual-C# detection with DocumentUriExtensions.IsRazorCSharpDocumentUri. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CallHierarchy/RemoteCallHierarchyService.cs | Replaces virtual-C# filtering with DocumentUriExtensions.IsRazorCSharpDocumentUri. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IFilePathService.cs | Deletes the IFilePathService interface. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/DocumentUriExtensions.cs | Adds DocumentUri extension helpers for Razor virtual document detection/remapping. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AbstractFilePathService.cs | Deletes the shared base implementation that backed IFilePathService. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToImplementationEndpoint.cs | Replaces HTML virtual URI remapping with DocumentUriExtensions. |
| src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs | Replaces HTML virtual URI remapping with DocumentUriExtensions. |
| src/Razor/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Formatting/DocumentFormattingBenchmark.cs | Updates benchmark wiring for RemoteSnapshotManager/DocumentMappingService constructor changes. |
ToddGrun
left a comment
There was a problem hiding this comment.
I'll trust you that this will end up in a nicer place as it looks like it complicated a couple of the callers.
If you mean the current "convert to DocumentUri so you can call an extension method" pattern, then yes, in the follow up a lot of these are becoming DocumentUri directly. |
Pulled out of larger work to migrate everything to
DocumentUrioverSystem.Uri, so some of the changes are a little annoying for now, like converting from one to the other just to call an extension method, but trust me this is just a point-in-time thing.Microsoft Reviewers: Open in CodeFlow