7
7
using System . Runtime . InteropServices ;
8
8
using Microsoft . Extensions . Logging . Abstractions ;
9
9
using Microsoft . PowerShell . EditorServices . Services ;
10
- using Microsoft . PowerShell . EditorServices . Test . Shared ;
11
10
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
12
11
using Xunit ;
13
12
using Microsoft . PowerShell . EditorServices . Utility ;
@@ -27,6 +26,10 @@ public class WorkspaceTests
27
26
28
27
internal static ScriptFile CreateScriptFile ( string path ) => new ( path , "" , VersionUtils . PSVersion ) ;
29
28
29
+ // Remember that LSP does weird stuff to the drive letter, so we have to convert it to a URI
30
+ // and back to ensure that drive letter gets lower cased and everything matches up.
31
+ private static string s_workspacePath =>
32
+ DocumentUri . FromFileSystemPath ( Path . GetFullPath ( "Fixtures/Workspace" ) ) . GetFileSystemPath ( ) ;
30
33
31
34
[ Fact ]
32
35
public void CanResolveWorkspaceRelativePath ( )
@@ -76,16 +79,21 @@ internal static WorkspaceService FixturesWorkspace()
76
79
{
77
80
return new WorkspaceService ( NullLoggerFactory . Instance )
78
81
{
79
- InitialWorkingDirectory = TestUtilities . NormalizePath ( "Fixtures/Workspace" )
82
+ WorkspaceFolders =
83
+ {
84
+ new WorkspaceFolder { Uri = DocumentUri . FromFileSystemPath ( s_workspacePath ) }
85
+ }
80
86
} ;
81
87
}
82
88
83
89
[ Fact ]
84
90
public void HasDefaultForWorkspacePaths ( )
85
91
{
86
92
WorkspaceService workspace = FixturesWorkspace ( ) ;
87
- string actual = Assert . Single ( workspace . WorkspacePaths ) ;
88
- Assert . Equal ( workspace . InitialWorkingDirectory , actual ) ;
93
+ string workspacePath = Assert . Single ( workspace . WorkspacePaths ) ;
94
+ Assert . Equal ( s_workspacePath , workspacePath ) ;
95
+ // We shouldn't assume an initial working directory since none was given.
96
+ Assert . Null ( workspace . InitialWorkingDirectory ) ;
89
97
}
90
98
91
99
// These are the default values for the EnumeratePSFiles() method
@@ -129,18 +137,18 @@ public void CanRecurseDirectoryTree()
129
137
130
138
List < string > expected = new ( )
131
139
{
132
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "donotfind.ps1" ) ,
133
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "nestedmodule.psd1" ) ,
134
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "nestedmodule.psm1" ) ,
135
- Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" )
140
+ Path . Combine ( s_workspacePath , "nested" , "donotfind.ps1" ) ,
141
+ Path . Combine ( s_workspacePath , "nested" , "nestedmodule.psd1" ) ,
142
+ Path . Combine ( s_workspacePath , "nested" , "nestedmodule.psm1" ) ,
143
+ Path . Combine ( s_workspacePath , "rootfile.ps1" )
136
144
} ;
137
145
138
146
// .NET Core doesn't appear to use the same three letter pattern matching rule although the docs
139
147
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
140
148
// 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_
141
149
if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" ) )
142
150
{
143
- expected . Insert ( 3 , Path . Combine ( workspace . InitialWorkingDirectory , "other" , "other.ps1xml" ) ) ;
151
+ expected . Insert ( 3 , Path . Combine ( s_workspacePath , "other" , "other.ps1xml" ) ) ;
144
152
}
145
153
146
154
Assert . Equal ( expected , actual ) ;
@@ -157,7 +165,7 @@ public void CanRecurseDirectoryTreeWithLimit()
157
165
maxDepth : 1 ,
158
166
ignoreReparsePoints : s_defaultIgnoreReparsePoints
159
167
) ;
160
- Assert . Equal ( new [ ] { Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" ) } , actual ) ;
168
+ Assert . Equal ( new [ ] { Path . Combine ( s_workspacePath , "rootfile.ps1" ) } , actual ) ;
161
169
}
162
170
163
171
[ Fact ]
@@ -173,16 +181,16 @@ public void CanRecurseDirectoryTreeWithGlobs()
173
181
) ;
174
182
175
183
Assert . Equal ( new [ ] {
176
- Path . Combine ( workspace . InitialWorkingDirectory , "nested" , "nestedmodule.psd1" ) ,
177
- Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" )
184
+ Path . Combine ( s_workspacePath , "nested" , "nestedmodule.psd1" ) ,
185
+ Path . Combine ( s_workspacePath , "rootfile.ps1" )
178
186
} , actual ) ;
179
187
}
180
188
181
189
[ Fact ]
182
190
public void CanOpenAndCloseFile ( )
183
191
{
184
192
WorkspaceService workspace = FixturesWorkspace ( ) ;
185
- string filePath = Path . GetFullPath ( Path . Combine ( workspace . InitialWorkingDirectory , "rootfile.ps1" ) ) ;
193
+ string filePath = Path . GetFullPath ( Path . Combine ( s_workspacePath , "rootfile.ps1" ) ) ;
186
194
187
195
ScriptFile file = workspace . GetFile ( filePath ) ;
188
196
Assert . Equal ( workspace . GetOpenedFiles ( ) , new [ ] { file } ) ;
0 commit comments