Skip to content

Commit 7e13faa

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

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-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
@@ -350,15 +354,11 @@ public IEnumerable<string> EnumeratePSFiles(
350354
int maxDepth,
351355
bool ignoreReparsePoints)
352356
{
353-
IEnumerable<string> rootPaths = WorkspaceFolders.Count == 0
354-
? new List<string> { InitialWorkingDirectory }
355-
: WorkspaceFolders.Select(i => i.Uri.GetFileSystemPath());
356-
357357
Matcher matcher = new();
358358
foreach (string pattern in includeGlobs) { matcher.AddInclude(pattern); }
359359
foreach (string pattern in excludeGlobs) { matcher.AddExclude(pattern); }
360360

361-
foreach (string rootPath in rootPaths)
361+
foreach (string rootPath in WorkspacePaths)
362362
{
363363
if (!Directory.Exists(rootPath))
364364
{

0 commit comments

Comments
 (0)