@@ -351,7 +351,7 @@ private void RecursivelyEnumerateFiles(string folderPath, ref List<string> found
351
351
this . logger . WriteHandledException (
352
352
$ "Could not enumerate files in the path '{ folderPath } ' due to an exception",
353
353
e ) ;
354
-
354
+
355
355
continue ;
356
356
}
357
357
@@ -400,7 +400,7 @@ private void RecursivelyEnumerateFiles(string folderPath, ref List<string> found
400
400
this . logger . WriteHandledException (
401
401
$ "Could not enumerate directories in the path '{ folderPath } ' due to an exception",
402
402
e ) ;
403
-
403
+
404
404
return ;
405
405
}
406
406
@@ -625,6 +625,59 @@ private static string UnescapeDriveColon(string fileUri)
625
625
return sb . ToString ( ) ;
626
626
}
627
627
628
+ /// <summary>
629
+ /// Converts a file system path into a DocumentUri required by Language Server Protocol.
630
+ /// </summary>
631
+ /// <remarks>
632
+ /// When sending a document path to a LSP client, the path must be provided as a
633
+ /// DocumentUri in order to features like the Problems window or peek definition
634
+ /// to be able to open the specified file.
635
+ /// </remarks>
636
+ /// <param name="path">
637
+ /// A file system path. Note: if the path is already a DocumentUri, it will be returned unmodified.
638
+ /// </param>
639
+ /// <returns>The file system path encoded as a DocumentUri.</returns>
640
+ internal static string ConvertPathToDocumentUri ( string path )
641
+ {
642
+ const string fileUriPrefix = "file:///" ;
643
+
644
+ if ( path . StartsWith ( "untitled:" , StringComparison . Ordinal ) )
645
+ {
646
+ return path ;
647
+ }
648
+
649
+ if ( path . StartsWith ( fileUriPrefix , StringComparison . Ordinal ) )
650
+ {
651
+ return path ;
652
+ }
653
+
654
+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
655
+ {
656
+ return new Uri ( path ) . AbsoluteUri ;
657
+ }
658
+
659
+ // VSCode file URIs on Windows need the drive letter lowercase, and the colon
660
+ // URI encoded. System.Uri won't do that, so we manually create the URI.
661
+ var newUri = System . Web . HttpUtility . UrlPathEncode ( path ) ;
662
+ int colonIndex = path . IndexOf ( ':' ) ;
663
+ for ( var i = colonIndex - 1 ; i >= 0 ; i -- )
664
+ {
665
+ newUri . Remove ( i , 1 ) ;
666
+ newUri . Insert ( i , char . ToLowerInvariant ( path [ i ] ) . ToString ( ) ) ;
667
+ }
668
+
669
+ // On a Linux filesystem, you can have multiple colons in a filename e.g. foo:bar:baz.txt
670
+ if ( colonIndex >= 0 )
671
+ {
672
+ newUri = newUri . Replace ( ":" , "%3A" ) ;
673
+ }
674
+
675
+ return newUri
676
+ . Replace ( '\\ ' , '/' )
677
+ . Insert ( 0 , fileUriPrefix )
678
+ . ToString ( ) ;
679
+ }
680
+
628
681
#endregion
629
682
}
630
683
}
0 commit comments