diff --git a/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psd1 b/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psd1 index 3289f6235..8b7c9c586 100644 --- a/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psd1 +++ b/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psd1 @@ -1,122 +1,126 @@ -# -# Module manifest for module 'PowerShellEditorServices.VSCode' -# -# Generated by: daviwil -# -# Generated on: 6/16/2017 -# - -@{ - -# Script module or binary module file associated with this manifest. -RootModule = 'PowerShellEditorServices.VSCode.psm1' - -# Version number of this module. -ModuleVersion = '0.1.0' - -# Supported PSEditions -# CompatiblePSEditions = @() - -# ID used to uniquely identify this module -GUID = '8794484f-cfc3-40f1-b88f-a934f403e679' - -# Author of this module -Author = 'Microsoft' - -# Company or vendor of this module -CompanyName = 'Microsoft' - -# Copyright statement for this module -Copyright = '(c) 2017 Microsoft. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.' - -# Minimum version of the Windows PowerShell engine required by this module -# PowerShellVersion = '' - -# Name of the Windows PowerShell host required by this module -# PowerShellHostName = '' - -# Minimum version of the Windows PowerShell host required by this module -# PowerShellHostVersion = '' - -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' - -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' - -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' - -# Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() - -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() - -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() - -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() - -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() - -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() - -# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @() - -# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. -CmdletsToExport = @() - -# Variables to export from this module -VariablesToExport = '*' - -# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() - -# DSC resources to export from this module -# DscResourcesToExport = @() - -# List of all modules packaged with this module -# ModuleList = @() - -# List of all files packaged with this module -# FileList = @() - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() - - # A URL to the license for this module. - LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - # ReleaseNotes = '' - - } # End of PSData hashtable - -} # End of PrivateData hashtable - -# HelpInfo URI of this module -# HelpInfoURI = '' - -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' - -} +# +# Module manifest for module 'PowerShellEditorServices.VSCode' +# +# Generated by: daviwil +# +# Generated on: 6/16/2017 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'PowerShellEditorServices.VSCode.psm1' + +# Version number of this module. +ModuleVersion = '0.1.0' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = '8794484f-cfc3-40f1-b88f-a934f403e679' + +# Author of this module +Author = 'Microsoft' + +# Company or vendor of this module +CompanyName = 'Microsoft' + +# Copyright statement for this module +Copyright = '(c) 2017 Microsoft. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.' + +# Minimum version of the Windows PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @('New-VSCodeHtmlContentView', + 'Show-VSCodeHtmlContentView', + 'Close-VSCodeHtmlContentView', + 'Set-VSCodeHtmlContentView', + 'Write-VSCodeHtmlContentView') + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} diff --git a/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 b/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 index 4ecd517e2..0bc740e6a 100644 --- a/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 +++ b/module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1 @@ -16,3 +16,7 @@ if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) else { Write-Verbose '$psEditor object not found in the session, components will not be registered.' } + +Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object { + . $PSItem.FullName +} diff --git a/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Close-VSCodeHtmlContentView.ps1 b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Close-VSCodeHtmlContentView.ps1 new file mode 100644 index 000000000..f8cf0c9c6 --- /dev/null +++ b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Close-VSCodeHtmlContentView.ps1 @@ -0,0 +1,33 @@ +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +function Close-VSCodeHtmlContentView { + <# + .SYNOPSIS + Closes an HtmlContentView. + + .DESCRIPTION + Closes an HtmlContentView inside of Visual Studio Code if + it is displayed. + + .PARAMETER HtmlContentView + The HtmlContentView to be closed. + + .EXAMPLE + Close-VSCodeHtmlContentView -HtmlContentView $htmlContentView + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [Alias("View")] + [ValidateNotNull()] + [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView] + $HtmlContentView + ) + + process { + $HtmlContentView.Close().Wait(); + } +} diff --git a/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/New-VSCodeHtmlContentView.ps1 b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/New-VSCodeHtmlContentView.ps1 new file mode 100644 index 000000000..b54477a3f --- /dev/null +++ b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/New-VSCodeHtmlContentView.ps1 @@ -0,0 +1,55 @@ +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +function New-VSCodeHtmlContentView { + <# + .SYNOPSIS + Creates a custom view in Visual Studio Code which displays HTML content. + + .DESCRIPTION + Creates a custom view in Visual Studio Code which displays HTML content. + + .PARAMETER Title + The title of the view. + + .PARAMETER ShowInColumn + If specified, causes the new view to be displayed in the specified column. + If unspecified, the Show-VSCodeHtmlContentView cmdlet will need to be used + to display the view. + + .EXAMPLE + # Create a new view called "My Custom View" + $htmlContentView = New-VSCodeHtmlContentView -Title "My Custom View" + + .EXAMPLE + # Create a new view and show it in the second view column + $htmlContentView = New-VSCodeHtmlContentView -Title "My Custom View" -ShowInColumn Two + #> + [CmdletBinding()] + [OutputType([Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView])] + param ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] + $Title, + + [Parameter(Mandatory = $false)] + [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.ViewColumn] + $ShowInColumn + ) + + process { + if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) { + $viewFeature = $psEditor.Components.Get([Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentViews]) + $view = $viewFeature.CreateHtmlContentView($Title).Result + + if ($ShowInColumn) { + $view.Show($ShowInColumn).Wait(); + } + + return $view + } + } +} diff --git a/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Set-VSCodeHtmlContentView.ps1 b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Set-VSCodeHtmlContentView.ps1 new file mode 100644 index 000000000..9ecd9ce4b --- /dev/null +++ b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Set-VSCodeHtmlContentView.ps1 @@ -0,0 +1,48 @@ +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +function Set-VSCodeHtmlContentView { + <# + .SYNOPSIS + Sets the content of an HtmlContentView. + + .DESCRIPTION + Sets the content of an HtmlContentView. If an empty string + is passed, it causes the view's content to be cleared. + + .PARAMETER HtmlContentView + The HtmlContentView where content will be set. + + .PARAMETER HtmlBodyContent + The HTML content that will be placed inside the tag + of the view. + + .EXAMPLE + # Set the view content with an h1 header + Set-VSCodeHtmlContentView -HtmlContentView $htmlContentView -HtmlBodyContent "

