Skip to content

Commit 24d86cf

Browse files
authored
Merge pull request #429 from daviwil/fix-vsc-645
Fix crash when performing symbol operations in untitled file
2 parents 4935c68 + 180b4c4 commit 24d86cf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ await editorSession.LanguageService.GetDefinitionOfSymbol(
653653
definitionLocations.Add(
654654
new Location
655655
{
656-
Uri = new Uri("file://" + definition.FoundDefinition.FilePath).AbsoluteUri,
656+
Uri = GetFileUri(definition.FoundDefinition.FilePath),
657657
Range = GetRangeFromScriptRegion(definition.FoundDefinition.ScriptRegion)
658658
});
659659
}
@@ -692,7 +692,7 @@ await editorSession.LanguageService.FindReferencesOfSymbol(
692692
{
693693
return new Location
694694
{
695-
Uri = new Uri("file://" + r.FilePath).AbsoluteUri,
695+
Uri = GetFileUri(r.FilePath),
696696
Range = GetRangeFromScriptRegion(r.ScriptRegion)
697697
};
698698
})
@@ -936,7 +936,7 @@ protected async Task HandleDocumentSymbolRequest(
936936
Kind = GetSymbolKind(r.SymbolType),
937937
Location = new Location
938938
{
939-
Uri = new Uri("file://" + r.FilePath).AbsolutePath,
939+
Uri = GetFileUri(r.FilePath),
940940
Range = GetRangeFromScriptRegion(r.ScriptRegion)
941941
},
942942
Name = GetDecoratedSymbolName(r)
@@ -1009,7 +1009,7 @@ protected async Task HandleWorkspaceSymbolRequest(
10091009
Kind = r.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function,
10101010
Location = new Location
10111011
{
1012-
Uri = new Uri("file://" + r.FilePath).AbsoluteUri,
1012+
Uri = GetFileUri(r.FilePath),
10131013
Range = GetRangeFromScriptRegion(r.ScriptRegion)
10141014
},
10151015
Name = GetDecoratedSymbolName(r)
@@ -1194,6 +1194,15 @@ await this.SendEvent(
11941194

11951195
#region Helper Methods
11961196

1197+
private static string GetFileUri(string filePath)
1198+
{
1199+
// If the file isn't untitled, return a URI-style path
1200+
return
1201+
!filePath.StartsWith("untitled")
1202+
? new Uri("file://" + filePath).AbsoluteUri
1203+
: filePath;
1204+
}
1205+
11971206
private static Range GetRangeFromScriptRegion(ScriptRegion scriptRegion)
11981207
{
11991208
return new Range

0 commit comments

Comments
 (0)