Skip to content

Commit 101784e

Browse files
committed
Rename WorkspacePath to InitialWorkingDirectory
And note where the API needs to be updated to get the workspace path for the current open editor (since there could be multiple workspaces).
1 parent 422e2cd commit 101784e

File tree

8 files changed

+36
-27
lines changed

8 files changed

+36
-27
lines changed

src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface IEditorScriptFile
4545
public interface IWorkspaceService
4646
{
4747
/// <summary>
48-
/// The root path of the workspace.
48+
/// The root path of the workspace for the current editor.
4949
/// </summary>
5050
string WorkspacePath { get; }
5151

@@ -116,7 +116,9 @@ internal WorkspaceService(
116116
ExcludedFileGlobs = _workspaceService.ExcludeFilesGlob.AsReadOnly();
117117
}
118118

119-
public string WorkspacePath => _workspaceService.WorkspacePath;
119+
// TODO: This needs to use the associated EditorContext to get the workspace for the current
120+
// editor instead of the initial working directory.
121+
public string WorkspacePath => _workspaceService.InitialWorkingDirectory;
120122

121123
public bool FollowSymlinks => _workspaceService.FollowSymlinks;
122124

src/PowerShellEditorServices/Extensions/EditorWorkspace.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class EditorWorkspace
1818
#region Properties
1919

2020
/// <summary>
21-
/// Gets the current workspace path if there is one or null otherwise.
21+
/// Gets the current workspace path if there is one for the open editor or null otherwise.
2222
/// </summary>
2323
public string Path => editorOperations.GetWorkspacePath();
2424

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public async Task StartAsync()
133133
// TODO: Support multi-workspace.
134134
foreach (WorkspaceFolder workspaceFolder in initializeParams.WorkspaceFolders)
135135
{
136-
workspaceService.WorkspacePath = workspaceFolder.Uri.GetFileSystemPath();
136+
workspaceService.InitialWorkingDirectory = workspaceFolder.Uri.GetFileSystemPath();
137137
break;
138138
}
139139
}
@@ -152,7 +152,7 @@ public async Task StartAsync()
152152
LoadProfiles = initializationOptions?.GetValue("enableProfileLoading")?.Value<bool>() ?? true,
153153
// TODO: Consider deprecating the setting which sets this and
154154
// instead use WorkspacePath exclusively.
155-
InitialWorkingDirectory = initializationOptions?.GetValue("initialWorkingDirectory")?.Value<string>() ?? workspaceService.WorkspacePath,
155+
InitialWorkingDirectory = initializationOptions?.GetValue("initialWorkingDirectory")?.Value<string>() ?? workspaceService.InitialWorkingDirectory,
156156
ShellIntegrationEnabled = initializationOptions?.GetValue("shellIntegrationEnabled")?.Value<bool>() ?? false
157157
};
158158

src/PowerShellEditorServices/Services/Extension/EditorOperationsService.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ public async Task SaveFileAsync(string currentPath, string newSavePath)
191191
}).ReturningVoid(CancellationToken.None).ConfigureAwait(false);
192192
}
193193

194-
public string GetWorkspacePath() => _workspaceService.WorkspacePath;
194+
// TODO: This should get the current editor's context and use it to determine which
195+
// workspace it's in.
196+
public string GetWorkspacePath() => _workspaceService.InitialWorkingDirectory;
195197

196198
public string GetWorkspaceRelativePath(string filePath) => _workspaceService.GetRelativePath(filePath);
197199

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
5858

5959
_configurationService.CurrentSettings.Update(
6060
incomingSettings.Powershell,
61-
_workspaceService.WorkspacePath,
61+
_workspaceService.InitialWorkingDirectory,
6262
_logger);
6363

6464
// Run any events subscribed to configuration updates

src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ internal class WorkspaceService
5858
#region Properties
5959

6060
/// <summary>
61-
/// Gets or sets the root path of the workspace.
61+
/// <para>Gets or sets the initial working directory.</para>
62+
/// <para>
63+
/// This is settable by the same key in the initialization options, and likely corresponds
64+
/// to the root of the workspace if only one workspace folder is being used. However, in
65+
/// multi-root workspaces this may be any workspace folder's root (or none if overridden).
66+
/// </para>
6267
/// </summary>
63-
public string WorkspacePath { get; set; }
68+
public string InitialWorkingDirectory { get; set; }
6469

