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