Skip to content

Commit e98a8b9

Browse files
committed
Add custom HTML views to VSCode module
This change adds support for custom HTML views in the VSCode module which forms the basis for UI extensions in the PowerShell extension in Visual Studio Code. This change includes both .NET PowerShell cmdlet APIs for interacting with custom HTML UI in the editor.
1 parent f0a9dc7 commit e98a8b9

20 files changed

+871
-123
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,126 @@
1-
#
2-
# Module manifest for module 'PowerShellEditorServices.VSCode'
3-
#
4-
# Generated by: daviwil
5-
#
6-
# Generated on: 6/16/2017
7-
#
8-
9-
@{
10-
11-
# Script module or binary module file associated with this manifest.
12-
RootModule = 'PowerShellEditorServices.VSCode.psm1'
13-
14-
# Version number of this module.
15-
ModuleVersion = '0.1.0'
16-
17-
# Supported PSEditions
18-
# CompatiblePSEditions = @()
19-
20-
# ID used to uniquely identify this module
21-
GUID = '8794484f-cfc3-40f1-b88f-a934f403e679'
22-
23-
# Author of this module
24-
Author = 'Microsoft'
25-
26-
# Company or vendor of this module
27-
CompanyName = 'Microsoft'
28-
29-
# Copyright statement for this module
30-
Copyright = '(c) 2017 Microsoft. All rights reserved.'
31-
32-
# Description of the functionality provided by this module
33-
Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.'
34-
35-
# Minimum version of the Windows PowerShell engine required by this module
36-
# PowerShellVersion = ''
37-
38-
# Name of the Windows PowerShell host required by this module
39-
# PowerShellHostName = ''
40-
41-
# Minimum version of the Windows PowerShell host required by this module
42-
# PowerShellHostVersion = ''
43-
44-
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45-
# DotNetFrameworkVersion = ''
46-
47-
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48-
# CLRVersion = ''
49-
50-
# Processor architecture (None, X86, Amd64) required by this module
51-
# ProcessorArchitecture = ''
52-
53-
# Modules that must be imported into the global environment prior to importing this module
54-
# RequiredModules = @()
55-
56-
# Assemblies that must be loaded prior to importing this module
57-
# RequiredAssemblies = @()
58-
59-
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60-
# ScriptsToProcess = @()
61-
62-
# Type files (.ps1xml) to be loaded when importing this module
63-
# TypesToProcess = @()
64-
65-
# Format files (.ps1xml) to be loaded when importing this module
66-
# FormatsToProcess = @()
67-
68-
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69-
# NestedModules = @()
70-
71-
# 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.
72-
FunctionsToExport = @()
73-
74-
# 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.
75-
CmdletsToExport = @()
76-
77-
# Variables to export from this module
78-
VariablesToExport = '*'
79-
80-
# 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.
81-
AliasesToExport = @()
82-
83-
# DSC resources to export from this module
84-
# DscResourcesToExport = @()
85-
86-
# List of all modules packaged with this module
87-
# ModuleList = @()
88-
89-
# List of all files packaged with this module
90-
# FileList = @()
91-
92-
# 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.
93-
PrivateData = @{
94-
95-
PSData = @{
96-
97-
# Tags applied to this module. These help with module discovery in online galleries.
98-
# Tags = @()
99-
100-
# A URL to the license for this module.
101-
LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE'
102-
103-
# A URL to the main website for this project.
104-
ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices'
105-
106-
# A URL to an icon representing this module.
107-
# IconUri = ''
108-
109-
# ReleaseNotes of this module
110-
# ReleaseNotes = ''
111-
112-
} # End of PSData hashtable
113-
114-
} # End of PrivateData hashtable
115-
116-
# HelpInfo URI of this module
117-
# HelpInfoURI = ''
118-
119-
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
120-
# DefaultCommandPrefix = ''
121-
122-
}
1+
#
2+
# Module manifest for module 'PowerShellEditorServices.VSCode'
3+
#
4+
# Generated by: daviwil
5+
#
6+
# Generated on: 6/16/2017
7+
#
8+
9+
@{
10+
11+
# Script module or binary module file associated with this manifest.
12+
RootModule = 'PowerShellEditorServices.VSCode.psm1'
13+
14+
# Version number of this module.
15+
ModuleVersion = '0.1.0'
16+
17+
# Supported PSEditions
18+
# CompatiblePSEditions = @()
19+
20+
# ID used to uniquely identify this module
21+
GUID = '8794484f-cfc3-40f1-b88f-a934f403e679'
22+
23+
# Author of this module
24+
Author = 'Microsoft'
25+
26+
# Company or vendor of this module
27+
CompanyName = 'Microsoft'
28+
29+
# Copyright statement for this module
30+
Copyright = '(c) 2017 Microsoft. All rights reserved.'
31+
32+
# Description of the functionality provided by this module
33+
Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.'
34+
35+
# Minimum version of the Windows PowerShell engine required by this module
36+
# PowerShellVersion = ''
37+
38+
# Name of the Windows PowerShell host required by this module
39+
# PowerShellHostName = ''
40+
41+
# Minimum version of the Windows PowerShell host required by this module
42+
# PowerShellHostVersion = ''
43+
44+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45+
# DotNetFrameworkVersion = ''
46+
47+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48+
# CLRVersion = ''
49+
50+
# Processor architecture (None, X86, Amd64) required by this module
51+
# ProcessorArchitecture = ''
52+
53+
# Modules that must be imported into the global environment prior to importing this module
54+
# RequiredModules = @()
55+
56+
# Assemblies that must be loaded prior to importing this module
57+
# RequiredAssemblies = @()
58+
59+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60+
# ScriptsToProcess = @()
61+
62+
# Type files (.ps1xml) to be loaded when importing this module
63+
# TypesToProcess = @()
64+
65+
# Format files (.ps1xml) to be loaded when importing this module
66+
# FormatsToProcess = @()
67+
68+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69+
# NestedModules = @()
70+
71+
# 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.
72+
FunctionsToExport = @('New-VSCodeHtmlContentView',
73+
'Show-VSCodeHtmlContentView',
74+
'Close-VSCodeHtmlContentView',
75+
'Set-VSCodeHtmlContentView',
76+
'Write-VSCodeHtmlContentView')
77+
78+
# 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.
79+
CmdletsToExport = @()
80+
81+
# Variables to export from this module
82+
VariablesToExport = '*'
83+
84+
# 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.
85+
AliasesToExport = @()
86+
87+
# DSC resources to export from this module
88+
# DscResourcesToExport = @()
89+
90+
# List of all modules packaged with this module
91+
# ModuleList = @()
92+
93+
# List of all files packaged with this module
94+
# FileList = @()
95+
96+
# 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.
97+
PrivateData = @{
98+
99+
PSData = @{
100+
101+
# Tags applied to this module. These help with module discovery in online galleries.
102+
# Tags = @()
103+
104+
# A URL to the license for this module.
105+
LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE'
106+
107+
# A URL to the main website for this project.
108+
ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices'
109+
110+
# A URL to an icon representing this module.
111+
# IconUri = ''
112+
113+
# ReleaseNotes of this module
114+
# ReleaseNotes = ''
115+
116+
} # End of PSData hashtable
117+
118+
} # End of PrivateData hashtable
119+
120+
# HelpInfo URI of this module
121+
# HelpInfoURI = ''
122+
123+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
124+
# DefaultCommandPrefix = ''
125+
126+
}

