Skip to content

Commit

Permalink
Fix crash when performing symbol operations in untitled file
Browse files Browse the repository at this point in the history
This change fixes a host crash which occurs when the user tries to
perform a symbol operation (like Go to Definition or Find References) in
an untitled script file.  The fix is to not try and convert an untitled
file's path to a Uri.

Resolves PowerShell/vscode-powershell#645
  • Loading branch information
daviwil committed Apr 6, 2017
1 parent 4935c68 commit 180b4c4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ await editorSession.LanguageService.GetDefinitionOfSymbol(
definitionLocations.Add(
new Location
{
Uri = new Uri("file://" + definition.FoundDefinition.FilePath).AbsoluteUri,
Uri = GetFileUri(definition.FoundDefinition.FilePath),
Range = GetRangeFromScriptRegion(definition.FoundDefinition.ScriptRegion)
});
}
Expand Down Expand Up @@ -692,7 +692,7 @@ await editorSession.LanguageService.FindReferencesOfSymbol(
{
return new Location
{
Uri = new Uri("file://" + r.FilePath).AbsoluteUri,
Uri = GetFileUri(r.FilePath),
Range = GetRangeFromScriptRegion(r.ScriptRegion)
};
})
Expand Down Expand Up @@ -936,7 +936,7 @@ protected async Task HandleDocumentSymbolRequest(
Kind = GetSymbolKind(r.SymbolType),
Location = new Location
{
Uri = new Uri("file://" + r.FilePath).AbsolutePath,
Uri = GetFileUri(r.FilePath),
Range = GetRangeFromScriptRegion(r.ScriptRegion)
},
Name = GetDecoratedSymbolName(r)
Expand Down Expand Up @@ -1009,7 +1009,7 @@ protected async Task HandleWorkspaceSymbolRequest(
Kind = r.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function,
Location = new Location
{
Uri = new Uri("file://" + r.FilePath).AbsoluteUri,
Uri = GetFileUri(r.FilePath),
Range = GetRangeFromScriptRegion(r.ScriptRegion)
},
Name = GetDecoratedSymbolName(r)
Expand Down Expand Up @@ -1194,6 +1194,15 @@ await this.SendEvent(

#region Helper Methods

private static string GetFileUri(string filePath)
{
// If the file isn't untitled, return a URI-style path
return
!filePath.StartsWith("untitled")
? new Uri("file://" + filePath).AbsoluteUri
: filePath;
}

private static Range GetRangeFromScriptRegion(ScriptRegion scriptRegion)
{
return new Range
Expand Down

0 comments on commit 180b4c4

Please sign in to comment.