@@ -358,18 +358,30 @@ private string ResolveFilePath(string filePath)
358
358
359
359
internal static bool IsPathInMemory ( string filePath )
360
360
{
361
- // When viewing PowerShell files in the Git diff viewer, VS Code
362
- // sends the contents of the file at HEAD with a URI that starts
363
- // with 'inmemory'. Untitled files which have been marked of
364
- // type PowerShell have a path starting with 'untitled'.
365
- return
366
- filePath . StartsWith ( "inmemory" ) ||
367
- filePath . StartsWith ( "untitled" ) ||
368
- filePath . StartsWith ( "private" ) ||
369
- filePath . StartsWith ( "git" ) ;
370
-
371
- // TODO #342: Remove 'private' and 'git' and then add logic to
372
- // throw when any unsupported file URI scheme is encountered.
361
+ bool isInMemory = false ;
362
+
363
+ // In cases where a "virtual" file is displayed in the editor,
364
+ // we need to treat the file differently than one that exists
365
+ // on disk. A virtual file could be something like a diff
366
+ // view of the current file or an untitled file.
367
+ try
368
+ {
369
+ // NotSupportedException or ArgumentException gets thrown when
370
+ // given an invalid path. Since any non-standard path will
371
+ // trigger this, assume that it means it's an in-memory file
372
+ // unless the path starts with file:
373
+ Path . GetFullPath ( filePath ) ;
374
+ }
375
+ catch ( ArgumentException )
376
+ {
377
+ isInMemory = true ;
378
+ }
379
+ catch ( NotSupportedException )
380
+ {
381
+ isInMemory = true ;
382
+ }
383
+
384
+ return ! filePath . ToLower ( ) . StartsWith ( "file:" ) && isInMemory ;
373
385
}
374
386
375
387
private string GetBaseFilePath ( string filePath )
0 commit comments