Pass associated notebook document to kernel source command (#163701)

This commit is contained in:
Peng Lyu 2022-10-14 14:33:05 -07:00 committed by GitHub
parent 1afc67ea7f
commit 5612f80f8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -17,6 +17,7 @@ export const enum MarshalledId {
CommentThreadNode,
TimelineActionContext,
NotebookCellActionContext,
NotebookActionContext,
TestItemContext,
Date
}

View file

@ -92,6 +92,13 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
return cell.apiCell;
}
}
if (arg && arg.$mid === MarshalledId.NotebookActionContext) {
const notebookUri = arg.uri;
const data = this._documents.get(notebookUri);
if (data) {
return data.apiNotebook;
}
}
return arg;
}
});

View file

@ -15,6 +15,7 @@ import { runWhenIdle } from 'vs/base/common/async';
import { IMenu, IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IAction } from 'vs/base/common/actions';
import { MarshalledId } from 'vs/base/common/marshallingIds';
class KernelInfo {
@ -53,6 +54,7 @@ class SourceAction extends Disposable implements ISourceAction {
constructor(
readonly action: IAction,
readonly model: INotebookTextModelLike,
readonly isPrimary: boolean
) {
super();
@ -72,7 +74,11 @@ class SourceAction extends Disposable implements ISourceAction {
private async _runAction(): Promise<void> {
try {
await this.action.run();
await this.action.run({
uri: this.model.uri,
$mid: MarshalledId.NotebookActionContext
});
} catch (error) {
console.warn(`Kernel source command failed: ${error}`);
}
@ -314,7 +320,7 @@ export class NotebookKernelService extends Disposable implements INotebookKernel
groups.forEach(group => {
const isPrimary = /^primary/.test(group[0]);
group[1].forEach(action => {
const sourceAction = new SourceAction(action, isPrimary);
const sourceAction = new SourceAction(action, notebook, isPrimary);
const stateChangeListener = sourceAction.onDidChangeState(() => {
this._onDidChangeSourceActions.fire({
notebook: notebook.uri