From a7809583a84cbb387f45a41bf75fc202e5a06131 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 9 Feb 2021 14:38:33 -0800 Subject: [PATCH] Delete VS Code Notebook API prototype --- .github/workflows/updateNotebookApi.yml | 105 --- src/features/PowerShellNotebooks.ts | 447 ------------- src/main.ts | 19 - test/features/PowerShellNotebooks.test.ts | 414 ------------ vscode.notebooks.d.ts | 27 - vscode.proposed.d.ts | 758 ---------------------- 6 files changed, 1770 deletions(-) delete mode 100644 .github/workflows/updateNotebookApi.yml delete mode 100644 src/features/PowerShellNotebooks.ts delete mode 100644 test/features/PowerShellNotebooks.test.ts delete mode 100644 vscode.notebooks.d.ts delete mode 100644 vscode.proposed.d.ts diff --git a/.github/workflows/updateNotebookApi.yml b/.github/workflows/updateNotebookApi.yml deleted file mode 100644 index 38e14721c3..0000000000 --- a/.github/workflows/updateNotebookApi.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: "Update Notebook API" - -on: - push: - pull_request: - schedule: - - cron: 0 22 * * * - -jobs: - Update-Notebook-Api: - - runs-on: ubuntu-latest - defaults: - run: - shell: pwsh - if: github.repository == 'PowerShell/vscode-powershell' - - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - - name: Setup Node.js environment - uses: actions/setup-node@v2.1.0 - - - name: Rename proposed dts to old - run: Move-Item ./vscode.proposed.d.ts ./old.vscode.proposed.d.ts - - - name: npm install - run: npm install - - - name: Get latest proposed dts - run: npm run download-api - - - name: Generate new dts and compare it with the old one - run: | - # This will contain the content of our new file - $fullFile = [System.Collections.Generic.List[string]]@() - $dts = Get-Content ./vscode.proposed.d.ts - - # First add everything up to the declare statement - $index = 0 - while ($dts[$index] -notmatch "declare module 'vscode' {") { - $fullFile += $dts[$index] - $index++ - } - - # Add the declare statement - $fullFile += $dts[$index] - - # Find the Notebook region start index - for ( $i = $index; $i -lt $dts.Length; $i++) { - if($dts[$i] -match '//#region notebook https://github.com/microsoft/vscode/issues/106744') { - $index = $i - break - } - } - - # Add everything until the endregion to the new file - while ($dts[$index] -notmatch "//#endregion") { - $fullFile += $dts[$index] - $index++ - } - - # Add the endregion line and ending brace line - $fullFile += $dts[$index] - $fullFile += '}' - - # Overwrite the file with the new content - $fullFile | Set-Content ./vscode.proposed.d.ts - - # Get the old and new files' raw text - $oldFile = Get-Content ./old.vscode.proposed.d.ts -Raw - $newFile = Get-Content ./vscode.proposed.d.ts -Raw - - # Compare them and log if they are different - if($oldFile -ne $newFile) { - Write-Host "New changes detected!" - } - - # Remove the old file so it doesn't get picked up by tsc - Remove-Item ./old.vscode.proposed.d.ts -Force - - - name: Create Pull Request - if: github.event_name == 'schedule' - id: cpr - uses: peter-evans/create-pull-request@v3 - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - with: - commit-message: "[Ignore] Update Notebook dts" - committer: GitHub - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> - title: "[Ignore] Update Notebook dts" - assignees: | - TylerLeonhardt - rjmholt - reviewers: | - TylerLeonhardt - rjmholt - base: master - draft: false - branch: powershell-notebook-patch-${{ github.run_id }} - labels: | - Created_by_Action - dependencies diff --git a/src/features/PowerShellNotebooks.ts b/src/features/PowerShellNotebooks.ts deleted file mode 100644 index 99011414ec..0000000000 --- a/src/features/PowerShellNotebooks.ts +++ /dev/null @@ -1,447 +0,0 @@ -/*--------------------------------------------------------- - * Copyright (C) Microsoft Corporation. All rights reserved. - *--------------------------------------------------------*/ - -import * as vscode from "vscode"; -import { CommentType } from "../settings"; -import { EvaluateRequestType } from "./Console"; -import { LanguageClientConsumer } from "../languageClientConsumer"; -import Settings = require("../settings"); -import { ILogger } from "../logging"; -import { LanguageClient } from "vscode-languageclient/node"; - -export class PowerShellNotebooksFeature extends LanguageClientConsumer { - - private readonly disposables: vscode.Disposable[]; - private readonly notebookContentProvider: vscode.NotebookContentProvider; - private readonly notebookKernel: PowerShellNotebookKernel; - - public constructor(logger: ILogger, skipRegisteringCommands?: boolean) { - super(); - this.disposables = []; - if(!skipRegisteringCommands) { - this.disposables.push(vscode.commands.registerCommand( - "PowerShell.EnableNotebookMode", - PowerShellNotebooksFeature.EnableNotebookMode)); - - this.disposables.push(vscode.commands.registerCommand( - "PowerShell.DisableNotebookMode", - PowerShellNotebooksFeature.DisableNotebookMode)); - } - - this.notebookContentProvider = new PowerShellNotebookContentProvider(logger); - this.notebookKernel = new PowerShellNotebookKernel(); - } - - public registerNotebookProviders() { - const options = { - transientOutputs: true, - transientMetadata: { - inputCollapsed: true, - outputCollapsed: true, - runState: true, - runStartTime: true, - executionOrder: true, - lastRunDuration: true, - statusMessage: true, - }, - }; - - // Until vscode supports using the same view type with different priority, - // we register 2 of the same viewTypes. - // This one is used to open *.Notebook.ps1 files which automatically go straight to Notebook mode. - this.disposables.push(vscode.notebook.registerNotebookKernelProvider({ - viewType: "PowerShellNotebookModeDefault" - }, this.notebookKernel)); - - this.disposables.push(vscode.notebook.registerNotebookContentProvider( - "PowerShellNotebookModeDefault", - this.notebookContentProvider, - options)); - - // This one is used to open *.ps1 files which will be opened in the default text editor first. - this.disposables.push(vscode.notebook.registerNotebookKernelProvider({ - viewType: "PowerShellNotebookModeOption" - }, this.notebookKernel)); - - this.disposables.push(vscode.notebook.registerNotebookContentProvider( - "PowerShellNotebookModeOption", - this.notebookContentProvider, - options)); - } - - public dispose() { - for (const disposable of this.disposables) { - disposable.dispose(); - } - } - - public setLanguageClient(languageClient: LanguageClient) { - this.notebookKernel.setLanguageClient(languageClient); - } - - private static async EnableNotebookMode() { - const uri = vscode.window.activeTextEditor.document.uri; - - // If the file is an untitled file, then we can't close it. - if (!vscode.window.activeTextEditor.document.isUntitled) { - await vscode.commands.executeCommand("workbench.action.closeActiveEditor"); - } - - if (uri.fsPath?.endsWith(".Notebook.ps1")) { - await vscode.commands.executeCommand("vscode.openWith", uri, "PowerShellNotebookModeDefault"); - } else { - await vscode.commands.executeCommand("vscode.openWith", uri, "PowerShellNotebookModeOption"); - } - } - - private static async DisableNotebookMode() { - const uri = vscode.window.activeNotebookEditor.document.uri; - await vscode.commands.executeCommand("workbench.action.closeActiveEditor"); - await vscode.commands.executeCommand("vscode.openWith", uri, "default"); - } -} - -interface IPowerShellNotebookCellMetadata { - commentType: CommentType; - openBlockCommentOnOwnLine?: boolean; - closeBlockCommentOnOwnLine?: boolean; -} - -function CreateCell(cellKind: vscode.CellKind, source: string[], metadata: IPowerShellNotebookCellMetadata): vscode.NotebookCellData { - return { - cellKind, - language: cellKind === vscode.CellKind.Markdown ? "markdown" : "powershell", - outputs: [], - source: source.join("\n"), - metadata: { - custom: metadata, - }, - }; -} - -class PowerShellNotebookContentProvider implements vscode.NotebookContentProvider { - private _onDidChangeNotebook = new vscode.EventEmitter(); - public onDidChangeNotebook: vscode.Event = this._onDidChangeNotebook.event; - - public constructor(private logger: ILogger) { - } - - public async openNotebook(uri: vscode.Uri, context: vscode.NotebookDocumentOpenContext): Promise { - // load from backup if needed. - const actualUri = context.backupId ? vscode.Uri.parse(context.backupId) : uri; - this.logger.writeDiagnostic(`Opening Notebook: ${uri.toString()}`); - const isUntitled = uri.scheme !== "file"; - - // If we have an untitled file, get the contents from vscode instead of the file system. - const data: string = isUntitled - ? (await vscode.workspace.openTextDocument(actualUri)).getText() - : (await vscode.workspace.fs.readFile(actualUri)).toString(); - - let lines: string[]; - // store the line ending in the metadata of the document - // so that we honor the line ending of the original file - // on save. - let lineEnding: string; - if (data.indexOf('\r\n') !== -1) { - lines = data.split(/\r\n/g); - lineEnding = '\r\n'; - } else { - lines = data.split(/\n/g); - lineEnding = '\n'; - } - - const notebookData: vscode.NotebookData = { - languages: ["powershell"], - cells: [], - metadata: { - custom: { - lineEnding, - isUntitled, - } - } - }; - - let currentCellSource: string[] = []; - let cellKind: vscode.CellKind | undefined; - let insideBlockComment: boolean = false; - - // This dictates whether the BlockComment cell was read in with content on the same - // line as the opening <#. This is so we can preserve the format of the backing file on save. - let openBlockCommentOnOwnLine: boolean = false; - - // Iterate through all lines in a document (aka ps1 file) and group the lines - // into cells (markdown or code) that will be rendered in Notebook mode. - // tslint:disable-next-line: prefer-for-of - for (let i = 0; i < lines.length; i++) { - // Handle block comments - if (insideBlockComment) { - if (lines[i].endsWith("#>")) { - // Get the content of the current line without #> - const currentLine = lines[i] - .substring(0, lines[i].length - 2) - .trimRight(); - - // This dictates whether the BlockComment cell was read in with content on the same - // line as the closing #>. This is so we can preserve the format of the backing file - // on save. - let closeBlockCommentOnOwnLine: boolean = true; - if (currentLine) { - closeBlockCommentOnOwnLine = false; - currentCellSource.push(currentLine); - } - - // We've reached the end of a block comment, - // push a markdown cell. - insideBlockComment = false; - - notebookData.cells.push(CreateCell( - vscode.CellKind.Markdown, - currentCellSource, - { - commentType: CommentType.BlockComment, - openBlockCommentOnOwnLine, - closeBlockCommentOnOwnLine - } - )); - - currentCellSource = []; - cellKind = null; - continue; - } - - // If we're still in a block comment, push the line and continue. - currentCellSource.push(lines[i]); - continue; - } else if (lines[i].startsWith("<#")) { - // If we found the start of a block comment, - // insert what we saw leading up to this. - // If cellKind is null/undefined, that means we - // are starting the file with a BlockComment. - if (cellKind) { - notebookData.cells.push(CreateCell( - cellKind, - currentCellSource, - { - commentType: cellKind === vscode.CellKind.Markdown ? CommentType.LineComment : CommentType.Disabled, - } - )); - } - - // We're starting a new Markdown cell. - cellKind = vscode.CellKind.Markdown; - insideBlockComment = true; - - // Get the content of the current line without `<#` - const currentLine = lines[i] - .substring(2, lines[i].length) - .trimLeft(); - - // If we have additional text on the line with the `<#` - // We need to keep track of what comes after it. - if (currentLine) { - // If both the `<#` and the `#>` are on the same line - // we want to push a markdown cell. - if (currentLine.endsWith("#>")) { - // Get the content of the current line without `#>` - const newCurrentLine = currentLine - .substring(0, currentLine.length - 2) - .trimRight(); - - notebookData.cells.push(CreateCell( - vscode.CellKind.Markdown, - [ newCurrentLine ], - { - commentType: CommentType.BlockComment, - openBlockCommentOnOwnLine: false, - closeBlockCommentOnOwnLine: false, - } - )); - - // Reset - currentCellSource = []; - cellKind = null; - insideBlockComment = false; - continue; - } - - openBlockCommentOnOwnLine = false; - currentCellSource = [ currentLine ]; - } else { - openBlockCommentOnOwnLine = true; - currentCellSource = []; - } - - continue; - } - - // Handle everything else (regular comments and code) - // If a line starts with # it's a comment - const kind: vscode.CellKind = lines[i].startsWith("#") ? vscode.CellKind.Markdown : vscode.CellKind.Code; - - // If this line is a continuation of the previous cell type, then add this line to the current cell source. - if (kind === cellKind) { - currentCellSource.push(kind === vscode.CellKind.Markdown && !insideBlockComment ? lines[i].replace(/^\#\s*/, "") : lines[i]); - } else { - // If cellKind has a value, then we can add the cell we've just computed. - if (cellKind) { - notebookData.cells.push(CreateCell( - cellKind, - currentCellSource, - { - commentType: cellKind === vscode.CellKind.Markdown ? CommentType.LineComment : CommentType.Disabled, - } - )); - } - - // set initial new cell state - currentCellSource = []; - cellKind = kind; - currentCellSource.push(kind === vscode.CellKind.Markdown ? lines[i].replace(/^\#\s*/, "") : lines[i]); - } - } - - // If we have some leftover lines that have not been added (for example, - // when there is only the _start_ of a block comment but not an _end_.) - // add the appropriate cell. - if (currentCellSource.length) { - notebookData.cells.push(CreateCell( - cellKind!, - currentCellSource, - { - commentType: cellKind === vscode.CellKind.Markdown ? CommentType.LineComment : CommentType.Disabled, - } - )); - } - - return notebookData; - } - - public resolveNotebook(document: vscode.NotebookDocument, webview: { readonly onDidReceiveMessage: vscode.Event; postMessage(message: any): Thenable; asWebviewUri(localResource: vscode.Uri): vscode.Uri; }): Promise { - // We don't need to do anything here because our Notebooks are backed by files. - return; - } - - public saveNotebook(document: vscode.NotebookDocument, cancellation: vscode.CancellationToken): Promise { - return this._save(document, document.uri, cancellation); - } - - public saveNotebookAs(targetResource: vscode.Uri, document: vscode.NotebookDocument, cancellation: vscode.CancellationToken): Promise { - return this._save(document, targetResource, cancellation); - } - - public async backupNotebook(document: vscode.NotebookDocument, context: vscode.NotebookDocumentBackupContext, cancellation: vscode.CancellationToken): Promise { - await this._save(document, context.destination, cancellation); - - return { - id: context.destination.toString(), - delete: () => { - vscode.workspace.fs.delete(context.destination); - } - }; - } - - private async _save(document: vscode.NotebookDocument, targetResource: vscode.Uri, _token: vscode.CancellationToken): Promise { - this.logger.writeDiagnostic(`Saving Notebook: ${targetResource.toString()}`); - - const retArr: string[] = []; - for (const cell of document.cells) { - if (cell.cellKind === vscode.CellKind.Code) { - retArr.push(...cell.document.getText().split(/\r\n|\n/)); - } else { - // First honor the comment type of the cell if it already has one. - // If not, use the user setting. - const commentKind = cell.metadata.custom?.commentType || Settings.load().notebooks.saveMarkdownCellsAs; - - if (commentKind === CommentType.BlockComment) { - const openBlockCommentOnOwnLine: boolean = cell.metadata.custom?.openBlockCommentOnOwnLine; - const closeBlockCommentOnOwnLine: boolean = cell.metadata.custom?.closeBlockCommentOnOwnLine; - const text = cell.document.getText().split(/\r\n|\n/); - if (openBlockCommentOnOwnLine) { - retArr.push("<#"); - } else { - text[0] = `<# ${text[0]}`; - } - - if (!closeBlockCommentOnOwnLine) { - text[text.length - 1] += " #>"; - retArr.push(...text); - } else { - retArr.push(...text); - retArr.push("#>"); - } - } else { - retArr.push(...cell.document.getText().split(/\r\n|\n/).map((line) => `# ${line}`)); - } - } - } - - const eol = document.metadata.custom.lineEnding; - await vscode.workspace.fs.writeFile(targetResource, new TextEncoder().encode(retArr.join(eol))); - } -} - -class PowerShellNotebookKernel implements vscode.NotebookKernel, vscode.NotebookKernelProvider { - private static informationMessage = "PowerShell extension has not finished starting up yet. Please try again in a few moments."; - - public id?: string; - public label: string = "PowerShell"; - public description?: string = "The PowerShell Notebook Mode kernel that runs commands in the PowerShell Integrated Console."; - public isPreferred?: boolean; - public preloads?: vscode.Uri[]; - - private _languageClient: LanguageClient; - private get languageClient(): LanguageClient { - if (!this._languageClient) { - vscode.window.showInformationMessage( - PowerShellNotebookKernel.informationMessage); - } - return this._languageClient; - } - - private set languageClient(value: LanguageClient) { - this._languageClient = value; - } - - public async executeAllCells(document: vscode.NotebookDocument): Promise { - for (const cell of document.cells) { - if (cell.cellKind === vscode.CellKind.Code) { - await this.executeCell(document, cell); - } - } - } - - public async executeCell(document: vscode.NotebookDocument, cell: vscode.NotebookCell | undefined): Promise { - await this.languageClient.sendRequest(EvaluateRequestType, { - expression: cell.document.getText(), - }); - - // Show the integrated console if it isn't already visible and - // scroll terminal to bottom so new output is visible - await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true); - await vscode.commands.executeCommand("workbench.action.terminal.scrollToBottom"); - } - - // Since executing a cell is a "fire and forget", there's no time for the user to cancel - // any of the executing cells. We can bring this in after PSES has a better API for executing code. - public cancelCellExecution(document: vscode.NotebookDocument, cell: vscode.NotebookCell): void { - return; - } - - // Since executing a cell is a "fire and forget", there's no time for the user to cancel - // any of the executing cells. We can bring this in after PSES has a better API for executing code. - public cancelAllCellsExecution(document: vscode.NotebookDocument): void { - return; - } - - public setLanguageClient(languageClient: LanguageClient) { - this.languageClient = languageClient; - } - - /* - vscode.NotebookKernelProvider implementation - */ - public provideKernels(document: vscode.NotebookDocument, token: vscode.CancellationToken): vscode.ProviderResult { - return [this]; - } -} diff --git a/src/main.ts b/src/main.ts index 254714e713..c7a46d0335 100644 --- a/src/main.ts +++ b/src/main.ts @@ -34,7 +34,6 @@ import { SessionManager } from "./session"; import Settings = require("./settings"); import { PowerShellLanguageId } from "./utils"; import { LanguageClientConsumer } from "./languageClientConsumer"; -import { PowerShellNotebooksFeature } from "./features/PowerShellNotebooks"; // The most reliable way to get the name and version of the current extension. // tslint:disable-next-line: no-var-requires @@ -167,24 +166,6 @@ export function activate(context: vscode.ExtensionContext): IPowerShellExtension externalApi ]; - // Notebook UI is only supported in VS Code Insiders. - if(vscode.env.uriScheme === "vscode-insiders") { - const powerShellNotebooksFeature = new PowerShellNotebooksFeature(logger); - - try { - powerShellNotebooksFeature.registerNotebookProviders(); - languageClientConsumers.push(powerShellNotebooksFeature); - } catch (e) { - // This would happen if VS Code changes their API. - powerShellNotebooksFeature.dispose(); - logger.writeVerbose("Failed to register NotebookContentProvider", e); - } - } else { - vscode.commands.registerCommand( - "PowerShell.EnableNotebookMode", - () => vscode.window.showWarningMessage("Notebook Mode only works in Visual Studio Code Insiders. To get it, go to: aka.ms/vscode-insiders")); - } - sessionManager.setLanguageClientConsumers(languageClientConsumers); if (extensionSettings.startAutomatically) { diff --git a/test/features/PowerShellNotebooks.test.ts b/test/features/PowerShellNotebooks.test.ts deleted file mode 100644 index b0a54a0bcd..0000000000 --- a/test/features/PowerShellNotebooks.test.ts +++ /dev/null @@ -1,414 +0,0 @@ -/*--------------------------------------------------------- - * Copyright (C) Microsoft Corporation. All rights reserved. - *--------------------------------------------------------*/ - -import * as assert from "assert"; -import * as path from "path"; -import * as vscode from "vscode"; -import { PowerShellNotebooksFeature } from "../../src/features/PowerShellNotebooks"; -import os = require("os"); -import { readFileSync } from "fs"; -import { CommentType } from "../../src/settings"; -import * as utils from "../../src/utils"; -import { MockLogger } from "../test_utils"; - -const notebookDir = [ - __dirname, - "..", - "..", - "..", - "test", - "features", - "testNotebookFiles" -]; - -const notebookOnlyCode = vscode.Uri.file( - path.join(...notebookDir, "onlyCode.ps1")); -const notebookOnlyMarkdown = vscode.Uri.file( - path.join(...notebookDir,"onlyMarkdown.ps1")); -const notebookSimpleBlockComments = vscode.Uri.file( - path.join(...notebookDir,"simpleBlockComments.ps1")); -const notebookBlockCommentsWithTextOnSameLine = vscode.Uri.file( - path.join(...notebookDir,"blockCommentsWithTextOnSameLine.ps1")); -const notebookSimpleLineComments = vscode.Uri.file( - path.join(...notebookDir,"simpleLineComments.ps1")); -const notebookSimpleMixedComments = vscode.Uri.file( - path.join(...notebookDir,"simpleMixedComments.ps1")); -const notebookSimpleDotNotebook = vscode.Uri.file( - path.join(...notebookDir,"simple.Notebook.ps1")); - -const notebookTestData = new Map(); - -function readBackingFile(uri: vscode.Uri): string { - return readFileSync(uri.fsPath).toString(); -} - -function compareCells(actualCells: vscode.NotebookCellData[], expectedCells: vscode.NotebookCellData[]) : void { - assert.deepStrictEqual(actualCells.length, expectedCells.length); - - // Compare cell metadata - for (let i = 0; i < actualCells.length; i++) { - assert.deepStrictEqual( - actualCells[i].metadata.custom, - expectedCells[i].metadata.custom - ); - } -} - -suite("PowerShellNotebooks tests", () => { - notebookTestData.set(notebookOnlyCode, [ - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: readBackingFile(notebookOnlyCode), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - } - ]); - - notebookTestData.set(notebookOnlyMarkdown, [ - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: readBackingFile(notebookOnlyMarkdown), - outputs: [], - metadata: { - custom: { - commentType: CommentType.LineComment, - } - } - } - ]); - - let content = readBackingFile(notebookSimpleBlockComments).split(os.EOL); - notebookTestData.set(notebookSimpleBlockComments, [ - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(0, 5).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: true, - openBlockCommentOnOwnLine: true - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(5, 6).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(6, 11).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: true, - openBlockCommentOnOwnLine: true - } - } - }, - ]); - - content = readBackingFile(notebookBlockCommentsWithTextOnSameLine).split(os.EOL); - notebookTestData.set(notebookBlockCommentsWithTextOnSameLine, [ - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(0, 5).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: true, - openBlockCommentOnOwnLine: true - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(5, 6).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(6, 9).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: false, - openBlockCommentOnOwnLine: false - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(9, 10).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(10, 13).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: true, - openBlockCommentOnOwnLine: false - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(13, 14).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(14, 17).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: false, - openBlockCommentOnOwnLine: true - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(17, 18).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(18, 19).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: false, - openBlockCommentOnOwnLine: false - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(19, 20).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - ]); - - content = readBackingFile(notebookSimpleLineComments).split(os.EOL); - notebookTestData.set(notebookSimpleLineComments, [ - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(0, 3).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.LineComment, - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(3, 4).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(4, 7).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.LineComment, - } - } - }, - ]); - - content = readBackingFile(notebookSimpleMixedComments).split(os.EOL); - notebookTestData.set(notebookSimpleMixedComments, [ - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(0, 3).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.LineComment, - } - } - }, - { - cellKind: vscode.CellKind.Code, - language: "powershell", - source: content.slice(3, 4).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.Disabled, - } - } - }, - { - cellKind: vscode.CellKind.Markdown, - language: "markdown", - source: content.slice(4, 9).join(os.EOL), - outputs: [], - metadata: { - custom: { - commentType: CommentType.BlockComment, - closeBlockCommentOnOwnLine: true, - openBlockCommentOnOwnLine: true - } - } - }, - ]); - - const feature = new PowerShellNotebooksFeature(new MockLogger(), true); - // `notebookContentProvider` is a private property so cast the feature as `any` so we can access it. - const notebookContentProvider: vscode.NotebookContentProvider = (feature as any).notebookContentProvider; - - for (const [uri, expectedCells] of notebookTestData) { - test(`Can open a notebook with expected cells - ${uri.fsPath}`, async () => { - const actualNotebookData = await notebookContentProvider.openNotebook(uri, {}); - compareCells(actualNotebookData.cells, expectedCells); - }); - } - - test("Can save a new notebook with expected cells and metadata", async () => { - const uri = vscode.Uri.file(path.join(__dirname, "testFile.ps1")); - try { - await vscode.workspace.fs.delete(uri); - } catch { - // If the file doesn't exist that's fine. - } - - // Open an existing notebook ps1. - await vscode.commands.executeCommand("vscode.openWith", notebookSimpleMixedComments, "PowerShellNotebookModeOption"); - - // Allow some time to pass to render the Notebook - await utils.sleep(5000); - assert.strictEqual( - vscode.window.activeNotebookEditor.document.uri.toString(), - notebookSimpleMixedComments.toString()); - - // Save it as testFile.ps1 and reopen it using the feature. - await notebookContentProvider.saveNotebookAs(uri, vscode.window.activeNotebookEditor.document, null); - const newNotebook = await notebookContentProvider.openNotebook(uri, {}); - - // Compare that saving as a file results in the same cell data as the existing one. - const expectedCells = notebookTestData.get(notebookSimpleMixedComments); - compareCells(newNotebook.cells, expectedCells); - }).timeout(20000); - - test("Can save a new notebook with expected content", async () => { - const uri = vscode.Uri.file(path.join(__dirname, "testFile1.ps1")); - try { - await vscode.workspace.fs.delete(uri); - } catch { - // If the file doesn't exist that's fine. - } - - // Open an existing notebook ps1. - await vscode.commands.executeCommand("vscode.openWith", notebookBlockCommentsWithTextOnSameLine, "PowerShellNotebookModeOption"); - - // Allow some time to pass to render the Notebook - await utils.sleep(5000); - assert.strictEqual( - vscode.window.activeNotebookEditor.document.uri.toString(), - notebookBlockCommentsWithTextOnSameLine.toString()); - - // Save it as testFile1.ps1 - const contentOfBackingFileBefore = (await vscode.workspace.fs.readFile(notebookBlockCommentsWithTextOnSameLine)).toString(); - await notebookContentProvider.saveNotebookAs(uri, vscode.window.activeNotebookEditor.document, null); - const contentOfBackingFileAfter = (await vscode.workspace.fs.readFile(uri)).toString(); - - // Verify that saving does not mutate result. - assert.strictEqual(contentOfBackingFileBefore, contentOfBackingFileAfter); - }).timeout(20000); - - test("Can open an untitled Notebook", async () => { - const doc = await vscode.workspace.openTextDocument({ - language: "powershell", - content: `# asdf -gci`, - }); - - const notebookData = await notebookContentProvider.openNotebook(doc.uri, {}); - assert.strictEqual(notebookData.cells.length, 2); - assert.strictEqual(notebookData.cells[0].cellKind, vscode.CellKind.Markdown); - assert.strictEqual(notebookData.cells[0].source, "asdf"); - assert.strictEqual(notebookData.cells[1].cellKind, vscode.CellKind.Code); - assert.strictEqual(notebookData.cells[1].source, "gci"); - }).timeout(20000); - - test(".Notebook.ps1 files are opened automatically", async () => { - await vscode.commands.executeCommand("vscode.open", notebookSimpleDotNotebook); - assert.strictEqual(vscode.window.activeNotebookEditor.document.cells.length, 2); - assert.strictEqual(vscode.window.activeNotebookEditor.document.cells[0].cellKind, vscode.CellKind.Markdown); - assert.strictEqual(vscode.window.activeNotebookEditor.document.cells[0].document.getText(), "asdf"); - assert.strictEqual(vscode.window.activeNotebookEditor.document.cells[1].cellKind, vscode.CellKind.Code); - assert.strictEqual(vscode.window.activeNotebookEditor.document.cells[1].document.getText(), "gci\n"); - }).timeout(20000); -}); diff --git a/vscode.notebooks.d.ts b/vscode.notebooks.d.ts deleted file mode 100644 index c1e10affe0..0000000000 --- a/vscode.notebooks.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* -This file contains types introduced in a newer version of vscode than 1.45 that are used by the Notebook Mode feature. - -We are locked on to 1.45 because that is what SAWs support. - -Once SAWs support a newer version of vscode we can remove this. My hope is that this will be the only addition to this file. -*/ - -declare module 'vscode' { - /** - * Accessibility information which controls screen reader behavior. - */ - export interface AccessibilityInformation { - /** - * Label to be read out by a screen reader once the item has focus. - */ - label: string; - - /** - * Role of the widget which defines how a screen reader interacts with it. - * The role should be set in special cases when for example a tree-like element behaves like a checkbox. - * If role is not specified VS Code will pick the appropriate role automatically. - * More about aria roles can be found here https://w3c.github.io/aria/#widget_roles - */ - role?: string; - } -} diff --git a/vscode.proposed.d.ts b/vscode.proposed.d.ts deleted file mode 100644 index 0ab6682f81..0000000000 --- a/vscode.proposed.d.ts +++ /dev/null @@ -1,758 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -/** - * This is the place for API experiments and proposals. - * These API are NOT stable and subject to change. They are only available in the Insiders - * distribution and CANNOT be used in published extensions. - * - * To test these API in local environment: - * - Use Insiders release of VS Code. - * - Add `"enableProposedApi": true` to your package.json. - * - Copy this file to your project. - */ - -declare module 'vscode' { - //#region notebook https://github.com/microsoft/vscode/issues/106744 - - export enum CellKind { - Markdown = 1, - Code = 2 - } - - export enum CellOutputKind { - Text = 1, - Error = 2, - Rich = 3 - } - - export interface CellStreamOutput { - outputKind: CellOutputKind.Text; - text: string; - } - - export interface CellErrorOutput { - outputKind: CellOutputKind.Error; - /** - * Exception Name - */ - ename: string; - /** - * Exception Value - */ - evalue: string; - /** - * Exception call stack - */ - traceback: string[]; - } - - export interface NotebookCellOutputMetadata { - /** - * Additional attributes of a cell metadata. - */ - custom?: { [key: string]: any; }; - } - - export interface CellDisplayOutput { - outputKind: CellOutputKind.Rich; - /** - * { mime_type: value } - * - * Example: - * ```json - * { - * "outputKind": vscode.CellOutputKind.Rich, - * "data": { - * "text/html": [ - * "

