Skip to content

Commit 649286d

Browse files
committed
Use our file system abstraction
1 parent 8943843 commit 649286d

File tree

7 files changed

+42
-22
lines changed

7 files changed

+42
-22
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Rename/RenameService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ namespace Microsoft.CodeAnalysis.Razor.Rename;
2424

2525
internal class RenameService(
2626
IRazorComponentSearchEngine componentSearchEngine,
27+
IFileSystem fileSystem,
2728
LanguageServerFeatureOptions languageServerFeatureOptions) : IRenameService
2829
{
2930
private readonly IRazorComponentSearchEngine _componentSearchEngine = componentSearchEngine;
31+
private readonly IFileSystem _fileSystem = fileSystem;
3032
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions;
3133

3234
public async Task<WorkspaceEdit?> TryGetRazorRenameEditsAsync(
@@ -60,7 +62,7 @@ internal class RenameService(
6062

6163
var originComponentDocumentFilePath = originComponentDocumentSnapshot.FilePath;
6264
var newPath = MakeNewPath(originComponentDocumentFilePath, newName);
63-
if (File.Exists(newPath))
65+
if (_fileSystem.FileExists(newPath))
6466
{
6567
return null;
6668
}

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Rename/OOPRenameService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Microsoft.CodeAnalysis.Remote.Razor.Rename;
1111
[method: ImportingConstructor]
1212
internal sealed class OOPRenameService(
1313
IRazorComponentSearchEngine componentSearchEngine,
14+
IFileSystem fileSystem,
1415
LanguageServerFeatureOptions languageServerFeatureOptions)
15-
: RenameService(componentSearchEngine, languageServerFeatureOptions)
16+
: RenameService(componentSearchEngine, fileSystem, languageServerFeatureOptions)
1617
{
1718
}

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointDelegationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ await projectManager.UpdateAsync(updater =>
6464

6565
var searchEngine = new RazorComponentSearchEngine(LoggerFactory);
6666

67-
var renameService = new RenameService(searchEngine, LanguageServerFeatureOptions);
67+
var renameService = new RenameService(searchEngine, new FileSystem(), LanguageServerFeatureOptions);
6868

6969
var endpoint = new RenameEndpoint(
7070
renameService,

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Refactoring/RenameEndpointTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ await projectManager.UpdateAsync(updater =>
710710

711711
clientConnection ??= StrictMock.Of<IClientConnection>();
712712

713-
var renameService = new RenameService(searchEngine, options);
713+
var renameService = new RenameService(searchEngine, new FileSystem(), options);
714714
var endpoint = new RenameEndpoint(
715715
renameService,
716716
options,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using Microsoft.AspNetCore.Razor;
10+
using Microsoft.CodeAnalysis;
11+
using Microsoft.CodeAnalysis.Razor.Utilities;
12+
using Microsoft.CodeAnalysis.Razor.Workspaces;
13+
14+
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
15+
16+
internal sealed class TestFileSystem((string filePath, string contents)[]? files) : IFileSystem
17+
{
18+
public bool FileExists(string filePath)
19+
=> files?.Any(f => FilePathNormalizingComparer.Instance.Equals(f.filePath, filePath)) ?? false;
20+
21+
public string ReadFile(string filePath)
22+
=> files.AssumeNotNull().Single(f => FilePathNormalizingComparer.Instance.Equals(f.filePath, filePath)).contents;
23+
24+
public Stream OpenReadStream(string filePath)
25+
=> new MemoryStream(Encoding.UTF8.GetBytes(ReadFile(filePath)));
26+
27+
public IEnumerable<string> GetDirectories(string workspaceDirectory)
28+
=> throw new NotImplementedException();
29+
30+
public IEnumerable<string> GetFiles(string workspaceDirectory, string searchPattern, SearchOption searchOption)
31+
=> throw new NotImplementedException();
32+
}

src/Razor/test/Microsoft.VisualStudioCode.RazorExtension.Test/Endpoints/Shared/CodeActions/CohostCodeActionsEndpointTestBase.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,4 @@ private async Task<WorkspaceEdit> ResolveCodeActionAsync(CodeAnalysis.TextDocume
186186
Assert.NotNull(result?.Edit);
187187
return result.Edit;
188188
}
189-
190-
private class TestFileSystem((string filePath, string contents)[]? files) : IFileSystem
191-
{
192-
public bool FileExists(string filePath)
193-
=> files?.Any(f => FilePathNormalizingComparer.Instance.Equals(f.filePath, filePath)) ?? false;
194-
195-
public string ReadFile(string filePath)
196-
=> files.AssumeNotNull().Single(f => FilePathNormalizingComparer.Instance.Equals(f.filePath, filePath)).contents;
197-
198-
public Stream OpenReadStream(string filePath)
199-
=> new MemoryStream(Encoding.UTF8.GetBytes(ReadFile(filePath)));
200-
201-
public IEnumerable<string> GetDirectories(string workspaceDirectory)
202-
=> throw new NotImplementedException();
203-
204-
public IEnumerable<string> GetFiles(string workspaceDirectory, string searchPattern, SearchOption searchOption)
205-
=> throw new NotImplementedException();
206-
}
207189
}

src/Razor/test/Microsoft.VisualStudioCode.RazorExtension.Test/Endpoints/Shared/CohostRenameEndpointTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,9 @@ private async Task VerifyRenamesAsync(
846846

847847
var requestInvoker = new TestHtmlRequestInvoker([(Methods.TextDocumentRenameName, (object?)null)]);
848848

849+
var fileSystem = (RemoteFileSystem)OOPExportProvider.GetExportedValue<IFileSystem>();
850+
fileSystem.GetTestAccessor().SetFileSystem(new TestFileSystem(additionalFiles));
851+
849852
var endpoint = new CohostRenameEndpoint(IncompatibleProjectService, RemoteServiceInvoker, requestInvoker);
850853

851854
var renameParams = new RenameParams

0 commit comments

Comments
 (0)