6570
/// <summary>
6671
/// Gets or sets the default list of file globs to exclude during workspace searches.
@@ -299,9 +304,9 @@ public string GetRelativePath(string filePath)
299304
{
300305
string resolvedPath = filePath;
301306

302-
if (!IsPathInMemory(filePath) && !string.IsNullOrEmpty(WorkspacePath))
307+
if (!IsPathInMemory(filePath) && !string.IsNullOrEmpty(InitialWorkingDirectory))
303308
{
304-
Uri workspaceUri = new(WorkspacePath);
309+
Uri workspaceUri = new(InitialWorkingDirectory);
305310
Uri fileUri = new(filePath);
306311

307312
resolvedPath = workspaceUri.MakeRelativeUri(fileUri).ToString();
@@ -341,7 +346,7 @@ public IEnumerable<string> EnumeratePSFiles(
341346
bool ignoreReparsePoints
342347
)
343348
{
344-
if (WorkspacePath is null || !Directory.Exists(WorkspacePath))
349+
if (InitialWorkingDirectory is null || !Directory.Exists(InitialWorkingDirectory))
345350
{
346351
yield break;
347352
}
@@ -351,7 +356,7 @@ bool ignoreReparsePoints
351356
foreach (string pattern in excludeGlobs) { matcher.AddExclude(pattern); }
352357

353358
WorkspaceFileSystemWrapperFactory fsFactory = new(
354-
WorkspacePath,
359+
InitialWorkingDirectory,
355360
maxDepth,
356361
VersionUtils.IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework,
357362
ignoreReparsePoints,
@@ -363,7 +368,7 @@ bool ignoreReparsePoints
363368
// item.Path always contains forward slashes in paths when it should be backslashes on Windows.
364369
// Since we're returning strings here, it's important to use the correct directory separator.
365370
string path = VersionUtils.IsWindows ? item.Path.Replace('/', Path.DirectorySeparatorChar) : item.Path;
366-
yield return Path.Combine(WorkspacePath, path);
371+
yield return Path.Combine(InitialWorkingDirectory, path);
367372
}
368373
}
369374

@@ -423,7 +428,7 @@ internal static bool IsPathInMemory(string filePath)
423428
return isInMemory;
424429
}
425430

426-
internal string ResolveWorkspacePath(string path) => ResolveRelativeScriptPath(WorkspacePath, path);
431+
internal string ResolveWorkspacePath(string path) => ResolveRelativeScriptPath(InitialWorkingDirectory, path);
427432

428433
internal string ResolveRelativeScriptPath(string baseFilePath, string relativePath)
429434
{

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public SymbolsServiceTests()
4040
psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance);
4141
workspace = new WorkspaceService(NullLoggerFactory.Instance)
4242
{
43-
WorkspacePath = TestUtilities.GetSharedPath("References")
43+
InitialWorkingDirectory = TestUtilities.GetSharedPath("References")
4444
};
4545
symbolsService = new SymbolsService(
4646
NullLoggerFactory.Instance,

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void CanResolveWorkspaceRelativePath()
3939
string expectedOutsidePath = TestUtilities.NormalizePath("../PeerPath/FilePath.ps1");
4040

4141
// Test with a workspace path
42-
workspace.WorkspacePath = workspacePath;
42+
workspace.InitialWorkingDirectory = workspacePath;
4343
Assert.Equal(expectedInsidePath, workspace.GetRelativePath(testPathInside));
4444
Assert.Equal(expectedOutsidePath, workspace.GetRelativePath(testPathOutside));
4545
Assert.Equal(testPathAnotherDrive, workspace.GetRelativePath(testPathAnotherDrive));
@@ -49,7 +49,7 @@ internal static WorkspaceService FixturesWorkspace()
4949
{
5050
return new WorkspaceService(NullLoggerFactory.Instance)
5151
{
52-
WorkspacePath = TestUtilities.NormalizePath("Fixtures/Workspace")
52+
InitialWorkingDirectory = TestUtilities.NormalizePath("Fixtures/Workspace")
5353
};
5454
}
5555

@@ -94,18 +94,18 @@ public void CanRecurseDirectoryTree()
9494

9595
List<string> expected = new()
9696
{
97-
Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"),
98-
Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"),
99-
Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"),
100-
Path.Combine(workspace.WorkspacePath, "rootfile.ps1")
97+
Path.Combine(workspace.InitialWorkingDirectory, "nested", "donotfind.ps1"),
98+
Path.Combine(workspace.InitialWorkingDirectory, "nested", "nestedmodule.psd1"),
99+
Path.Combine(workspace.InitialWorkingDirectory, "nested", "nestedmodule.psm1"),
100+
Path.Combine(workspace.InitialWorkingDirectory, "rootfile.ps1")
101101
};
102102

103103
// .NET Core doesn't appear to use the same three letter pattern matching rule although the docs
104104
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
105105
// ref https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-2.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_EnumerationOptions_
106106
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
107107
{
108-
expected.Insert(3, Path.Combine(workspace.WorkspacePath, "other", "other.ps1xml"));
108+
expected.Insert(3, Path.Combine(workspace.InitialWorkingDirectory, "other", "other.ps1xml"));
109109
}
110110

111111
Assert.Equal(expected, actual);
@@ -122,7 +122,7 @@ public void CanRecurseDirectoryTreeWithLimit()
122122
maxDepth: 1,
123123
ignoreReparsePoints: s_defaultIgnoreReparsePoints
124124
);
125-
Assert.Equal(new[] { Path.Combine(workspace.WorkspacePath, "rootfile.ps1") }, actual);
125+
Assert.Equal(new[] { Path.Combine(workspace.InitialWorkingDirectory, "rootfile.ps1") }, actual);
126126
}
127127

128128
[Fact]
@@ -138,8 +138,8 @@ public void CanRecurseDirectoryTreeWithGlobs()
138138
);
139139

140140
Assert.Equal(new[] {
141-
Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"),
142-
Path.Combine(workspace.WorkspacePath, "rootfile.ps1")
141+
Path.Combine(workspace.InitialWorkingDirectory, "nested", "nestedmodule.psd1"),
142+
Path.Combine(workspace.InitialWorkingDirectory, "rootfile.ps1")
143143
}, actual);
144144
}
145145

@@ -181,7 +181,7 @@ public void CanDetermineIsPathInMemory()
181181
public void CanOpenAndCloseFile()
182182
{
183183
WorkspaceService workspace = FixturesWorkspace();
184-
string filePath = Path.GetFullPath(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"));
184+
string filePath = Path.GetFullPath(Path.Combine(workspace.InitialWorkingDirectory, "rootfile.ps1"));
185185

186186
ScriptFile file = workspace.GetFile(filePath);
187187
Assert.Equal(workspace.GetOpenedFiles(), new[] { file });

0 commit comments

Comments
 (0)