Hello

" - * ], - * "text/plain": [ - * "" - * ] - * } - * } - */ - data: { [key: string]: any; }; - - readonly metadata?: NotebookCellOutputMetadata; - } - - export type CellOutput = CellStreamOutput | CellErrorOutput | CellDisplayOutput; - - export class NotebookCellOutputItem { - - readonly mime: string; - readonly value: unknown; - readonly metadata?: Record; - - constructor(mime: string, value: unknown, metadata?: Record); - } - - //TODO@jrieken add id? - export class NotebookCellOutput { - - readonly outputs: NotebookCellOutputItem[]; - readonly metadata?: Record; - - constructor(outputs: NotebookCellOutputItem[], metadata?: Record); - - //TODO@jrieken HACK to workaround dependency issues... - toJSON(): any; - } - - export enum NotebookCellRunState { - Running = 1, - Idle = 2, - Success = 3, - Error = 4 - } - - export enum NotebookRunState { - Running = 1, - Idle = 2 - } - - export interface NotebookCellMetadata { - /** - * Controls whether a cell's editor is editable/readonly. - */ - editable?: boolean; - - /** - * Controls if the cell is executable. - * This metadata is ignored for markdown cell. - */ - runnable?: boolean; - - /** - * Controls if the cell has a margin to support the breakpoint UI. - * This metadata is ignored for markdown cell. - */ - breakpointMargin?: boolean; - - /** - * Whether the [execution order](#NotebookCellMetadata.executionOrder) indicator will be displayed. - * Defaults to true. - */ - hasExecutionOrder?: boolean; - - /** - * The order in which this cell was executed. - */ - executionOrder?: number; - - /** - * A status message to be shown in the cell's status bar - */ - statusMessage?: string; - - /** - * The cell's current run state - */ - runState?: NotebookCellRunState; - - /** - * If the cell is running, the time at which the cell started running - */ - runStartTime?: number; - - /** - * The total duration of the cell's last run - */ - lastRunDuration?: number; - - /** - * Whether a code cell's editor is collapsed - */ - inputCollapsed?: boolean; - - /** - * Whether a code cell's outputs are collapsed - */ - outputCollapsed?: boolean; - - /** - * Additional attributes of a cell metadata. - */ - custom?: { [key: string]: any; }; - } - - export interface NotebookCell { - readonly index: number; - readonly notebook: NotebookDocument; - readonly uri: Uri; - readonly cellKind: CellKind; - readonly document: TextDocument; - readonly language: string; - outputs: CellOutput[]; - metadata: NotebookCellMetadata; - } - - export interface NotebookDocumentMetadata { - /** - * Controls if users can add or delete cells - * Defaults to true - */ - editable?: boolean; - - /** - * Controls whether the full notebook can be run at once. - * Defaults to true - */ - runnable?: boolean; - - /** - * Default value for [cell editable metadata](#NotebookCellMetadata.editable). - * Defaults to true. - */ - cellEditable?: boolean; - - /** - * Default value for [cell runnable metadata](#NotebookCellMetadata.runnable). - * Defaults to true. - */ - cellRunnable?: boolean; - - /** - * Default value for [cell hasExecutionOrder metadata](#NotebookCellMetadata.hasExecutionOrder). - * Defaults to true. - */ - cellHasExecutionOrder?: boolean; - - displayOrder?: GlobPattern[]; - - /** - * Additional attributes of the document metadata. - */ - custom?: { [key: string]: any; }; - - /** - * The document's current run state - */ - runState?: NotebookRunState; - - /** - * Whether the document is trusted, default to true - * When false, insecure outputs like HTML, JavaScript, SVG will not be rendered. - */ - trusted?: boolean; - - /** - * Languages the document supports - */ - languages?: string[]; - } - - export interface NotebookDocumentContentOptions { - /** - * Controls if outputs change will trigger notebook document content change and if it will be used in the diff editor - * Default to false. If the content provider doesn't persisit the outputs in the file document, this should be set to true. - */ - transientOutputs: boolean; - - /** - * Controls if a meetadata property change will trigger notebook document content change and if it will be used in the diff editor - * Default to false. If the content provider doesn't persisit a metadata property in the file document, it should be set to true. - */ - transientMetadata: { [K in keyof NotebookCellMetadata]?: boolean }; - } - - export interface NotebookDocument { - readonly uri: Uri; - readonly version: number; - readonly fileName: string; - readonly viewType: string; - readonly isDirty: boolean; - readonly isUntitled: boolean; - readonly cells: ReadonlyArray; - readonly contentOptions: NotebookDocumentContentOptions; - languages: string[]; - metadata: NotebookDocumentMetadata; - } - - export interface NotebookConcatTextDocument { - uri: Uri; - isClosed: boolean; - dispose(): void; - onDidChange: Event; - version: number; - getText(): string; - getText(range: Range): string; - - offsetAt(position: Position): number; - positionAt(offset: number): Position; - validateRange(range: Range): Range; - validatePosition(position: Position): Position; - - locationAt(positionOrRange: Position | Range): Location; - positionAt(location: Location): Position; - contains(uri: Uri): boolean; - } - - export interface WorkspaceEdit { - replaceNotebookMetadata(uri: Uri, value: NotebookDocumentMetadata): void; - replaceNotebookCells(uri: Uri, start: number, end: number, cells: NotebookCellData[], metadata?: WorkspaceEditEntryMetadata): void; - replaceNotebookCellOutput(uri: Uri, index: number, outputs: (NotebookCellOutput | CellOutput)[], metadata?: WorkspaceEditEntryMetadata): void; - replaceNotebookCellMetadata(uri: Uri, index: number, cellMetadata: NotebookCellMetadata, metadata?: WorkspaceEditEntryMetadata): void; - } - - export interface NotebookEditorEdit { - replaceMetadata(value: NotebookDocumentMetadata): void; - replaceCells(start: number, end: number, cells: NotebookCellData[]): void; - replaceCellOutput(index: number, outputs: (NotebookCellOutput | CellOutput)[]): void; - replaceCellMetadata(index: number, metadata: NotebookCellMetadata): void; - } - - export interface NotebookCellRange { - readonly start: number; - /** - * exclusive - */ - readonly end: number; - } - - export enum NotebookEditorRevealType { - /** - * The range will be revealed with as little scrolling as possible. - */ - Default = 0, - /** - * The range will always be revealed in the center of the viewport. - */ - InCenter = 1, - - /** - * If the range is outside the viewport, it will be revealed in the center of the viewport. - * Otherwise, it will be revealed with as little scrolling as possible. - */ - InCenterIfOutsideViewport = 2, - - /** - * The range will always be revealed at the top of the viewport. - */ - AtTop = 3 - } - - export interface NotebookEditor { - /** - * The document associated with this notebook editor. - */ - readonly document: NotebookDocument; - - /** - * The primary selected cell on this notebook editor. - */ - readonly selection?: NotebookCell; - - - /** - * The current visible ranges in the editor (vertically). - */ - readonly visibleRanges: NotebookCellRange[]; - - /** - * The column in which this editor shows. - */ - readonly viewColumn?: ViewColumn; - - /** - * Fired when the panel is disposed. - */ - readonly onDidDispose: Event; - - /** - * Active kernel used in the editor - */ - readonly kernel?: NotebookKernel; - - /** - * Fired when the output hosting webview posts a message. - */ - readonly onDidReceiveMessage: Event; - /** - * Post a message to the output hosting webview. - * - * Messages are only delivered if the editor is live. - * - * @param message Body of the message. This must be a string or other json serializable object. - */ - postMessage(message: any): Thenable; - - /** - * Convert a uri for the local file system to one that can be used inside outputs webview. - */ - asWebviewUri(localResource: Uri): Uri; - - /** - * Perform an edit on the notebook associated with this notebook editor. - * - * The given callback-function is invoked with an [edit-builder](#NotebookEditorEdit) which must - * be used to make edits. Note that the edit-builder is only valid while the - * callback executes. - * - * @param callback A function which can create edits using an [edit-builder](#NotebookEditorEdit). - * @return A promise that resolves with a value indicating if the edits could be applied. - */ - edit(callback: (editBuilder: NotebookEditorEdit) => void): Thenable; - - setDecorations(decorationType: NotebookEditorDecorationType, range: NotebookCellRange): void; - - revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void; - } - - export interface NotebookOutputSelector { - mimeTypes?: string[]; - } - - export interface NotebookRenderRequest { - output: CellDisplayOutput; - mimeType: string; - outputId: string; - } - - export interface NotebookDocumentMetadataChangeEvent { - readonly document: NotebookDocument; - } - - export interface NotebookCellsChangeData { - readonly start: number; - readonly deletedCount: number; - readonly deletedItems: NotebookCell[]; - readonly items: NotebookCell[]; - } - - export interface NotebookCellsChangeEvent { - - /** - * The affected document. - */ - readonly document: NotebookDocument; - readonly changes: ReadonlyArray; - } - - export interface NotebookCellMoveEvent { - - /** - * The affected document. - */ - readonly document: NotebookDocument; - readonly index: number; - readonly newIndex: number; - } - - export interface NotebookCellOutputsChangeEvent { - - /** - * The affected document. - */ - readonly document: NotebookDocument; - readonly cells: NotebookCell[]; - } - - export interface NotebookCellLanguageChangeEvent { - - /** - * The affected document. - */ - readonly document: NotebookDocument; - readonly cell: NotebookCell; - readonly language: string; - } - - export interface NotebookCellMetadataChangeEvent { - readonly document: NotebookDocument; - readonly cell: NotebookCell; - } - - export interface NotebookEditorSelectionChangeEvent { - readonly notebookEditor: NotebookEditor; - readonly selection?: NotebookCell; - } - - export interface NotebookEditorVisibleRangesChangeEvent { - readonly notebookEditor: NotebookEditor; - readonly visibleRanges: ReadonlyArray; - } - - export interface NotebookCellData { - readonly cellKind: CellKind; - readonly source: string; - readonly language: string; - readonly outputs: CellOutput[]; - readonly metadata: NotebookCellMetadata | undefined; - } - - export interface NotebookData { - readonly cells: NotebookCellData[]; - readonly languages: string[]; - readonly metadata: NotebookDocumentMetadata; - } - - interface NotebookDocumentContentChangeEvent { - - /** - * The document that the edit is for. - */ - readonly document: NotebookDocument; - } - - interface NotebookDocumentEditEvent { - - /** - * The document that the edit is for. - */ - readonly document: NotebookDocument; - - /** - * Undo the edit operation. - * - * This is invoked by VS Code when the user undoes this edit. To implement `undo`, your - * extension should restore the document and editor to the state they were in just before this - * edit was added to VS Code's internal edit stack by `onDidChangeCustomDocument`. - */ - undo(): Thenable | void; - - /** - * Redo the edit operation. - * - * This is invoked by VS Code when the user redoes this edit. To implement `redo`, your - * extension should restore the document and editor to the state they were in just after this - * edit was added to VS Code's internal edit stack by `onDidChangeCustomDocument`. - */ - redo(): Thenable | void; - - /** - * Display name describing the edit. - * - * This will be shown to users in the UI for undo/redo operations. - */ - readonly label?: string; - } - - interface NotebookDocumentBackup { - /** - * Unique identifier for the backup. - * - * This id is passed back to your extension in `openNotebook` when opening a notebook editor from a backup. - */ - readonly id: string; - - /** - * Delete the current backup. - * - * This is called by VS Code when it is clear the current backup is no longer needed, such as when a new backup - * is made or when the file is saved. - */ - delete(): void; - } - - interface NotebookDocumentBackupContext { - readonly destination: Uri; - } - - interface NotebookDocumentOpenContext { - readonly backupId?: string; - } - - /** - * Communication object passed to the {@link NotebookContentProvider} and - * {@link NotebookOutputRenderer} to communicate with the webview. - */ - export interface NotebookCommunication { - /** - * ID of the editor this object communicates with. A single notebook - * document can have multiple attached webviews and editors, when the - * notebook is split for instance. The editor ID lets you differentiate - * between them. - */ - readonly editorId: string; - - /** - * Fired when the output hosting webview posts a message. - */ - readonly onDidReceiveMessage: Event; - /** - * Post a message to the output hosting webview. - * - * Messages are only delivered if the editor is live. - * - * @param message Body of the message. This must be a string or other json serializable object. - */ - postMessage(message: any): Thenable; - - /** - * Convert a uri for the local file system to one that can be used inside outputs webview. - */ - asWebviewUri(localResource: Uri): Uri; - } - - export interface NotebookContentProvider { - readonly options?: NotebookDocumentContentOptions; - readonly onDidChangeNotebookContentOptions?: Event; - readonly onDidChangeNotebook: Event; - - /** - * Content providers should always use [file system providers](#FileSystemProvider) to - * resolve the raw content for `uri` as the resouce is not necessarily a file on disk. - */ - // eslint-disable-next-line vscode-dts-provider-naming - openNotebook(uri: Uri, openContext: NotebookDocumentOpenContext): NotebookData | Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - // eslint-disable-next-line vscode-dts-cancellation - resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - saveNotebook(document: NotebookDocument, cancellation: CancellationToken): Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - saveNotebookAs(targetResource: Uri, document: NotebookDocument, cancellation: CancellationToken): Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, cancellation: CancellationToken): Thenable; - } - - export interface NotebookKernel { - readonly id?: string; - label: string; - description?: string; - detail?: string; - isPreferred?: boolean; - preloads?: Uri[]; - executeCell(document: NotebookDocument, cell: NotebookCell): void; - cancelCellExecution(document: NotebookDocument, cell: NotebookCell): void; - executeAllCells(document: NotebookDocument): void; - cancelAllCellsExecution(document: NotebookDocument): void; - } - - export type NotebookFilenamePattern = GlobPattern | { include: GlobPattern; exclude: GlobPattern; }; - - export interface NotebookDocumentFilter { - viewType?: string | string[]; - filenamePattern?: NotebookFilenamePattern; - } - - export interface NotebookKernelProvider { - onDidChangeKernels?: Event; - provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult; - resolveKernel?(kernel: T, document: NotebookDocument, webview: NotebookCommunication, token: CancellationToken): ProviderResult; - } - - /** - * Represents the alignment of status bar items. - */ - export enum NotebookCellStatusBarAlignment { - - /** - * Aligned to the left side. - */ - Left = 1, - - /** - * Aligned to the right side. - */ - Right = 2 - } - - export interface NotebookCellStatusBarItem { - readonly cell: NotebookCell; - readonly alignment: NotebookCellStatusBarAlignment; - readonly priority?: number; - text: string; - tooltip: string | undefined; - command: string | Command | undefined; - accessibilityInformation?: AccessibilityInformation; - show(): void; - hide(): void; - dispose(): void; - } - - export interface NotebookDecorationRenderOptions { - backgroundColor?: string | ThemeColor; - borderColor?: string | ThemeColor; - top: ThemableDecorationAttachmentRenderOptions; - } - - export interface NotebookEditorDecorationType { - readonly key: string; - dispose(): void; - } - - export interface NotebookDocumentShowOptions { - viewColumn?: ViewColumn; - preserveFocus?: boolean; - preview?: boolean; - selection?: NotebookCellRange; - } - - - export namespace notebook { - export function registerNotebookContentProvider( - notebookType: string, - provider: NotebookContentProvider, - options?: NotebookDocumentContentOptions & { - /** - * Not ready for production or development use yet. - */ - viewOptions?: { - displayName: string; - filenamePattern: NotebookFilenamePattern[]; - exclusive?: boolean; - }; - } - ): Disposable; - - export function registerNotebookKernelProvider( - selector: NotebookDocumentFilter, - provider: NotebookKernelProvider - ): Disposable; - - export function createNotebookEditorDecorationType(options: NotebookDecorationRenderOptions): NotebookEditorDecorationType; - export function openNotebookDocument(uri: Uri, viewType?: string): Thenable; - export const onDidOpenNotebookDocument: Event; - export const onDidCloseNotebookDocument: Event; - export const onDidSaveNotebookDocument: Event; - - /** - * All currently known notebook documents. - */ - export const notebookDocuments: ReadonlyArray; - export const onDidChangeNotebookDocumentMetadata: Event; - export const onDidChangeNotebookCells: Event; - export const onDidChangeCellOutputs: Event; - export const onDidChangeCellLanguage: Event; - export const onDidChangeCellMetadata: Event; - /** - * Create a document that is the concatenation of all notebook cells. By default all code-cells are included - * but a selector can be provided to narrow to down the set of cells. - * - * @param notebook - * @param selector - */ - export function createConcatTextDocument(notebook: NotebookDocument, selector?: DocumentSelector): NotebookConcatTextDocument; - - export const onDidChangeActiveNotebookKernel: Event<{ document: NotebookDocument, kernel: NotebookKernel | undefined; }>; - - /** - * Creates a notebook cell status bar [item](#NotebookCellStatusBarItem). - * It will be disposed automatically when the notebook document is closed or the cell is deleted. - * - * @param cell The cell on which this item should be shown. - * @param alignment The alignment of the item. - * @param priority The priority of the item. Higher values mean the item should be shown more to the left. - * @return A new status bar item. - */ - export function createCellStatusBarItem(cell: NotebookCell, alignment?: NotebookCellStatusBarAlignment, priority?: number): NotebookCellStatusBarItem; - } - - export namespace window { - export const visibleNotebookEditors: NotebookEditor[]; - export const onDidChangeVisibleNotebookEditors: Event; - export const activeNotebookEditor: NotebookEditor | undefined; - export const onDidChangeActiveNotebookEditor: Event; - export const onDidChangeNotebookEditorSelection: Event; - export const onDidChangeNotebookEditorVisibleRanges: Event; - export function showNotebookDocument(document: NotebookDocument, options?: NotebookDocumentShowOptions): Thenable; - } - - //#endregion -}