Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/microsoft-trydotnet-editor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/microsoft-trydotnet-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
70 changes: 44 additions & 26 deletions src/microsoft-trydotnet-editor/src/projectKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand All @@ -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 = <polyglotNotebooks.OpenDocument>commandInvocation.commandEnvelope.command;
this._openDocument = {
Expand All @@ -60,54 +68,64 @@ 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);
}
});

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);
}
});

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);
}
});

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<void>;
protected abstract handleRequestDiagnostics(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise<void>;
protected abstract handleRequestCompletions(commandInvocation: polyglotNotebooks.IKernelCommandInvocation): Promise<void>;
Expand Down