|
15 | 15 | using System;
|
16 | 16 | using System.IO;
|
17 | 17 | using System.Linq;
|
| 18 | +using System.Runtime.InteropServices; |
18 | 19 | using System.Threading.Tasks;
|
19 | 20 | using Xunit;
|
20 | 21 |
|
@@ -260,6 +261,97 @@ await this.SendRequest(
|
260 | 261 | Assert.True(updatedCompletionItem.Documentation.Length > 0);
|
261 | 262 | }
|
262 | 263 |
|
| 264 | + [Fact] |
| 265 | + public async Task CompletesDetailOnFilePathSuggestion() |
| 266 | + { |
| 267 | + string expectedPathSnippet; |
| 268 | + |
| 269 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 270 | + { |
| 271 | + expectedPathSnippet = @".\TestFiles\CompleteFunctionName.ps1"; |
| 272 | + } |
| 273 | + else |
| 274 | + { |
| 275 | + expectedPathSnippet = "./TestFiles/CompleteFunctionName.ps1"; |
| 276 | + } |
| 277 | + |
| 278 | + // Change dir to root of this test project's folder |
| 279 | + await this.SetLocationForServerTest(this.TestRootDir); |
| 280 | + |
| 281 | + await this.SendOpenFileEvent(TestUtilities.NormalizePath("TestFiles/CompleteFunctionName.ps1")); |
| 282 | + |
| 283 | + CompletionItem[] completions = |
| 284 | + await this.SendRequest( |
| 285 | + CompletionRequest.Type, |
| 286 | + new TextDocumentPositionParams |
| 287 | + { |
| 288 | + TextDocument = new TextDocumentIdentifier |
| 289 | + { |
| 290 | + Uri = TestUtilities.NormalizePath("TestFiles/CompleteFunctionName.ps1") |
| 291 | + }, |
| 292 | + Position = new Position |
| 293 | + { |
| 294 | + Line = 8, |
| 295 | + Character = 35 |
| 296 | + } |
| 297 | + }); |
| 298 | + |
| 299 | + CompletionItem completionItem = |
| 300 | + completions |
| 301 | + .FirstOrDefault( |
| 302 | + c => c.InsertText == expectedPathSnippet); |
| 303 | + |
| 304 | + Assert.NotNull(completionItem); |
| 305 | + Assert.Equal(InsertTextFormat.PlainText, completionItem.InsertTextFormat); |
| 306 | + } |
| 307 | + |
| 308 | + [Fact] |
| 309 | + public async Task CompletesDetailOnFolderPathSuggestion() |
| 310 | + { |
| 311 | + string expectedPathSnippet; |
| 312 | + InsertTextFormat insertTextFormat; |
| 313 | + |
| 314 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 315 | + { |
| 316 | + expectedPathSnippet = @"'.\TestFiles\Folder With Spaces$0'"; |
| 317 | + insertTextFormat = InsertTextFormat.Snippet; |
| 318 | + } |
| 319 | + else |
| 320 | + { |
| 321 | + expectedPathSnippet = @"'./TestFiles/Folder With Spaces$0'"; |
| 322 | + insertTextFormat = InsertTextFormat.Snippet; |
| 323 | + } |
| 324 | + |
| 325 | + // Change dir to root of this test project's folder |
| 326 | + await this.SetLocationForServerTest(this.TestRootDir); |
| 327 | + |
| 328 | + await this.SendOpenFileEvent(TestUtilities.NormalizePath("TestFiles/CompleteFunctionName.ps1")); |
| 329 | + |
| 330 | + CompletionItem[] completions = |
| 331 | + await this.SendRequest( |
| 332 | + CompletionRequest.Type, |
| 333 | + new TextDocumentPositionParams |
| 334 | + { |
| 335 | + TextDocument = new TextDocumentIdentifier |
| 336 | + { |
| 337 | + Uri = TestUtilities.NormalizePath("TestFiles/CompleteFunctionName.ps1") |
| 338 | + }, |
| 339 | + Position = new Position |
| 340 | + { |
| 341 | + Line = 7, |
| 342 | + Character = 32 |
| 343 | + } |
| 344 | + }); |
| 345 | + |
| 346 | + CompletionItem completionItem = |
| 347 | + completions |
| 348 | + .FirstOrDefault( |
| 349 | + c => c.InsertText == expectedPathSnippet); |
| 350 | + |
| 351 | + Assert.NotNull(completionItem); |
| 352 | + Assert.Equal(insertTextFormat, completionItem.InsertTextFormat); |
| 353 | + } |
| 354 | + |
263 | 355 | [Fact]
|
264 | 356 | public async Task FindsReferencesOfVariable()
|
265 | 357 | {
|
@@ -829,6 +921,27 @@ await this.SendRequest(
|
829 | 921 | Assert.Equal(expectedArchitecture, versionDetails.Architecture);
|
830 | 922 | }
|
831 | 923 |
|
| 924 | + private string TestRootDir |
| 925 | + { |
| 926 | + get |
| 927 | + { |
| 928 | + string assemblyDir = Path.GetDirectoryName(this.GetType().Assembly.Location); |
| 929 | + return Path.Combine(assemblyDir, @"..\..\.."); |
| 930 | + } |
| 931 | + } |
| 932 | + |
| 933 | + private async Task SetLocationForServerTest(string path) |
| 934 | + { |
| 935 | + // Change dir to root of this test project's folder |
| 936 | + await this.SendRequest( |
| 937 | + EvaluateRequest.Type, |
| 938 | + new EvaluateRequestArguments |
| 939 | + { |
| 940 | + Expression = $"Set-Location {path}", |
| 941 | + Context = "repl" |
| 942 | + }); |
| 943 | + } |
| 944 | + |
832 | 945 | private async Task SendOpenFileEvent(string filePath, bool waitForDiagnostics = true)
|
833 | 946 | {
|
834 | 947 | string fileContents = string.Join(Environment.NewLine, File.ReadAllLines(filePath));
|
|
0 commit comments