1
- // Copyright (c) Microsoft Corporation.
1
+ // Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
5
5
using System . Collections . Concurrent ;
6
6
using System . Collections . Generic ;
7
7
using System . IO ;
8
+ using System . Linq ;
8
9
using System . Security ;
9
10
using System . Text ;
10
11
using Microsoft . Extensions . FileSystemGlobbing ;
13
14
using Microsoft . PowerShell . EditorServices . Services . Workspace ;
14
15
using Microsoft . PowerShell . EditorServices . Utility ;
15
16
using OmniSharp . Extensions . LanguageServer . Protocol ;
17
+ using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
16
18
17
19
namespace Microsoft . PowerShell . EditorServices . Services
18
20
{
@@ -67,6 +69,11 @@ internal class WorkspaceService
67
69
/// </summary>
68
70
public string InitialWorkingDirectory { get ; set ; }
69
71
72
+ /// <summary>
73
+ /// Gets or sets the folders of the workspace.
74
+ /// </summary>
75
+ public List < WorkspaceFolder > WorkspaceFolders { get ; set ; }
76
+
70
77
/// <summary>
71
78
/// Gets or sets the default list of file globs to exclude during workspace searches.
72
79
/// </summary>
@@ -88,6 +95,7 @@ public WorkspaceService(ILoggerFactory factory)
88
95
{
89
96
powerShellVersion = VersionUtils . PSVersion ;
90
97
logger = factory . CreateLogger < WorkspaceService > ( ) ;
98
+ WorkspaceFolders = new List < WorkspaceFolder > ( ) ;
91
99
ExcludeFilesGlob = new List < string > ( ) ;
92
100
FollowSymlinks = true ;
93
101
}
@@ -336,39 +344,46 @@ public IEnumerable<string> EnumeratePSFiles()
336
344
}
337
345
338
346
/// <summary>
339
- /// Enumerate all the PowerShell (ps1, psm1, psd1) files in the workspace in a recursive manner.
347
+ /// Enumerate all the PowerShell (ps1, psm1, psd1) files in the workspace folders in a
348
+ /// recursive manner. Falls back to initial working directory if there are no workspace folders.
340
349
/// </summary>
341
350
/// <returns>An enumerator over the PowerShell files found in the workspace.</returns>
342
351
public IEnumerable < string > EnumeratePSFiles (
343
352
string [ ] excludeGlobs ,
344
353
string [ ] includeGlobs ,
345
354
int maxDepth ,
346
- bool ignoreReparsePoints
347
- )
355
+ bool ignoreReparsePoints )
348
356
{
349
- if ( InitialWorkingDirectory is null || ! Directory . Exists ( InitialWorkingDirectory ) )
350
- {
351
- yield break ;
352
- }
357
+ IEnumerable < string > rootPaths = WorkspaceFolders . Count == 0
358
+ ? new List < string > { InitialWorkingDirectory }
359
+ : WorkspaceFolders . Select ( i => i . Uri . GetFileSystemPath ( ) ) ;
353
360
354
361
Matcher matcher = new ( ) ;
355
362
foreach ( string pattern in includeGlobs ) { matcher . AddInclude ( pattern ) ; }
356
363
foreach ( string pattern in excludeGlobs ) { matcher . AddExclude ( pattern ) ; }
357
364
358
- WorkspaceFileSystemWrapperFactory fsFactory = new (
359
- InitialWorkingDirectory ,
360
- maxDepth ,
361
- VersionUtils . IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework ,
362
- ignoreReparsePoints ,
363
- logger
364
- ) ;
365
- PatternMatchingResult fileMatchResult = matcher . Execute ( fsFactory . RootDirectory ) ;
366
- foreach ( FilePatternMatch item in fileMatchResult . Files )
365
+ foreach ( string rootPath in rootPaths )
367
366
{
368
- // item.Path always contains forward slashes in paths when it should be backslashes on Windows.
369
- // Since we're returning strings here, it's important to use the correct directory separator.
370
- string path = VersionUtils . IsWindows ? item . Path . Replace ( '/' , Path . DirectorySeparatorChar ) : item . Path ;
371
- yield return Path . Combine ( InitialWorkingDirectory , path ) ;
367
+ if ( ! Directory . Exists ( rootPath ) )
368
+ {
369
+ continue ;
370
+ }
371
+
372
+ WorkspaceFileSystemWrapperFactory fsFactory = new (
373
+ rootPath ,
374
+ maxDepth ,
375
+ VersionUtils . IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework ,
376
+ ignoreReparsePoints ,
377
+ logger ) ;
378
+
379
+ PatternMatchingResult fileMatchResult = matcher . Execute ( fsFactory . RootDirectory ) ;
380
+ foreach ( FilePatternMatch item in fileMatchResult . Files )
381
+ {
382
+ // item.Path always contains forward slashes in paths when it should be backslashes on Windows.
383
+ // Since we're returning strings here, it's important to use the correct directory separator.
384
+ string path = VersionUtils . IsWindows ? item . Path . Replace ( '/' , Path . DirectorySeparatorChar ) : item . Path ;
385
+ yield return Path . Combine ( rootPath , path ) ;
386
+ }
372
387
}
373
388
}
374
389
0 commit comments