diff --git a/src/microsoft-trydotnet-editor/package-lock.json b/src/microsoft-trydotnet-editor/package-lock.json index 3131a5362..a4c541517 100644 --- a/src/microsoft-trydotnet-editor/package-lock.json +++ b/src/microsoft-trydotnet-editor/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@microsoft/polyglot-notebooks": "1.0.441801", + "@microsoft/polyglot-notebooks": "1.0.740304", "monaco-editor": "0.56.0", "rxjs": "7.8.2", "uuid": "14.0.1" @@ -608,9 +608,9 @@ } }, "node_modules/@microsoft/polyglot-notebooks": { - "version": "1.0.441801", - "resolved": "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/npm/registry/@microsoft/polyglot-notebooks/-/polyglot-notebooks-1.0.441801.tgz", - "integrity": "sha1-vGUZjaNCd1Wv4b4VL1yH/7FOM5Q=", + "version": "1.0.740304", + "resolved": "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/npm/registry/@microsoft/polyglot-notebooks/-/polyglot-notebooks-1.0.740304.tgz", + "integrity": "sha1-v9rBexPWAg2xA+0KSxw/Q+1emO8=", "license": "MIT", "dependencies": { "rxjs": "7.5.6", diff --git a/src/microsoft-trydotnet-editor/package.json b/src/microsoft-trydotnet-editor/package.json index 289f16aac..9994c7b83 100644 --- a/src/microsoft-trydotnet-editor/package.json +++ b/src/microsoft-trydotnet-editor/package.json @@ -53,7 +53,7 @@ "webpack-cli": "7.0.2" }, "dependencies": { - "@microsoft/polyglot-notebooks": "1.0.441801", + "@microsoft/polyglot-notebooks": "1.0.740304", "monaco-editor": "0.56.0", "rxjs": "7.8.2", "uuid": "14.0.1" diff --git a/src/microsoft-trydotnet-editor/src/projectKernel.ts b/src/microsoft-trydotnet-editor/src/projectKernel.ts index 04efe99cd..c5474beb0 100644 --- a/src/microsoft-trydotnet-editor/src/projectKernel.ts +++ b/src/microsoft-trydotnet-editor/src/projectKernel.ts @@ -25,9 +25,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.SubmitCodeType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleSubmitCode(commandInvocation); } }); @@ -44,7 +49,10 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.OpenDocumentType, handle: async (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return; + } await this.handleOpenDocument(commandInvocation); let command = commandInvocation.commandEnvelope.command; this._openDocument = { @@ -60,8 +68,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestDiagnosticsType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestDiagnostics(commandInvocation); } }); @@ -69,8 +83,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestCompletionsType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestCompletions(commandInvocation); } }); @@ -78,8 +98,14 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestHoverTextType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestHoverText(commandInvocation); } }); @@ -87,27 +113,19 @@ export abstract class ProjectKernel extends polyglotNotebooks.Kernel { this.registerCommandHandler({ commandType: polyglotNotebooks.RequestSignatureHelpType, handle: (commandInvocation: polyglotNotebooks.IKernelCommandInvocation) => { - this.throwIfProjectIsNotOpened(); - this.throwIffDocumentIsNotOpened(); + if (!this._project) { + commandInvocation.context.fail(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); + return Promise.resolve(); + } + if (!this._openDocument) { + commandInvocation.context.fail(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); + return Promise.resolve(); + } return this.handleRequestSignatureHelp(commandInvocation); } }); } - protected throwIfProjectIsNotOpened() { - if (!this._project) { - // todo : align error message with .NET - throw new Error(`Project must be opened, send the command '${polyglotNotebooks.OpenProjectType}' first.`); - } - } - - protected throwIffDocumentIsNotOpened() { - if (!this._openDocument) { - // todo : align error message with .NET - throw new Error(`Document must be opened, send the command '${polyglotNotebooks.OpenDocumentType}' first.`); - } - } - protected abstract handleOpenProject(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise; protected abstract handleRequestDiagnostics(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise; protected abstract handleRequestCompletions(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise;