Skip to content

Commit 93243a9

Browse files
Initial Notebook UI Mode in VS Code Insiders (#2789)
* initial changes * add activation event * add block comment support * add saveMarkdownCellsAs setting * set metadata in new cells on save * actually work across files * updated API with metadata * refactor based on option and new Kernel type * add github action and proposed * add pwsh * remove old * trigger PR * add log * force cron to trigger * time * time * time * better titles * powershell comments * remove not needed comments * use githubrunnumber * use run_id * Update Notebook dts (#3) Co-authored-by: TylerLeonhardt <[email protected]> * better check for registering * Update Notebook dts (#4) Co-authored-by: TylerLeonhardt <[email protected]> * rob's feedback * Add a few tests * added save test * move to utils.sleep * fix regex * add logger * Codacy part 1 * Codacy part 2 * Update Notebook dts (#5) Co-authored-by: TylerLeonhardt <[email protected]> * move GitHub Action to use master Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: TylerLeonhardt <[email protected]> Co-authored-by: Tyler Leonhardt (POWERSHELL) <[email protected]>
1 parent 56800c0 commit 93243a9

23 files changed

+1355
-22
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: "Update Notebook API"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: 0 22 * * *
8+
9+
jobs:
10+
Update-Notebook-Api:
11+
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
shell: pwsh
16+
17+
steps:
18+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup Node.js environment
22+
uses: actions/[email protected]
23+
24+
- name: Rename proposed dts to old
25+
run: Move-Item ./vscode.proposed.d.ts ./old.vscode.proposed.d.ts
26+
27+
- name: npm install
28+
run: npm install
29+
30+
- name: Get latest proposed dts
31+
run: npm run download-api
32+
33+
- name: Generate new dts and compare it with the old one
34+
run: |
35+
# This will contain the content of our new file
36+
$fullFile = [System.Collections.Generic.List[string]]@()
37+
$dts = Get-Content ./vscode.proposed.d.ts
38+
39+
# First add everything up to the declare statement
40+
$index = 0
41+
while ($dts[$index] -notmatch "declare module 'vscode' {") {
42+
$fullFile += $dts[$index]
43+
$index++
44+
}
45+
46+
# Add the declare statement
47+
$fullFile += $dts[$index]
48+
49+
# Find the Notebook region start index
50+
for ( $i = $index; $i -lt $dts.Length; $i++) {
51+
if($dts[$i] -match '//#region @rebornix: Notebook') {
52+
$index = $i
53+
break
54+
}
55+
}
56+
57+
# Add everything until the endregion to the new file
58+
while ($dts[$index] -notmatch "//#endregion") {
59+
$fullFile += $dts[$index]
60+
$index++
61+
}
62+
63+
# Add the endregion line and ending brace line
64+
$fullFile += $dts[$index]
65+
$fullFile += '}'
66+
67+
# Overwrite the file with the new content
68+
$fullFile | Set-Content ./vscode.proposed.d.ts
69+
70+
# Get the old and new files' raw text
71+
$oldFile = Get-Content ./old.vscode.proposed.d.ts -Raw
72+
$newFile = Get-Content ./vscode.proposed.d.ts -Raw
73+
74+
# Compare them and log if they are different
75+
if($oldFile -ne $newFile) {
76+
Write-Host "New changes detected!"
77+
}
78+
79+
# Remove the old file so it doesn't get picked up by tsc
80+
Remove-Item ./old.vscode.proposed.d.ts -Force
81+
82+
- name: Compile the TypeScript to check for errors
83+
run: npm run compile
84+
85+
- name: Create Pull Request
86+
if: github.event_name == 'schedule'
87+
id: cpr
88+
uses: peter-evans/create-pull-request@v2
89+
env:
90+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
91+
with:
92+
commit-message: "Update Notebook dts"
93+
committer: GitHub <[email protected]>
94+
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
95+
title: "Update Notebook dts"
96+
assignees: TylerLeonhardt
97+
reviewers: TylerLeonhardt
98+
base: master
99+
draft: false
100+
branch: powershell-notebook-patch-${{ github.run_id }}
101+
labels: Created_by_Action

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ npm-debug.log
1414
.vscode-test/
1515
*.DS_Store
1616
test-results.xml
17+
vscode.d.ts

.vscode/launch.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
"request": "launch",
3030
"runtimeExecutable": "${execPath}",
3131
"args": [
32+
"--disable-extensions",
33+
"--enable-proposed-api", "ms-vscode.powershell-preview",
3234
"--extensionDevelopmentPath=${workspaceFolder}",
33-
"--extensionTestsPath=${workspaceFolder}/out/test/testRunner.js" ],
35+
"--extensionTestsPath=${workspaceFolder}/out/test/testRunner.js",
36+
"${workspaceFolder}/test"
37+
],
3438
"outFiles": ["${workspaceFolder}/out/**/*.js"],
3539
"preLaunchTask": "Build"
3640
}

package-lock.json

