diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd396dabe59..048f460119d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,11 @@ ([#12732](https://github.com/Microsoft/vscode-python/issues/12732)) 1. Show a prompt asking user to upgrade Code runner to new version to keep using it when in Deprecate PythonPath experiment. ([#12764](https://github.com/Microsoft/vscode-python/issues/12764)) +1. Opening notebooks in the preview Notebook editor for [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). + * Install Python extension in the latest [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). + * Wait for `Python Extension` to get activated (e.g. open a `Python` file). + * Right click on an `*.ipynb (Jupyter Notebook)` file and select `Open in preview Notebook Editor`. + ([#10496](https://github.com/Microsoft/vscode-python/issues/10496)) ### Fixes @@ -119,6 +124,10 @@ ([#12656](https://github.com/Microsoft/vscode-python/issues/12656)) 1. Add more telemetry for "Select Interpreter" command. ([#12722](https://github.com/Microsoft/vscode-python/issues/12722)) +1. Add tests for trusted notebooks. + ([#12554](https://github.com/Microsoft/vscode-python/issues/12554)) +1. Update categories in `package.json`. + ([#12844](https://github.com/Microsoft/vscode-python/issues/12844)) ### Thanks diff --git a/news/1 Enhancements/10496.md b/news/1 Enhancements/10496.md deleted file mode 100644 index e486012325cb..000000000000 --- a/news/1 Enhancements/10496.md +++ /dev/null @@ -1,4 +0,0 @@ -Opening notebooks in the preview Notebook editor for [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). -* Install Python extension in the latest [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/). -* Wait for `Python Extension` to get activated (e.g. open a `Python` file). -* Right click on an `*.ipynb (Jupyter Notebook)` file and select `Open in preview Notebook Editor`. diff --git a/news/3 Code Health/12554.md b/news/3 Code Health/12554.md deleted file mode 100644 index 926f9f320057..000000000000 --- a/news/3 Code Health/12554.md +++ /dev/null @@ -1 +0,0 @@ -Add tests for trusted notebooks. diff --git a/news/3 Code Health/12844.md b/news/3 Code Health/12844.md deleted file mode 100644 index 004246586d91..000000000000 --- a/news/3 Code Health/12844.md +++ /dev/null @@ -1 +0,0 @@ -Update categories in `package.json`. diff --git a/package.json b/package.json index 1a7fdca8262e..36674cbae8dd 100644 --- a/package.json +++ b/package.json @@ -369,7 +369,8 @@ "icon": { "light": "resources/light/export_to_python.svg", "dark": "resources/dark/export_to_python.svg" - } + }, + "enablement": "notebookViewType == jupyter-notebook && python.datascience.isnotebooktrusted" }, { "command": "python.datascience.exportAsPythonScript", @@ -702,16 +703,7 @@ "light": "resources/light/un-trusted.svg", "dark": "resources/dark/un-trusted.svg" }, - "enablement": "notebookEditorFocused && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" - }, - { - "command": "python.datascience.notebookeditor.trusted", - "title": "%DataScience.notebookIsTrusted%", - "category": "Python", - "icon": { - "light": "resources/light/trusted.svg", - "dark": "resources/dark/trusted.svg" - } + "enablement": "notebookViewType == jupyter-notebook && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" }, { "command": "python.datascience.notebookeditor.runallcells", @@ -877,25 +869,19 @@ "command": "python.datascience.notebookeditor.restartkernel", "title": "%python.command.python.datascience.restartkernel.title%", "group": "navigation", - "when": "notebookEditorFocused" + "when": "notebookViewType == jupyter-notebook" }, { "command": "python.datascience.notebookeditor.trust", "title": "%DataScience.trustNotebookCommandTitle%", "group": "navigation@1", - "when": "notebookEditorFocused && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" - }, - { - "command": "python.datascience.notebookeditor.trusted", - "title": "%DataScience.notebookIsTrusted%", - "group": "navigation@1", - "when": "notebookEditorFocused && python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" + "when": "notebookViewType == jupyter-notebook && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" }, { "command": "python.datascience.export", "title": "%DataScience.notebookExportAs%", "group": "navigation", - "when": "notebookEditorFocused" + "when": "notebookViewType == jupyter-notebook" } ], "explorer/context": [ @@ -940,19 +926,19 @@ "command": "python.datascience.exportAsPythonScript", "title": "%python.command.python.datascience.exportAsPythonScript.title%", "category": "Python", - "when": "python.datascience.isnativeactive && python.datascience.featureenabled" + "when": "python.datascience.isnativeactive && python.datascience.featureenabled && python.datascience.isnotebooktrusted" }, { "command": "python.datascience.exportToHTML", "title": "%python.command.python.datascience.exportToHTML.title%", "category": "Python", - "when": "python.datascience.isnativeactive && python.datascience.featureenabled" + "when": "python.datascience.isnativeactive && python.datascience.featureenabled && python.datascience.isnotebooktrusted" }, { "command": "python.datascience.exportToPDF", "title": "%python.command.python.datascience.exportToPDF.title%", "category": "Python", - "when": "python.datascience.isnativeactive && python.datascience.featureenabled" + "when": "python.datascience.isnativeactive && python.datascience.featureenabled && python.datascience.isnotebooktrusted" }, { "command": "python.switchOffInsidersChannel", @@ -1175,12 +1161,6 @@ "category": "Python", "when": "python.datascience.featureenabled && notebookEditorFocused && !python.datascience.isnotebooktrusted && python.datascience.trustfeatureenabled" }, - { - "command": "python.datascience.notebookeditor.trusted", - "title": "%DataScience.notebookIsTrusted%", - "category": "Python", - "when": "config.noExists" - }, { "command": "python.datascience.notebookeditor.runallcells", "title": "%python.command.python.datascience.notebookeditor.runallcells.title%", diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index dc310105fdb1..9e35df989c56 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -184,5 +184,4 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu [DSCommands.GatherQuality]: [string]; [DSCommands.EnableLoadingWidgetsFrom3rdPartySource]: [undefined | never]; [DSCommands.TrustNotebook]: [undefined | never | Uri]; - [DSCommands.TrustedNotebook]: [undefined | never]; } diff --git a/src/client/datascience/constants.ts b/src/client/datascience/constants.ts index 7d7b732a1e4c..5a371aa92ff5 100644 --- a/src/client/datascience/constants.ts +++ b/src/client/datascience/constants.ts @@ -91,7 +91,6 @@ export namespace Commands { export const OpenNotebookNonCustomEditor = 'python.datascience.notebookeditor.open'; export const GatherQuality = 'python.datascience.gatherquality'; export const TrustNotebook = 'python.datascience.notebookeditor.trust'; - export const TrustedNotebook = 'python.datascience.notebookeditor.trusted'; export const EnableLoadingWidgetsFrom3rdPartySource = 'python.datascience.enableLoadingWidgetScriptsFromThirdPartySource'; } diff --git a/src/client/datascience/interactive-ipynb/digestStorage.ts b/src/client/datascience/interactive-ipynb/digestStorage.ts index cba0fa78c91e..0db3feed5fa5 100644 --- a/src/client/datascience/interactive-ipynb/digestStorage.ts +++ b/src/client/datascience/interactive-ipynb/digestStorage.ts @@ -3,7 +3,7 @@ import { inject, injectable } from 'inversify'; import * as os from 'os'; import * as path from 'path'; import { Uri } from 'vscode'; -import { traceError } from '../../common/logger'; +import { traceError, traceInfo } from '../../common/logger'; import { isFileNotFoundError } from '../../common/platform/errors'; import { IFileSystem } from '../../common/platform/types'; import { IExtensionContext } from '../../common/types'; @@ -13,6 +13,7 @@ import { IDigestStorage } from '../types'; export class DigestStorage implements IDigestStorage { public readonly key: Promise; private digestDir: Promise; + private loggedFileLocations = new Set(); constructor( @inject(IFileSystem) private fs: IFileSystem, @@ -26,6 +27,10 @@ export class DigestStorage implements IDigestStorage { const fileLocation = await this.getFileLocation(uri); // Since the signature is a hex digest, the character 'z' is being used to delimit the start and end of a single digest await this.fs.appendFile(fileLocation, `z${signature}z\n`); + if (!this.loggedFileLocations.has(fileLocation)) { + traceInfo(`Wrote trust for ${uri.toString()} to ${fileLocation}`); + this.loggedFileLocations.add(fileLocation); + } } public async containsDigest(uri: Uri, signature: string) { diff --git a/src/client/datascience/interactive-ipynb/trustCommandHandler.ts b/src/client/datascience/interactive-ipynb/trustCommandHandler.ts index 09ee31f49e62..f7834234477f 100644 --- a/src/client/datascience/interactive-ipynb/trustCommandHandler.ts +++ b/src/client/datascience/interactive-ipynb/trustCommandHandler.ts @@ -13,7 +13,6 @@ import '../../common/extensions'; import { IDisposableRegistry, IExperimentService } from '../../common/types'; import { swallowExceptions } from '../../common/utils/decorators'; import { DataScience } from '../../common/utils/localize'; -import { noop } from '../../common/utils/misc'; import { Commands } from '../constants'; import { INotebookStorageProvider } from '../interactive-ipynb/notebookStorageProvider'; import { INotebookEditorProvider, ITrustService } from '../types'; @@ -39,7 +38,6 @@ export class TrustCommandHandler implements IExtensionSingleActivationService { const context = new ContextKey('python.datascience.trustfeatureenabled', this.commandManager); context.set(true).ignoreErrors(); this.disposables.push(this.commandManager.registerCommand(Commands.TrustNotebook, this.onTrustNotebook, this)); - this.disposables.push(this.commandManager.registerCommand(Commands.TrustedNotebook, noop)); } @swallowExceptions('Trusting notebook') private async onTrustNotebook(uri?: Uri) { diff --git a/src/client/datascience/notebookStorage/notebookModel.ts b/src/client/datascience/notebookStorage/notebookModel.ts index 0bbe75705836..3b031870d81d 100644 --- a/src/client/datascience/notebookStorage/notebookModel.ts +++ b/src/client/datascience/notebookStorage/notebookModel.ts @@ -90,7 +90,7 @@ export class NativeEditorNotebookModel extends BaseNotebookModel { // Dirty state comes from undo. At least VS code will track it that way. However // skip file changes as we don't forward those to VS code - if (change.kind !== 'save' && change.kind !== 'saveAs') { + if (change.kind !== 'save' && change.kind !== 'saveAs' && change.kind !== 'updateTrust') { this.changeCount += 1; } diff --git a/src/datascience-ui/interactive-common/trustMessage.tsx b/src/datascience-ui/interactive-common/trustMessage.tsx index a5d55993082b..c97a97e6c6cb 100644 --- a/src/datascience-ui/interactive-common/trustMessage.tsx +++ b/src/datascience-ui/interactive-common/trustMessage.tsx @@ -22,7 +22,9 @@ export class TrustMessage extends React.PureComponent { }; const dynamicStyle: React.CSSProperties = { maxWidth: getMaxWidth(textSize), - color: this.props.isNotebookTrusted ? undefined : 'var(--vscode-editorError-foreground)', + color: this.props.isNotebookTrusted + ? 'var(--vscode-editor-foreground)' + : 'var(--vscode-editorError-foreground)', cursor: this.props.isNotebookTrusted ? undefined : 'pointer' }; diff --git a/src/datascience-ui/native-editor/addCellLine.tsx b/src/datascience-ui/native-editor/addCellLine.tsx index 8f275cc072ce..f5513aafecc9 100644 --- a/src/datascience-ui/native-editor/addCellLine.tsx +++ b/src/datascience-ui/native-editor/addCellLine.tsx @@ -25,19 +25,23 @@ export class AddCellLine extends React.Component { const plus = this.props.includePlus ? ( ) : null; + const disabled = !this.props.isNotebookTrusted; + const innerFilter = disabled ? 'image-button-inner-disabled-filter' : ''; return (
);