Skip to content

Commit bfc19d5

Browse files
authored
Merge branch 'master' into release/1.4.2
2 parents 7a31917 + c84b614 commit bfc19d5

File tree

11 files changed

+103
-30
lines changed

11 files changed

+103
-30
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "2.0.0",
33

44
"windows": {
5-
"command": "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
5+
"command": "${env:windir}/System32/WindowsPowerShell/v1.0/powershell.exe",
66
"args": [ "-NoProfile", "-ExecutionPolicy", "Bypass" ]
77
},
88
"linux": {
@@ -14,8 +14,6 @@
1414
"args": [ "-NoProfile" ]
1515
},
1616

17-
"showOutput": "always",
18-
1917
"tasks": [
2018
{
2119
"taskName": "Install",

ISSUE_TEMPLATE.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<!--
22
3-
Please fill in these details so that we can help you!
3+
BEFORE SUBMITTING A NEW ISSUE, PLEASE READ THE FAQ!!
4+
https://github.com/PowerShell/vscode-powershell/wiki/FAQ
45
5-
If you are filing an issue related to PowerShell syntax coloring/highlighting,
6-
please file it at the EditorSyntax repo:
6+
If your issue is not addressed by the FAQ, please
7+
fill in the following details so that we can help you!
78
8-
https://github.com/PowerShell/EditorSyntax/issues
9+
The more repro details you can provide, along with a zip
10+
of the log files from your session, the better the chances
11+
are for a quick resolution.
912
1013
-->
1114

@@ -17,7 +20,7 @@ https://github.com/PowerShell/EditorSyntax/issues
1720
- Output from `$PSVersionTable`:
1821

1922
```
20-
Copy / paste the below commands into the PowerShell Integrated Terminal, and paste the output here
23+
Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:
2124
2225
code -v
2326
$pseditor.EditorServicesVersion

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ that Visual Studio Code provides.
1919
Read the [installation instructions](https://github.com/PowerShell/PowerShell/blob/master/docs/learning-powershell/using-vscode.md)
2020
to get more details on how to use the extension on these platforms.
2121

22+
Read the [FAQ](https://github.com/PowerShell/vscode-powershell/wiki/FAQ) for answers to common questions.
23+
2224
## Features
2325

2426
- Syntax highlighting

examples/.vscode/tasks.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
// Start PowerShell
3535
"windows": {
36-
"command": "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
36+
"command": "${env:windir}/System32/WindowsPowerShell/v1.0/powershell.exe",
3737
"args": [ "-NoProfile", "-ExecutionPolicy", "Bypass" ]
3838
},
3939
"linux": {
@@ -45,15 +45,11 @@
4545
"args": [ "-NoProfile" ]
4646
},
4747

48-
// Show the output window always
49-
"showOutput": "always",
50-
5148
// Associate with test task runner
5249
"tasks": [
5350
{
5451
"taskName": "Clean",
5552
"suppressTaskName": true,
56-
"showOutput": "always",
5753
"args": [
5854
"Write-Host 'Invoking PSake...'; Invoke-PSake build.ps1 -taskList Clean;",
5955
"Invoke-Command { Write-Host 'Completed Clean task in task runner.' }"
@@ -63,7 +59,6 @@
6359
"taskName": "Build",
6460
"suppressTaskName": true,
6561
"isBuildCommand": true,
66-
"showOutput": "always",
6762
"args": [
6863
"Write-Host 'Invoking PSake...'; Invoke-PSake build.ps1 -taskList Build;",
6964
"Invoke-Command { Write-Host 'Completed Build task in task runner.' }"
@@ -72,7 +67,6 @@
7267
{
7368
"taskName": "Publish",
7469
"suppressTaskName": true,
75-
"showOutput": "always",
7670
"args": [
7771
"Write-Host 'Invoking PSake...'; Invoke-PSake build.ps1 -taskList Publish;",
7872
"Invoke-Command { Write-Host 'Completed Publish task in task runner.' }"
@@ -82,9 +76,8 @@
8276
"taskName": "Test",
8377
"suppressTaskName": true,
8478
"isTestCommand": true,
85-
"showOutput": "always",
8679
"args": [
87-
"Write-Host 'Invoking Pester...'; Invoke-Pester -PesterOption @{IncludeVSCodeMarker=$true};",
80+
"Write-Host 'Invoking Pester...'; $ProgressPreference = 'SilentlyContinue'; Invoke-Pester -PesterOption @{IncludeVSCodeMarker=$true};",
8881
"Invoke-Command { Write-Host 'Completed Test task in task runner.' }"
8982
],
9083
"problemMatcher": "$pester"

examples/Assets/script.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var h1 = document.createElement('h1');
2+
h1.appendChild(document.createTextNode('Hello from JavaScript!'));
3+
document.body.appendChild(h1);

examples/Assets/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
color: white;
3+
background-color: cornflowerblue;
4+
}

examples/ContentViewTest.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$params = @{
2+
HtmlBodyContent = "Testing JavaScript and CSS paths..."
3+
JavaScriptPaths = ".\Assets\script.js"
4+
StyleSheetPaths = ".\Assets\style.css"
5+
}
6+
7+
$view = New-VSCodeHtmlContentView -Title "Test View" -ShowInColumn Two
8+
Set-VSCodeHtmlContentView -View $view @params

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"devDependencies": {
4343
"@types/node": "^6.0.40",
44-
"typescript": "^2.0.3",
44+
"typescript": "2.3.x",
4545
"vsce": "^1.18.0",
4646
"vscode": "^1.1.0",
4747
"mocha": "^2.3.3",
@@ -75,7 +75,7 @@
7575
},
7676
{
7777
"command": "PowerShell.OpenInISE",
78-
"key": "ctrl+shift+i",
78+
"key": "shift+alt+i",
7979
"when": "editorTextFocus && editorLangId == 'powershell'"
8080
}
8181
],
@@ -230,14 +230,14 @@
230230
}
231231
},
232232
{
233-
"label": "PowerShell: Launch - Current File w/Args Prompt",
233+
"label": "PowerShell: Launch Current File w/Args Prompt",
234234
"description": "Launch current file (in active editor window) under debugger, prompting first for script arguments",
235235
"body": {
236236
"type": "PowerShell",
237237
"request": "launch",
238238
"name": "PowerShell Launch Current File w/Args Prompt",
239239
"script": "^\"\\${file}\"",
240-
"args": [],
240+
"args": [ "^\"\\${command:SpecifyScriptArgs}\"" ],
241241
"cwd": "^\"\\${file}\""
242242
}
243243
},

scripts/Start-EditorServices.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ param(
4444
[ValidateNotNullOrEmpty()]
4545
$LogPath,
4646

47-
[ValidateSet("Normal", "Verbose", "Error")]
47+
[ValidateSet("Normal", "Verbose", "Error", "Diagnostic")]
4848
$LogLevel,
4949

5050
[Parameter(Mandatory=$true)]

src/features/CustomViews.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class CustomViewsFeature implements IFeature {
5050
args => {
5151
this.contentProvider.setHtmlContentView(
5252
args.id,
53-
args.htmlBodyContent);
53+
args.htmlContent);
5454
});
5555

5656
languageClient.onRequest(
@@ -119,7 +119,7 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider {
119119
)
120120
}
121121

122-
public setHtmlContentView(id: string, content: string) {
122+
public setHtmlContentView(id: string, content: HtmlContent) {
123123
let uriString = this.getUri(id);
124124
let view: CustomView = this.viewIndex[uriString];
125125

@@ -160,7 +160,11 @@ abstract class CustomView {
160160

161161
class HtmlContentView extends CustomView {
162162

163-
private htmlContent: string = "";
163+
private htmlContent: HtmlContent = {
164+
bodyContent: "",
165+
javaScriptPaths: [],
166+
styleSheetPaths: []
167+
};
164168

165169
constructor(
166170
id: string,
@@ -169,17 +173,49 @@ class HtmlContentView extends CustomView {
169173
super(id, title, CustomViewType.HtmlContent);
170174
}
171175

172-
setContent(htmlContent: string) {
176+
setContent(htmlContent: HtmlContent) {
173177
this.htmlContent = htmlContent;
174178
}
175179

176180
appendContent(content: string) {
177-
this.htmlContent += content;
181+
this.htmlContent.bodyContent += content;
178182
}
179183

180184
getContent(): string {
181-
// Return an HTML page which disables JavaScript in content by default
182-
return `<html><head><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src *; style-src 'self'; script-src 'none';"></head><body>${this.htmlContent}</body></html>`;
185+
var styleSrc = "none";
186+
var styleTags = "";
187+
188+
function getNonce(): number {
189+
return Math.floor(Math.random() * 100000) + 100000;
190+
}
191+
192+
if (this.htmlContent.styleSheetPaths &&
193+
this.htmlContent.styleSheetPaths.length > 0) {
194+
styleSrc = "";
195+
this.htmlContent.styleSheetPaths.forEach(
196+
p => {
197+
var nonce = getNonce();
198+
styleSrc += `'nonce-${nonce}' `;
199+
styleTags += `<link nonce="${nonce}" href="${p}" rel="stylesheet" type="text/css" />\n`;
200+
});
201+
}
202+
203+
var scriptSrc = "none";
204+
var scriptTags = "";
205+
206+
if (this.htmlContent.javaScriptPaths &&
207+
this.htmlContent.javaScriptPaths.length > 0) {
208+
scriptSrc = "";
209+
this.htmlContent.javaScriptPaths.forEach(
210+
p => {
211+
var nonce = getNonce();
212+
scriptSrc += `'nonce-${nonce}' `;
213+
scriptTags += `<script nonce="${nonce}" src="${p}"></script>\n`;
214+
});
215+
}
216+
217+
// Return an HTML page with the specified content
218+
return `<html><head><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src *; style-src ${styleSrc}; script-src ${scriptSrc};">${styleTags}</head><body>\n${this.htmlContent.bodyContent}\n${scriptTags}</body></html>`;
183219
}
184220
}
185221

@@ -226,9 +262,15 @@ namespace SetHtmlContentViewRequest {
226262
'powerShell/setHtmlViewContent');
227263
}
228264

265+
interface HtmlContent {
266+
bodyContent: string;
267+
javaScriptPaths: string[];
268+
styleSheetPaths: string[];
269+
}
270+
229271
interface SetHtmlContentViewRequestArguments {
230272
id: string;
231-
htmlBodyContent: string;
273+
htmlContent: HtmlContent;
232274
}
233275

234276
namespace AppendHtmlOutputViewRequest {

0 commit comments

Comments
 (0)