|
9 | 9 | using System.IO;
|
10 | 10 | using System.Security;
|
11 | 11 | using System.Text;
|
12 |
| -using System.Runtime.InteropServices; |
13 | 12 | using Microsoft.Extensions.FileSystemGlobbing;
|
14 | 13 | using Microsoft.Extensions.Logging;
|
15 | 14 | using Microsoft.PowerShell.EditorServices.Utility;
|
@@ -462,17 +461,6 @@ private void RecursivelyFindReferences(
|
462 | 461 | }
|
463 | 462 | }
|
464 | 463 |
|
465 |
| - internal Uri ResolveFileUri(Uri fileUri) |
466 |
| - { |
467 |
| - if (fileUri.IsFile) |
468 |
| - { |
469 |
| - fileUri = WorkspaceService.UnescapeDriveColon(fileUri); |
470 |
| - } |
471 |
| - |
472 |
| - this.logger.LogDebug("Resolved path: " + fileUri.OriginalString); |
473 |
| - return fileUri; |
474 |
| - } |
475 |
| - |
476 | 464 | internal static bool IsPathInMemory(string filePath)
|
477 | 465 | {
|
478 | 466 | bool isInMemory = false;
|
@@ -562,141 +550,6 @@ internal string ResolveRelativeScriptPath(string baseFilePath, string relativePa
|
562 | 550 | return combinedPath;
|
563 | 551 | }
|
564 | 552 |
|
565 |
| - private static Uri UnescapeDriveColon(Uri fileUri) |
566 |
| - { |
567 |
| - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
568 |
| - { |
569 |
| - return fileUri; |
570 |
| - } |
571 |
| - |
572 |
| - string driveSegment = fileUri.Segments[1]; |
573 |
| - // Check here that we have something like "file:///C%3A/" as a prefix (caller must check the file:// part) |
574 |
| - if (!(char.IsLetter(driveSegment[0]) && |
575 |
| - driveSegment[1] == '%' && |
576 |
| - driveSegment[2] == '3' && |
577 |
| - driveSegment[3] == 'A' && |
578 |
| - driveSegment[4] == '/')) |
579 |
| - { |
580 |
| - return fileUri; |
581 |
| - } |
582 |
| - |
583 |
| - // We lost "%3A" and gained ":", so length - 2 |
584 |
| - var sb = new StringBuilder(fileUri.OriginalString.Length - 2); |
585 |
| - sb.Append("file:///"); |
586 |
| - |
587 |
| - // The drive letter. |
588 |
| - sb.Append(driveSegment[0]); |
589 |
| - sb.Append(":/"); |
590 |
| - |
591 |
| - // The rest of the URI after the colon. |
592 |
| - // Skip the first two segments which are / and the drive. |
593 |
| - for (int i = 2; i < fileUri.Segments.Length; i++) |
594 |
| - { |
595 |
| - sb.Append(fileUri.Segments[i]); |
596 |
| - } |
597 |
| - |
598 |
| - return new Uri(sb.ToString()); |
599 |
| - } |
600 |
| - |
601 |
| - /// <summary> |
602 |
| - /// Converts a file system path into a DocumentUri required by Language Server Protocol. |
603 |
| - /// </summary> |
604 |
| - /// <remarks> |
605 |
| - /// When sending a document path to a LSP client, the path must be provided as a |
606 |
| - /// DocumentUri in order to features like the Problems window or peek definition |
607 |
| - /// to be able to open the specified file. |
608 |
| - /// </remarks> |
609 |
| - /// <param name="path"> |
610 |
| - /// A file system path. Note: if the path is already a DocumentUri, it will be returned unmodified. |
611 |
| - /// </param> |
612 |
| - /// <returns>The file system path encoded as a DocumentUri.</returns> |
613 |
| - public static string ConvertPathToDocumentUri(string path) |
614 |
| - { |
615 |
| - const string fileUriPrefix = "file:"; |
616 |
| - const string untitledUriPrefix = "untitled:"; |
617 |
| - |
618 |
| - // If path is already in document uri form, there is nothing to convert. |
619 |
| - if (path.StartsWith(untitledUriPrefix, StringComparison.Ordinal) || |
620 |
| - path.StartsWith(fileUriPrefix, StringComparison.Ordinal)) |
621 |
| - { |
622 |
| - return path; |
623 |
| - } |
624 |
| - |
625 |
| - string escapedPath = Uri.EscapeDataString(path); |
626 |
| - |
627 |
| - // Max capacity of the StringBuilder will be the current escapedPath length |
628 |
| - // plus extra chars for file:///. |
629 |
| - var docUriStrBld = new StringBuilder(escapedPath.Length + fileUriPrefix.Length + 3); |
630 |
| - docUriStrBld.Append(fileUriPrefix).Append("//"); |
631 |
| - |
632 |
| - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
633 |
| - { |
634 |
| - // VSCode file URIs on Windows need the drive letter to be lowercase. Search the |
635 |
| - // original path for colon since a char search (no string culture involved) is |
636 |
| - // faster than a string search. If found, then lowercase the associated drive letter. |
637 |
| - if (path.Contains(':')) |
638 |
| - { |
639 |
| - // A valid, drive-letter based path converted to URI form needs to be prefixed |
640 |
| - // with a / to indicate the path is an absolute path. |
641 |
| - docUriStrBld.Append("/"); |
642 |
| - int prefixLen = docUriStrBld.Length; |
643 |
| - |
644 |
| - docUriStrBld.Append(escapedPath); |
645 |
| - |
646 |
| - // Uri.EscapeDataString goes a bit far, encoding \ chars. Also, VSCode wants / instead of \. |
647 |
| - docUriStrBld.Replace("%5C", "/"); |
648 |
| - |
649 |
| - // Find the first colon after the "file:///" prefix, skipping the first char after |
650 |
| - // the prefix since a Windows path cannot start with a colon. End the check at |
651 |
| - // less than docUriStrBld.Length - 2 since we need to look-ahead two characters. |
652 |
| - for (int i = prefixLen + 1; i < docUriStrBld.Length - 2; i++) |
653 |
| - { |
654 |
| - if ((docUriStrBld[i] == '%') && (docUriStrBld[i + 1] == '3') && (docUriStrBld[i + 2] == 'A')) |
655 |
| - { |
656 |
| - int driveLetterIndex = i - 1; |
657 |
| - char driveLetter = char.ToLowerInvariant(docUriStrBld[driveLetterIndex]); |
658 |
| - docUriStrBld.Replace(docUriStrBld[driveLetterIndex], driveLetter, driveLetterIndex, 1); |
659 |
| - break; |
660 |
| - } |
661 |
| - } |
662 |
| - } |
663 |
| - else |
664 |
| - { |
665 |
| - // This is a Windows path without a drive specifier, must be either a relative or UNC path. |
666 |
| - int prefixLen = docUriStrBld.Length; |
667 |
| - |
668 |
| - docUriStrBld.Append(escapedPath); |
669 |
| - |
670 |
| - // Uri.EscapeDataString goes a bit far, encoding \ chars. Also, VSCode wants / instead of \. |
671 |
| - docUriStrBld.Replace("%5C", "/"); |
672 |
| - |
673 |
| - // The proper URI form for a UNC path is file://server/share. In the case of a UNC |
674 |
| - // path, remove the path's leading // because the file:// prefix already provides it. |
675 |
| - if ((docUriStrBld.Length > prefixLen + 1) && |
676 |
| - (docUriStrBld[prefixLen] == '/') && |
677 |
| - (docUriStrBld[prefixLen + 1] == '/')) |
678 |
| - { |
679 |
| - docUriStrBld.Remove(prefixLen, 2); |
680 |
| - } |
681 |
| - } |
682 |
| - } |
683 |
| - else |
684 |
| - { |
685 |
| - // On non-Windows systems, append the escapedPath and undo the over-aggressive |
686 |
| - // escaping of / done by Uri.EscapeDataString. |
687 |
| - docUriStrBld.Append(escapedPath).Replace("%2F", "/"); |
688 |
| - } |
689 |
| - |
690 |
| - if (!VersionUtils.IsNetCore) |
691 |
| - { |
692 |
| - // ' is not encoded by Uri.EscapeDataString in Windows PowerShell 5.x. |
693 |
| - // This is apparently a difference between .NET Framework and .NET Core. |
694 |
| - docUriStrBld.Replace("'", "%27"); |
695 |
| - } |
696 |
| - |
697 |
| - return docUriStrBld.ToString(); |
698 |
| - } |
699 |
| - |
700 | 553 | #endregion
|
701 | 554 | }
|
702 | 555 | }
|
0 commit comments