Skip to content

Delete projects we wont be keeping around and get pses.vscode working again #1046

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
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ public class NewVSCodeHtmlContentViewCommand : PSCmdlet

private ILogger _logger;

private ViewColumn? _showInColumn;

///
[Parameter(Mandatory = true, Position = 0)]
[ValidateNotNullOrEmpty]
public string Title { get; set; }

///
[Parameter(Position = 1)]
public ViewColumn? ShowInColumn { get; set; }

///
protected override void BeginProcessing()
public ViewColumn ShowInColumn
{
get => _showInColumn.GetValueOrDefault();
set => _showInColumn = value;
}

///
protected override void ProcessRecord()
protected override void BeginProcessing()
{
if (_htmlContentViewsFeature == null)
{
Expand All @@ -53,25 +54,27 @@ protected override void ProcessRecord()
}
else
{
throw new Exception("unable to fetch psEditor value");
WriteError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this is a non-terminating error.

Would it be better as a terminating error, since not being able to find the PSEditor object we won't be able to proceed meaningfully?

Terminating here wouldn't kill a script, just a pipeline, so it would operate with the desired effect I think.

ThrowTerminatingError(
    new ErrorRecord(
        new ItemNotFoundException("Cannot find the '$psEditor' variable"),
        "PSEditorNotFound",
        ErrorCategory.ObjectNotFound,
        targetObject: null));
return;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense. Updated!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't kill the script, but in general I prefer non-terminating because that lets the user easily handle errors with the -ErrorAction common parameter. With a terminating error, you have to try/catch, so I try to leave that for rare catastrophic errors.

I don't feel particularly strongly about not using terminating in this particular case though, just adding some more information.

new ErrorRecord(
new ItemNotFoundException("Cannot find a variable with the name 'psEditor'."),
"PSEditorNotFound",
ErrorCategory.ObjectNotFound,
targetObject: null));

return;
}
}

IHtmlContentView view = _htmlContentViewsFeature.CreateHtmlContentViewAsync(Title)
.GetAwaiter()
.GetResult();

if (ShowInColumn != null) {
view.Show(ShowInColumn.Value).GetAwaiter().GetResult();
if (_showInColumn != null) {
view.Show(_showInColumn.Value).GetAwaiter().GetResult();
}

WriteObject(view);
}

///
protected override void EndProcessing()
{
}
}

///
Expand Down Expand Up @@ -100,23 +103,13 @@ public class SetVSCodeHtmlContentViewCommand : PSCmdlet

///
protected override void BeginProcessing()
{
}

///
protected override void ProcessRecord()
{
var htmlContent = new HtmlContent();
htmlContent.BodyContent = HtmlBodyContent;
htmlContent.JavaScriptPaths = JavaScriptPaths;
htmlContent.StyleSheetPaths = StyleSheetPaths;
HtmlContentView.SetContentAsync(htmlContent).GetAwaiter().GetResult();
}

///
protected override void EndProcessing()
{
}
}

///
Expand All @@ -131,19 +124,9 @@ public class CloseVSCodeHtmlContentViewCommand : PSCmdlet

///
protected override void BeginProcessing()
{
}

///
protected override void ProcessRecord()
{
HtmlContentView.Close().GetAwaiter().GetResult();
}

///
protected override void EndProcessing()
{
}
}

///
Expand All @@ -164,19 +147,9 @@ public class ShowVSCodeHtmlContentViewCommand : PSCmdlet

///
protected override void BeginProcessing()
{
}

///
protected override void ProcessRecord()
{
HtmlContentView.Show(ViewColumn).GetAwaiter().GetResult();
}

///
protected override void EndProcessing()
{
}
}

///
Expand All @@ -195,20 +168,10 @@ public class WriteVSCodeHtmlContentViewCommand : PSCmdlet
[ValidateNotNull]
public string AppendedHtmlBodyContent { get; set; }

///
protected override void BeginProcessing()
{
}

///
protected override void ProcessRecord()
{
HtmlContentView.AppendContentAsync(AppendedHtmlBodyContent).GetAwaiter().GetResult();
}

///
protected override void EndProcessing()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CustomViewBase(
internal async Task CreateAsync()
{
await languageServer.SendRequest(
"powerShell/newCustomView",
NewCustomViewRequest.Method,
new NewCustomViewRequest
{
Id = this.Id,
Expand All @@ -51,7 +51,7 @@ await languageServer.SendRequest(
public async Task Show(ViewColumn viewColumn)
{
await languageServer.SendRequest(
"powerShell/showCustomView",
ShowCustomViewRequest.Method,
new ShowCustomViewRequest
{
Id = this.Id,
Expand All @@ -63,7 +63,7 @@ await languageServer.SendRequest(
public async Task Close()
{
await languageServer.SendRequest(
"powerShell/closeCustomView",
CloseCustomViewRequest.Method,
new CloseCustomViewRequest
{
Id = this.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews
/// </summary>
public class NewCustomViewRequest
{
/// <summary>
/// The Language Server Protocol 'method'.
/// </summary>
public static string Method => "powerShell/newCustomView";

/// <summary>
/// Gets or sets the Id of the view.
/// </summary>
Expand All @@ -33,6 +38,11 @@ public class NewCustomViewRequest
/// </summary>
public class ShowCustomViewRequest
{
/// <summary>
/// The Language Server Protocol 'method'.
/// </summary>
public static string Method => "powerShell/showCustomView";

/// <summary>
/// Gets or sets the Id of the view.
/// </summary>
Expand All @@ -49,6 +59,11 @@ public class ShowCustomViewRequest
/// </summary>
public class CloseCustomViewRequest
{
/// <summary>
/// The Language Server Protocol 'method'.
/// </summary>
public static string Method => "powerShell/closeCustomView";

/// <summary>
/// Gets or sets the Id of the view.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public HtmlContentView(
public async Task SetContentAsync(string htmlBodyContent)
{
await languageServer.SendRequest(
"powerShell/setHtmlViewContent",
SetHtmlContentViewRequest.Method,
new SetHtmlContentViewRequest
{
Id = this.Id,
Expand All @@ -49,7 +49,7 @@ public async Task SetContentAsync(HtmlContent htmlContent)
};

await languageServer.SendRequest(
"powerShell/setHtmlViewContent",
SetHtmlContentViewRequest.Method,
new SetHtmlContentViewRequest
{
Id = this.Id,
Expand All @@ -61,7 +61,7 @@ await languageServer.SendRequest(
public async Task AppendContentAsync(string appendedHtmlBodyContent)
{
await languageServer.SendRequest(
"powerShell/appendHtmlViewContent",
AppendHtmlContentViewRequest.Method,
new AppendHtmlContentViewRequest
{
Id = this.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews
/// </summary>
public class SetHtmlContentViewRequest
{
/// <summary>
/// The Language Server Protocol 'method'.
/// </summary>
public static string Method => "powerShell/setHtmlViewContent";

/// <summary>
/// Gets or sets the Id of the view.
/// </summary>
Expand All @@ -28,6 +33,11 @@ public class SetHtmlContentViewRequest
/// </summary>
public class AppendHtmlContentViewRequest
{
/// <summary>
/// The Language Server Protocol 'method'.
/// </summary>
public static string Method => "powerShell/appendHtmlViewContent";

/// <summary>
/// Gets or sets the Id of the view.
/// </summary>
Expand Down