diff --git a/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs
index d12de06e3a..46930cda66 100644
--- a/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs
+++ b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs
@@ -23,6 +23,11 @@ public sealed class EditorWorkspace
///
public string Path => editorOperations.GetWorkspacePath();
+ ///
+ /// Get all the workspace folders' paths.
+ ///
+ public string[] Paths => editorOperations.GetWorkspacePaths();
+
#endregion
#region Constructors
diff --git a/src/PowerShellEditorServices/Extensions/IEditorOperations.cs b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs
index 63bae45749..c349bcae15 100644
--- a/src/PowerShellEditorServices/Extensions/IEditorOperations.cs
+++ b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs
@@ -26,6 +26,12 @@ internal interface IEditorOperations
/// The server's initial working directory.
string GetWorkspacePath();
+ ///
+ /// Get all the workspace folders' paths.
+ ///
+ ///
+ string[] GetWorkspacePaths();
+
///
/// Resolves the given file path relative to the current workspace path.
///
diff --git a/src/PowerShellEditorServices/Services/Extension/EditorOperationsService.cs b/src/PowerShellEditorServices/Services/Extension/EditorOperationsService.cs
index a187533c55..4ff235d947 100644
--- a/src/PowerShellEditorServices/Services/Extension/EditorOperationsService.cs
+++ b/src/PowerShellEditorServices/Services/Extension/EditorOperationsService.cs
@@ -6,6 +6,7 @@
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
+using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -192,6 +193,8 @@ public async Task SaveFileAsync(string currentPath, string newSavePath)
// from another for the extension API.
public string GetWorkspacePath() => _workspaceService.InitialWorkingDirectory;
+ public string[] GetWorkspacePaths() => _workspaceService.WorkspacePaths.ToArray();
+
public string GetWorkspaceRelativePath(ScriptFile scriptFile) => _workspaceService.GetRelativePath(scriptFile);
public async Task ShowInformationMessageAsync(string message)
diff --git a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs
index fce8cab204..e8f7023216 100644
--- a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs
+++ b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs
@@ -104,6 +104,10 @@ public WorkspaceService(ILoggerFactory factory)
#region Public Methods
+ public IEnumerable WorkspacePaths => WorkspaceFolders.Count == 0
+ ? new List { InitialWorkingDirectory }
+ : WorkspaceFolders.Select(i => i.Uri.GetFileSystemPath());
+
///
/// Gets an open file in the workspace. If the file isn't open but exists on the filesystem, load and return it.
/// IMPORTANT: Not all documents have a backing file e.g. untitled: scheme documents. Consider using
@@ -358,15 +362,11 @@ public IEnumerable EnumeratePSFiles(
int maxDepth,
bool ignoreReparsePoints)
{
- IEnumerable rootPaths = WorkspaceFolders.Count == 0
- ? new List { InitialWorkingDirectory }
- : WorkspaceFolders.Select(i => i.Uri.GetFileSystemPath());
-
Matcher matcher = new();
foreach (string pattern in includeGlobs) { matcher.AddInclude(pattern); }
foreach (string pattern in excludeGlobs) { matcher.AddExclude(pattern); }
- foreach (string rootPath in rootPaths)
+ foreach (string rootPath in WorkspacePaths)
{
if (!Directory.Exists(rootPath))
{
diff --git a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs
index 1fff5eb3a0..a25e4e8db0 100644
--- a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs
+++ b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs
@@ -80,6 +80,14 @@ internal static WorkspaceService FixturesWorkspace()
};
}
+ [Fact]
+ public void HasDefaultForWorkspacePaths()
+ {
+ WorkspaceService workspace = FixturesWorkspace();
+ string actual = Assert.Single(workspace.WorkspacePaths);
+ Assert.Equal(workspace.InitialWorkingDirectory, actual);
+ }
+
// These are the default values for the EnumeratePSFiles() method
// in Microsoft.PowerShell.EditorServices.Workspace class
private static readonly string[] s_defaultExcludeGlobs = Array.Empty();