Diff for: module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject])
1616
else {
1717
Write-Verbose '$psEditor object not found in the session, components will not be registered.'
1818
}
19+
20+
Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object {
21+
. $PSItem.FullName
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
#
5+
6+
function Close-VSCodeHtmlContentView {
7+
<#
8+
.SYNOPSIS
9+
Closes an HtmlContentView.
10+
11+
.DESCRIPTION
12+
Closes an HtmlContentView inside of Visual Studio Code if
13+
it is displayed.
14+
15+
.PARAMETER HtmlContentView
16+
The HtmlContentView to be closed.
17+
18+
.EXAMPLE
19+
Close-VSCodeHtmlContentView -HtmlContentView $htmlContentView
20+
#>
21+
[CmdletBinding()]
22+
param (
23+
[Parameter(Mandatory = $true)]
24+
[Alias("View")]
25+
[ValidateNotNull()]
26+
[Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView]
27+
$HtmlContentView
28+
)
29+
30+
process {
31+
$HtmlContentView.Close().Wait();
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
#
5+
6+
function New-VSCodeHtmlContentView {
7+
<#
8+
.SYNOPSIS
9+
Creates a custom view in Visual Studio Code which displays HTML content.
10+
11+
.DESCRIPTION
12+
Creates a custom view in Visual Studio Code which displays HTML content.
13+
14+
.PARAMETER Title
15+
The title of the view.
16+
17+
.PARAMETER ShowInColumn
18+
If specified, causes the new view to be displayed in the specified column.
19+
If unspecified, the Show-VSCodeHtmlContentView cmdlet will need to be used
20+
to display the view.
21+
22+
.EXAMPLE
23+
# Create a new view called "My Custom View"
24+
$htmlContentView = New-VSCodeHtmlContentView -Title "My Custom View"
25+
26+
.EXAMPLE
27+
# Create a new view and show it in the second view column
28+
$htmlContentView = New-VSCodeHtmlContentView -Title "My Custom View" -ShowInColumn Two
29+
#>
30+
[CmdletBinding()]
31+
[OutputType([Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView])]
32+
param (
33+
[Parameter(Mandatory = $true)]
34+
[ValidateNotNullOrEmpty()]
35+
[string]
36+
$Title,
37+
38+
[Parameter(Mandatory = $false)]
39+
[Microsoft.PowerShell.EditorServices.VSCode.CustomViews.ViewColumn]
40+
$ShowInColumn
41+
)
42+
43+
process {
44+
if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) {
45+
$viewFeature = $psEditor.Components.Get([Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentViews])
46+
$view = $viewFeature.CreateHtmlContentView($Title).Result
47+
48+
if ($ShowInColumn) {
49+
$view.Show($ShowInColumn).Wait();
50+
}
51+
52+
return $view
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
#
5+
6+
function Set-VSCodeHtmlContentView {
7+
<#
8+
.SYNOPSIS
9+
Sets the content of an HtmlContentView.
10+
11+
.DESCRIPTION
12+
Sets the content of an HtmlContentView. If an empty string
13+
is passed, it causes the view's content to be cleared.
14+
15+
.PARAMETER HtmlContentView
16+
The HtmlContentView where content will be set.
17+
18+
.PARAMETER HtmlBodyContent
19+
The HTML content that will be placed inside the <body> tag
20+
of the view.
21+
22+
.EXAMPLE
23+
# Set the view content with an h1 header
24+
Set-VSCodeHtmlContentView -HtmlContentView $htmlContentView -HtmlBodyContent "<h1>Hello world!</h1>"
25+
26+
.EXAMPLE
27+
# Clear the view
28+
Set-VSCodeHtmlContentView -View $htmlContentView -Content ""
29+
#>
30+
[CmdletBinding()]
31+
param (
32+
[Parameter(Mandatory = $true)]
33+
[Alias("View")]
34+
[ValidateNotNull()]
35+
[Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView]
36+
$HtmlContentView,
37+
38+
[Parameter(Mandatory = $true)]
39+
[Alias("Content")]
40+
[AllowEmptyString()]
41+
[string]
42+
$HtmlBodyContent
43+
)
44+
45+
process {
46+
$HtmlContentView.SetContent($HtmlBodyContent).Wait();
47+
}
48+
}

0 commit comments

Comments
 (0)