Skip to content

Fix crash when performing symbol operations in untitled file #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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