Hello world!

" + + .EXAMPLE + # Clear the view + Set-VSCodeHtmlContentView -View $htmlContentView -Content "" + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [Alias("View")] + [ValidateNotNull()] + [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView] + $HtmlContentView, + + [Parameter(Mandatory = $true)] + [Alias("Content")] + [AllowEmptyString()] + [string] + $HtmlBodyContent + ) + + process { + $HtmlContentView.SetContent($HtmlBodyContent).Wait(); + } +} diff --git a/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Show-VSCodeHtmlContentView.ps1 b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Show-VSCodeHtmlContentView.ps1 new file mode 100644 index 000000000..1be803471 --- /dev/null +++ b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Show-VSCodeHtmlContentView.ps1 @@ -0,0 +1,47 @@ +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +function Show-VSCodeHtmlContentView { + <# + .SYNOPSIS + Shows an HtmlContentView. + + .DESCRIPTION + Shows an HtmlContentView that has been created and not shown + yet or has previously been closed. + + .PARAMETER HtmlContentView + The HtmlContentView that will be shown. + + .PARAMETER ViewColumn + If specified, causes the new view to be displayed in the specified column. + + .EXAMPLE + # Shows the view in the first editor column + Show-VSCodeHtmlContentView -HtmlContentView $htmlContentView + + .EXAMPLE + # Shows the view in the third editor column + Show-VSCodeHtmlContentView -View $htmlContentView -Column Three + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [Alias("View")] + [ValidateNotNull()] + [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView] + $HtmlContentView, + + [Parameter(Mandatory = $false)] + [Alias("Column")] + [ValidateNotNull()] + [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.ViewColumn] + $ViewColumn = [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.ViewColumn]::One + ) + + process { + $HtmlContentView.Show($ViewColumn).Wait() + } +} diff --git a/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Write-VSCodeHtmlContentView.ps1 b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Write-VSCodeHtmlContentView.ps1 new file mode 100644 index 000000000..b7a88d5ad --- /dev/null +++ b/module/PowerShellEditorServices.VSCode/Public/HtmlContentView/Write-VSCodeHtmlContentView.ps1 @@ -0,0 +1,46 @@ +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +function Write-VSCodeHtmlContentView { + <# + .SYNOPSIS + Writes an HTML fragment to an HtmlContentView. + + .DESCRIPTION + Writes an HTML fragment to an HtmlContentView. This new fragment + is appended to the existing content, useful in cases where the + output will be appended to an ongoing output stream. + + .PARAMETER HtmlContentView + The HtmlContentView where content will be appended. + + .PARAMETER AppendedHtmlBodyContent + The HTML content that will be appended to the view's element content. + + .EXAMPLE + Write-VSCodeHtmlContentView -HtmlContentView $htmlContentView -AppendedHtmlBodyContent "

