Skip to content
Merged
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
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