@@ -142,8 +142,7 @@ public ScriptFile GetFile(Uri fileUri)
142142 {
143143 scriptFile =
144144 new ScriptFile (
145- resolvedFileUri . LocalPath ,
146- resolvedFileUri . OriginalString ,
145+ resolvedFileUri ,
147146 streamReader ,
148147 this . powerShellVersion ) ;
149148
@@ -249,8 +248,7 @@ public ScriptFile GetFileBuffer(Uri fileUri, string initialBuffer)
249248 {
250249 scriptFile =
251250 new ScriptFile (
252- resolvedFileUri . LocalPath ,
253- resolvedFileUri . OriginalString ,
251+ resolvedFileUri ,
254252 initialBuffer ,
255253 this . powerShellVersion ) ;
256254
@@ -399,9 +397,9 @@ private void RecursivelyFindReferences(
399397 Dictionary < string , ScriptFile > referencedScriptFiles )
400398 {
401399 // 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 ) ;
405403
406404 foreach ( string referencedFileName in scriptFile . ReferencedFiles )
407405 {
@@ -437,31 +435,6 @@ private void RecursivelyFindReferences(
437435 }
438436 }
439437
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-
465438 internal Uri ResolveFileUri ( Uri fileUri )
466439 {
467440 if ( fileUri . IsFile )
@@ -509,27 +482,6 @@ internal static bool IsPathInMemory(string filePath)
509482 return isInMemory ;
510483 }
511484
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-
533485 internal string ResolveRelativeScriptPath ( string baseFilePath , string relativePath )
534486 {
535487 string combinedPath = null ;
@@ -578,39 +530,6 @@ internal string ResolveRelativeScriptPath(string baseFilePath, string relativePa
578530 return combinedPath ;
579531 }
580532
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-
614533 private static Uri UnescapeDriveColon ( Uri fileUri )
615534 {
616535 if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
0 commit comments