Appended content

" + + .EXAMPLE + Write-VSCodeHtmlContentView -View $htmlContentView -Content "

Appended content

" + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [Alias("View")] + [ValidateNotNull()] + [Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView] + $HtmlContentView, + + [Parameter(Mandatory = $true)] + [Alias("Content")] + [ValidateNotNull()] + [string] + $AppendedHtmlBodyContent + ) + + process { + $HtmlContentView.AppendContent($AppendedHtmlBodyContent).Wait(); + } +} diff --git a/src/PowerShellEditorServices.VSCode/ComponentRegistration.cs b/src/PowerShellEditorServices.VSCode/ComponentRegistration.cs index de76c5c33..5ea4422cd 100644 --- a/src/PowerShellEditorServices.VSCode/ComponentRegistration.cs +++ b/src/PowerShellEditorServices.VSCode/ComponentRegistration.cs @@ -5,16 +5,37 @@ using System; using Microsoft.PowerShell.EditorServices.Components; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; using Microsoft.PowerShell.EditorServices.Utility; +using Microsoft.PowerShell.EditorServices.VSCode.CustomViews; namespace Microsoft.PowerShell.EditorServices.VSCode { + /// + /// Methods for registering components from this module into + /// the editor session. + /// public static class ComponentRegistration { + /// + /// Registers the feature components in this module with the + /// host editor. + /// + /// + /// The IComponentRegistry where feature components will be registered. + /// public static void Register(IComponentRegistry components) { ILogger logger = components.Get(); - logger.Write(LogLevel.Normal, "PowerShell Editor Services VS Code module loaded."); + + components.Register( + new HtmlContentViewsFeature( + components.Get(), + logger)); + + logger.Write( + LogLevel.Normal, + "PowerShell Editor Services VS Code module loaded."); } } } diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs new file mode 100644 index 000000000..f212ee968 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs @@ -0,0 +1,73 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using Microsoft.PowerShell.EditorServices.Utility; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + internal abstract class CustomViewBase : ICustomView + { + protected IMessageSender messageSender; + protected ILogger logger; + + public Guid Id { get; private set; } + + public string Title { get; private set; } + + protected CustomViewType ViewType { get; private set; } + + public CustomViewBase( + string viewTitle, + CustomViewType viewType, + IMessageSender messageSender, + ILogger logger) + { + this.Id = Guid.NewGuid(); + this.Title = viewTitle; + this.ViewType = viewType; + this.messageSender = messageSender; + this.logger = logger; + } + + internal Task Create() + { + return + this.messageSender.SendRequest( + NewCustomViewRequest.Type, + new NewCustomViewRequest + { + Id = this.Id, + Title = this.Title, + ViewType = this.ViewType, + }, true); + } + + public Task Show(ViewColumn viewColumn) + { + return + this.messageSender.SendRequest( + ShowCustomViewRequest.Type, + new ShowCustomViewRequest + { + Id = this.Id, + ViewColumn = viewColumn + }, true); + } + + public Task Close() + { + return + this.messageSender.SendRequest( + CloseCustomViewRequest.Type, + new CloseCustomViewRequest + { + Id = this.Id, + }, true); + } + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs new file mode 100644 index 000000000..7e8f2cb50 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using Microsoft.PowerShell.EditorServices.Utility; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + internal abstract class CustomViewFeatureBase + where TView : ICustomView + { + protected IMessageSender messageSender; + protected ILogger logger; + private Dictionary viewIndex; + + public CustomViewFeatureBase( + IMessageSender messageSender, + ILogger logger) + { + this.viewIndex = new Dictionary(); + this.messageSender = messageSender; + this.logger = logger; + } + + protected void AddView(TView view) + { + this.viewIndex.Add(view.Title, view); + } + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewMessages.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewMessages.cs new file mode 100644 index 000000000..d87a5e7f7 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewMessages.cs @@ -0,0 +1,80 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Defines a message for creating a custom view in the editor. + /// + public class NewCustomViewRequest + { + /// + /// The RequestType for this request. + /// + public static readonly + RequestType Type = + RequestType.Create("powerShell/newCustomView"); + + /// + /// Gets or sets the Id of the view. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the title of the view. + /// + public string Title { get; set; } + + /// + /// Gets or sets the view's type. + /// + public CustomViewType ViewType { get; set;} + } + + /// + /// Defines a message for showing a custom view in the editor. + /// + public class ShowCustomViewRequest + { + /// + /// The RequestType for this request. + /// + public static readonly + RequestType Type = + RequestType.Create("powerShell/showCustomView"); + + /// + /// Gets or sets the Id of the view. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the column in which the view should be shown. + /// + public ViewColumn ViewColumn { get; set; } + } + + /// + /// Defines a message for closing a custom view in the editor. + /// + public class CloseCustomViewRequest + { + /// + /// The RequestType for this request. + /// + public static readonly + RequestType Type = + RequestType.Create("powerShell/closeCustomView"); + + /// + /// Gets or sets the Id of the view. + /// + public Guid Id { get; set; } + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewType.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewType.cs new file mode 100644 index 000000000..430a79800 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewType.cs @@ -0,0 +1,18 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Enumerates the available custom view types. + /// + public enum CustomViewType + { + /// + /// An IHtmlContentView. + /// + HtmlContent = 1 + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs new file mode 100644 index 000000000..d1a952ce2 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs @@ -0,0 +1,51 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using Microsoft.PowerShell.EditorServices.Utility; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + internal class HtmlContentView : CustomViewBase, IHtmlContentView + { + public HtmlContentView( + string viewTitle, + IMessageSender messageSender, + ILogger logger) + : base( + viewTitle, + CustomViewType.HtmlContent, + messageSender, + logger) + { + } + + public Task SetContent(string htmlBodyContent) + { + return + this.messageSender.SendRequest( + SetHtmlContentViewRequest.Type, + new SetHtmlContentViewRequest + { + Id = this.Id, + HtmlBodyContent = htmlBodyContent + }, true); + } + + public Task AppendContent(string appendedHtmlBodyContent) + { + return + this.messageSender.SendRequest( + AppendHtmlContentViewRequest.Type, + new AppendHtmlContentViewRequest + { + Id = this.Id, + AppendedHtmlBodyContent = appendedHtmlBodyContent + }, true); + } + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewMessages.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewMessages.cs new file mode 100644 index 000000000..135ee5da2 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewMessages.cs @@ -0,0 +1,56 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Defines a message for setting the content of a HtmlContentView. + /// + public class SetHtmlContentViewRequest + { + /// + /// The RequestType for this request. + /// + public static readonly + RequestType Type = + RequestType.Create("powerShell/setHtmlViewContent"); + + /// + /// Gets or sets the Id of the view. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the HTML body content to set in the view. + /// + public string HtmlBodyContent { get; set; } + } + + /// + /// Defines a message for appending to the content of an IHtmlContentView. + /// + public class AppendHtmlContentViewRequest + { + /// + /// The RequestType for this request. + /// + public static readonly + RequestType Type = + RequestType.Create("powerShell/appendHtmlViewContent"); + + /// + /// Gets or sets the Id of the view. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the HTML body content to append to the view. + /// + public string AppendedHtmlBodyContent { get; set; } + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs new file mode 100644 index 000000000..4ae093c2e --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs @@ -0,0 +1,36 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using Microsoft.PowerShell.EditorServices.Utility; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + internal class HtmlContentViewsFeature : CustomViewFeatureBase, IHtmlContentViews + { + public HtmlContentViewsFeature( + IMessageSender messageSender, + ILogger logger) + : base(messageSender, logger) + { + } + + public async Task CreateHtmlContentView(string viewTitle) + { + HtmlContentView htmlView = + new HtmlContentView( + viewTitle, + this.messageSender, + this.logger); + + await htmlView.Create(); + this.AddView(htmlView); + + return htmlView; + } + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/ICustomView.cs b/src/PowerShellEditorServices.VSCode/CustomViews/ICustomView.cs new file mode 100644 index 000000000..5b52781b3 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/ICustomView.cs @@ -0,0 +1,42 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using Microsoft.PowerShell.EditorServices.Utility; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Defines the interface for an arbitrary custom view that + /// can be shown in Visual Studio Code. + /// + public interface ICustomView + { + /// + /// Gets the unique ID of the view. + /// + Guid Id { get; } + + /// + /// Gets the display title of the view. + /// + string Title { get; } + + /// + /// Shows the view in the specified column. + /// + /// The column in which the view will be shown. + /// A Task which can be awaited for completion. + Task Show(ViewColumn viewColumn); + + /// + /// Closes the view in the editor. + /// + /// A Task which can be awaited for completion. + Task Close(); + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentView.cs b/src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentView.cs new file mode 100644 index 000000000..34ee9ea73 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentView.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Defines the interface for a custom view which displays + /// rendered HTML content in an editor tab. + /// + public interface IHtmlContentView : ICustomView + { + /// + /// Sets the HTML body content of the view. + /// + /// + /// The HTML content that is placed inside of the page's body tag. + /// + /// A Task which can be awaited for completion. + Task SetContent(string htmlBodyContent); + + /// + /// Appends HTML body content to the view. + /// + /// + /// The HTML fragment to be appended to the output stream. + /// + /// A Task which can be awaited for completion. + Task AppendContent(string appendedHtmlBodyContent); + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentViews.cs b/src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentViews.cs new file mode 100644 index 000000000..5b42b4540 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/IHtmlContentViews.cs @@ -0,0 +1,26 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Defines an interface for a component which can create + /// new IHtmlContentView implementation instances. + /// + public interface IHtmlContentViews + { + /// + /// Creates an instance of an IHtmlContentView implementation. + /// + /// The title of the view to create. + /// + /// A Task to await for completion, returns the IHtmlContentView instance. + /// + Task CreateHtmlContentView(string viewTitle); + } +} diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/ViewColumn.cs b/src/PowerShellEditorServices.VSCode/CustomViews/ViewColumn.cs new file mode 100644 index 000000000..7169cf3a5 --- /dev/null +++ b/src/PowerShellEditorServices.VSCode/CustomViews/ViewColumn.cs @@ -0,0 +1,32 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews +{ + /// + /// Defines the possible columns in which a custom view + /// can be displayed. + /// + public enum ViewColumn + { + /// + /// The first view column. + /// + One = 1, + + /// + /// The second view column. + /// + Two, + + /// + /// The third view column. + /// + Three + } +} diff --git a/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj b/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj index a587f2eae..138117cf6 100644 --- a/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj +++ b/src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj @@ -9,6 +9,12 @@ $(PackageTargetFallback);dnxcore50;portable-net45+win8 + + + 1591,1573,1572 + bin\$(TargetFramework)\$(Configuration)\Microsoft.PowerShell.EditorServices.VSCode.xml + +