Skip to content

Commit b9250dd

Browse files
committed
Fix issue with reference code lens not working with UNC paths
1 parent 8c66fa9 commit b9250dd

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/PowerShellEditorServices/Workspace/Workspace.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ private static string UnescapeDriveColon(string fileUri)
639639
/// <returns>The file system path encoded as a DocumentUri.</returns>
640640
public static string ConvertPathToDocumentUri(string path)
641641
{
642-
const string fileUriPrefix = "file:///";
642+
const string fileUriPrefix = "file:";
643643
const string untitledUriPrefix = "untitled:";
644644

645645
// If path is already in document uri form, there is nothing to convert.
@@ -685,7 +685,15 @@ public static string ConvertPathToDocumentUri(string path)
685685
}
686686

687687
// ' is not always encoded. I've seen this in Windows PowerShell.
688-
return docUriStrBld.Replace("'", "%27").Insert(0, fileUriPrefix).ToString();
688+
docUriStrBld.Replace("'", "%27");
689+
690+
// Insert /// unless path is a UNC path in which case the proper URI form is file://server/share.
691+
if ((docUriStrBld.Length < 2) || ((docUriStrBld[0] != '/') && (docUriStrBld[1] != '/')))
692+
{
693+
docUriStrBld.Insert(0, "///");
694+
}
695+
696+
return docUriStrBld.Insert(0, fileUriPrefix).ToString();
689697
}
690698

691699
#endregion

test/PowerShellEditorServices.Test/Session/ScriptFileTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,14 @@ public void DocumentUriRetunsCorrectStringForAbsolutePath()
595595
scriptFile = new ScriptFile(path, path, emptyStringReader, PowerShellVersion);
596596
Assert.Equal("file:///c%3A/Users/AmosBurton/projects/Rocinate/ProtoMolecule.ps1", scriptFile.DocumentUri);
597597

598-
path = @"c:\Users\BobbyDraper\projects\Rocinate\foo's_~#-[@] +,;=%.ps1";
598+
path = @"c:\Users\BobbieDraper\projects\Rocinate\foo's_~#-[@] +,;=%.ps1";
599599
scriptFile = new ScriptFile(path, path, emptyStringReader, PowerShellVersion);
600-
Assert.Equal("file:///c%3A/Users/BobbyDraper/projects/Rocinate/foo%27s_~%23-%5B%40%5D%20%2B%2C%3B%3D%25.ps1", scriptFile.DocumentUri);
600+
Assert.Equal("file:///c%3A/Users/BobbieDraper/projects/Rocinate/foo%27s_~%23-%5B%40%5D%20%2B%2C%3B%3D%25.ps1", scriptFile.DocumentUri);
601+
602+
// Test UNC path
603+
path = @"\\ClarissaMao\projects\Rocinate\foo's_~#-[@] +,;=%.ps1";
604+
scriptFile = new ScriptFile(path, path, emptyStringReader, PowerShellVersion);
605+
Assert.Equal("file://ClarissaMao/projects/Rocinate/foo%27s_~%23-%5B%40%5D%20%2B%2C%3B%3D%25.ps1", scriptFile.DocumentUri);
601606
}
602607
else
603608
{
@@ -606,9 +611,9 @@ public void DocumentUriRetunsCorrectStringForAbsolutePath()
606611
scriptFile = new ScriptFile(path, path, emptyStringReader, PowerShellVersion);
607612
Assert.Equal("file:///home/AlexKamal/projects/Rocinate/ProtoMolecule.ps1", scriptFile.DocumentUri);
608613

609-
path = "/home/BobbyDraper/projects/Rocinate/foo's_~#-[@] +,;=%.ps1";
614+
path = "/home/BobbieDraper/projects/Rocinate/foo's_~#-[@] +,;=%.ps1";
610615
scriptFile = new ScriptFile(path, path, emptyStringReader, PowerShellVersion);
611-
Assert.Equal("file:///home/BobbyDraper/projects/Rocinate/foo%27s_~%23-%5B%40%5D%20%2B%2C%3B%3D%25.ps1", scriptFile.DocumentUri);
616+
Assert.Equal("file:///home/BobbieDraper/projects/Rocinate/foo%27s_~%23-%5B%40%5D%20%2B%2C%3B%3D%25.ps1", scriptFile.DocumentUri);
612617

613618
path = "/home/NaomiNagata/projects/Rocinate/Proto:Mole:cule.ps1";
614619
scriptFile = new ScriptFile(path, path, emptyStringReader, PowerShellVersion);

0 commit comments

Comments
 (0)