@@ -142,8 +142,7 @@ public ScriptFile GetFile(Uri fileUri)
142
142
{
143
143
scriptFile =
144
144
new ScriptFile (
145
- resolvedFileUri . LocalPath ,
146
- resolvedFileUri . OriginalString ,
145
+ resolvedFileUri ,
147
146
streamReader ,
148
147
this . powerShellVersion ) ;
149
148
@@ -249,8 +248,7 @@ public ScriptFile GetFileBuffer(Uri fileUri, string initialBuffer)
249
248
{
250
249
scriptFile =
251
250
new ScriptFile (
252
- resolvedFileUri . LocalPath ,
253
- resolvedFileUri . OriginalString ,
251
+ resolvedFileUri ,
254
252
initialBuffer ,
255
253
this . powerShellVersion ) ;
256
254
@@ -399,9 +397,9 @@ private void RecursivelyFindReferences(
399
397
Dictionary < string , ScriptFile > referencedScriptFiles )
400
398
{
401
399
// Get the base path of the current script for use in resolving relative paths
402
- string baseFilePath =
403
- GetBaseFilePath (
404
- scriptFile . FilePath ) ;
400
+ string baseFilePath = scriptFile . IsInMemory
401
+ ? WorkspacePath
402
+ : Path . GetDirectoryName ( scriptFile . FilePath ) ;
405
403
406
404
foreach ( string referencedFileName in scriptFile . ReferencedFiles )
407
405
{
@@ -437,31 +435,6 @@ private void RecursivelyFindReferences(
437
435
}
438
436
}
439
437
440
- internal string ResolveFilePath ( string filePath )
441
- {
442
- if ( ! IsPathInMemory ( filePath ) )
443
- {
444
- if ( filePath . StartsWith ( @"file://" ) )
445
- {
446
- filePath = WorkspaceService . UnescapeDriveColon ( filePath ) ;
447
- // Client sent the path in URI format, extract the local path
448
- filePath = new Uri ( filePath ) . LocalPath ;
449
- }
450
-
451
- // Clients could specify paths with escaped space, [ and ] characters which .NET APIs
452
- // will not handle. These paths will get appropriately escaped just before being passed
453
- // into the PowerShell engine.
454
- //filePath = PowerShellContext.UnescapeWildcardEscapedPath(filePath);
455
-
456
- // Get the absolute file path
457
- filePath = Path . GetFullPath ( filePath ) ;
458
- }
459
-
460
- this . logger . LogDebug ( "Resolved path: " + filePath ) ;
461
-
462
- return filePath ;
463
- }
464
-
465
438
internal Uri ResolveFileUri ( Uri fileUri )
466
439
{
467
440
if ( fileUri . IsFile )
@@ -509,27 +482,6 @@ internal static bool IsPathInMemory(string filePath)
509
482
return isInMemory ;
510
483
}
511
484
512
- private string GetBaseFilePath ( string filePath )
513
- {
514
- if ( IsPathInMemory ( filePath ) )
515
- {
516
- // If the file is in memory, use the workspace path
517
- return this . WorkspacePath ;
518
- }
519
-
520
- if ( ! Path . IsPathRooted ( filePath ) )
521
- {
522
- // TODO: Assert instead?
523
- throw new InvalidOperationException (
524
- string . Format (
525
- "Must provide a full path for originalScriptPath: {0}" ,
526
- filePath ) ) ;
527
- }
528
-
529
- // Get the directory of the file path
530
- return Path . GetDirectoryName ( filePath ) ;
531
- }
532
-
533
485
internal string ResolveRelativeScriptPath ( string baseFilePath , string relativePath )
534
486
{
535
487
string combinedPath = null ;
@@ -578,39 +530,6 @@ internal string ResolveRelativeScriptPath(string baseFilePath, string relativePa
578
530
return combinedPath ;
579
531
}
580
532
581
- /// <summary>
582
- /// Takes a file-scheme URI with an escaped colon after the drive letter and unescapes only the colon.
583
- /// VSCode sends escaped colons after drive letters, but System.Uri expects unescaped.
584
- /// </summary>
585
- /// <param name="fileUri">The fully-escaped file-scheme URI string.</param>
586
- /// <returns>A file-scheme URI string with the drive colon unescaped.</returns>
587
- private static string UnescapeDriveColon ( string fileUri )
588
- {
589
- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
590
- {
591
- return fileUri ;
592
- }
593
-
594
- // Check here that we have something like "file:///C%3A/" as a prefix (caller must check the file:// part)
595
- if ( ! ( fileUri [ 7 ] == '/' &&
596
- char . IsLetter ( fileUri [ 8 ] ) &&
597
- fileUri [ 9 ] == '%' &&
598
- fileUri [ 10 ] == '3' &&
599
- fileUri [ 11 ] == 'A' &&
600
- fileUri [ 12 ] == '/' ) )
601
- {
602
- return fileUri ;
603
- }
604
-
605
- var sb = new StringBuilder ( fileUri . Length - 2 ) ; // We lost "%3A" and gained ":", so length - 2
606
- sb . Append ( "file:///" ) ;
607
- sb . Append ( fileUri [ 8 ] ) ; // The drive letter
608
- sb . Append ( ':' ) ;
609
- sb . Append ( fileUri . Substring ( 12 ) ) ; // The rest of the URI after the colon
610
-
611
- return sb . ToString ( ) ;
612
- }
613
-
614
533
private static Uri UnescapeDriveColon ( Uri fileUri )
615
534
{
616
535
if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
0 commit comments