Skip to content

Commit 056a4d5

Browse files
committed
Add Paths to workspace API for multi-root workspaces
Since `Path` now refers to initial working directory.
1 parent e540922 commit 056a4d5

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/PowerShellEditorServices/Extensions/EditorWorkspace.cs

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public sealed class EditorWorkspace
2323
/// </summary>
2424
public string Path => editorOperations.GetWorkspacePath();
2525

26+
/// <summary>
27+
/// Get all the workspace folders' paths.
28+
/// </summary>
29+
public string[] Paths => editorOperations.GetWorkspacePaths();
30+
2631
#endregion
2732

2833
#region Constructors

src/PowerShellEditorServices/Extensions/IEditorOperations.cs

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ internal interface IEditorOperations
2626
/// <returns>The server's initial working directory.</returns>
2727
string GetWorkspacePath();
2828

29+
/// <summary>
30+
/// Get all the workspace folders' paths.
31+
/// </summary>
32+
/// <returns></returns>
33+
string[] GetWorkspacePaths();
34+
2935
/// <summary>
3036
/// Resolves the given file path relative to the current workspace path.
3137
/// </summary>

src/PowerShellEditorServices/Services/Extension/EditorOperationsService.cs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
77
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
88
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
9+
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112

@@ -192,6 +193,8 @@ public async Task SaveFileAsync(string currentPath, string newSavePath)
192193
// from another for the extension API.
193194
public string GetWorkspacePath() => _workspaceService.InitialWorkingDirectory;
194195

196+
public string[] GetWorkspacePaths() => _workspaceService.WorkspacePaths.ToArray();
197+
195198
public string GetWorkspaceRelativePath(ScriptFile scriptFile) => _workspaceService.GetRelativePath(scriptFile);
196199

197200
public async Task ShowInformationMessageAsync(string message)

src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public WorkspaceService(ILoggerFactory factory)
104104

105105
#region Public Methods
106106

107+
public IEnumerable<string> WorkspacePaths => WorkspaceFolders.Count == 0
108+
? new List<string> { InitialWorkingDirectory }
109+
: WorkspaceFolders.Select(i => i.Uri.GetFileSystemPath());
110+
107111
/// <summary>
108112
/// Gets an open file in the workspace. If the file isn't open but exists on the filesystem, load and return it.
109113
/// <para>IMPORTANT: Not all documents have a backing file e.g. untitled: scheme documents. Consider using
@@ -358,15 +362,11 @@ public IEnumerable<string> EnumeratePSFiles(
358362
int maxDepth,
359363
bool ignoreReparsePoints)
360364
{
361-
IEnumerable<string> rootPaths = WorkspaceFolders.Count == 0
362-
? new List<string> { InitialWorkingDirectory }
363-
: WorkspaceFolders.Select(i => i.Uri.GetFileSystemPath());
364-
365365
Matcher matcher = new();
366366
foreach (string pattern in includeGlobs) { matcher.AddInclude(pattern); }
367367
foreach (string pattern in excludeGlobs) { matcher.AddExclude(pattern); }
368368

369-
foreach (string rootPath in rootPaths)
369+
foreach (string rootPath in WorkspacePaths)
370370
{
371371
if (!Directory.Exists(rootPath))
372372
{

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ internal static WorkspaceService FixturesWorkspace()
8080
};
8181
}
8282

83+
[Fact]
84+
public void HasDefaultForWorkspacePaths()
85+
{
86+
WorkspaceService workspace = FixturesWorkspace();
87+
string actual = Assert.Single(workspace.WorkspacePaths);
88+
Assert.Equal(workspace.InitialWorkingDirectory, actual);
89+
}
90+
8391
// These are the default values for the EnumeratePSFiles() method
8492
// in Microsoft.PowerShell.EditorServices.Workspace class
8593
private static readonly string[] s_defaultExcludeGlobs = Array.Empty<string>();

0 commit comments

Comments
 (0)