+70-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+64-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publisher": "ms-vscode",
77
"description": "(Preview) Develop PowerShell scripts in Visual Studio Code!",
88
"engines": {
9-
"vscode": "^1.43.0"
9+
"vscode": "^1.44.0"
1010
},
1111
"license": "SEE LICENSE IN LICENSE.txt",
1212
"homepage": "https://github.com/PowerShell/vscode-powershell/blob/master/README.md",
@@ -26,6 +26,7 @@
2626
"url": "https://github.com/PowerShell/vscode-powershell.git"
2727
},
2828
"main": "./out/src/main",
29+
"enableProposedApi": true,
2930
"activationEvents": [
3031
"onDebugInitialConfigurations",
3132
"onDebugResolve:PowerShell",
@@ -43,7 +44,8 @@
4344
"onCommand:PowerShell.RegisterExternalExtension",
4445
"onCommand:PowerShell.UnregisterExternalExtension",
4546
"onCommand:PowerShell.GetPowerShellVersionDetails",
46-
"onView:PowerShellCommands"
47+
"onView:PowerShellCommands",
48+
"onNotebookEditor:PowerShellNotebookMode"
4749
],
4850
"dependencies": {
4951
"node-fetch": "^2.6.0",
@@ -56,13 +58,13 @@
5658
"@types/glob": "^7.1.3",
5759
"@types/mocha": "~7.0.2",
5860
"@types/mock-fs": "~4.10.0",
59-
"@types/node": "~12.12.39",
61+
"@types/node": "~14.0.22",
6062
"@types/node-fetch": "~2.5.7",
6163
"@types/rewire": "~2.5.28",
6264
"@types/semver": "~7.3.1",
6365
"@types/sinon": "~9.0.4",
6466
"@types/uuid": "^8.0.0",
65-
"@types/vscode": "1.43.0",
67+
"@types/vscode": "1.44.0",
6668
"mocha": "~5.2.0",
6769
"mocha-junit-reporter": "~2.0.0",
6870
"mocha-multi-reporters": "~1.1.7",
@@ -72,15 +74,17 @@
7274
"tslint": "~6.1.2",
7375
"typescript": "~3.9.6",
7476
"vsce": "~1.77.0",
75-
"vscode-test": "~1.4.0"
77+
"vscode-test": "~1.4.0",
78+
"vscode-dts": "~0.3.1"
7679
},
7780
"extensionDependencies": [
7881
"vscode.powershell"
7982
],
8083
"scripts": {
8184
"compile": "tsc -v && tsc -p ./ && tslint -p ./",
8285
"compile-watch": "tsc -watch -p ./",
83-
"test": "node ./out/test/runTests.js"
86+
"test": "node ./out/test/runTests.js",
87+
"download-api": "vscode-dts dev"
8488
},
8589
"contributes": {
8690
"breakpoints": [
@@ -106,6 +110,18 @@
106110
}
107111
]
108112
},
113+
"notebookProvider": [
114+
{
115+
"viewType": "PowerShellNotebookMode",
116+
"displayName": "Powershell Notebook",
117+
"selector": [
118+
{
119+
"filenamePattern": "*.ps1"
120+
}
121+
],
122+
"priority": "option"
123+
}
124+
],
109125
"keybindings": [
110126
{
111127
"command": "PowerShell.ShowHelp",
@@ -201,6 +217,24 @@
201217
"dark": "resources/dark/play.svg"
202218
}
203219
},
220+
{
221+
"command": "PowerShell.ShowNotebookMode",
222+
"title": "(Preview) Show Notebook Mode",
223+
"category": "PowerShell",
224+
"icon": {
225+
"light": "resources/light/book.svg",
226+
"dark": "resources/dark/book.svg"
227+
}
228+
},
229+
{
230+
"command": "PowerShell.HideNotebookMode",
231+
"title": "Show Text Editor",
232+
"category": "PowerShell",
233+
"icon": {
234+
"light": "resources/light/file-code.svg",
235+
"dark": "resources/dark/file-code.svg"
236+
}
237+
},
204238
{
205239
"command": "PowerShell.RestartSession",
206240
"title": "Restart Current Session",
@@ -376,6 +410,16 @@
376410
"when": "editorLangId == powershell && config.powershell.buttons.showRunButtons",
377411
"command": "PowerShell.RunSelection",
378412
"group": "navigation@101"
413+
},
414+
{
415+
"when": "editorLangId == powershell && config.powershell.notebooks.showToggleButton",
416+
"command": "PowerShell.ShowNotebookMode",
417+
"group": "navigation@102"
418+
},
419+
{
420+
"when": "resourceLangId == powershell && notebookEditorFocused",
421+
"command": "PowerShell.HideNotebookMode",
422+
"group": "navigation@102"
379423
}
380424
],
381425
"editor/title/context": [
@@ -881,6 +925,20 @@
881925
"type": "boolean",
882926
"default": false,
883927
"description": "Show buttons in the editor titlebar for moving the panel around."
928+
},
929+
"powershell.notebooks.showToggleButton": {
930+
"type": "boolean",
931+
"default": false,
932+
"description": "Controls whether we show or hide the buttons to toggle Notebook mode in the top right."
933+
},
934+
"powershell.notebooks.saveMarkdownCellsAs": {
935+
"type": "string",
936+
"enum": [
937+
"BlockComment",
938+
"LineComment"
939+
],
940+
"default": "BlockComment",
941+
"description": "Controls what new markdown cells in Notebook Mode get saved as in the PowerShell file."
884942
}
885943
}
886944
},

resources/dark/book.svg

+3
Loading

resources/dark/file-code.svg

+3
Loading

resources/light/book.svg

+3
Loading

resources/light/file-code.svg

+3
Loading

0 commit comments

Comments
 (0)