Skip to content
Closed
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
12 changes: 1 addition & 11 deletions src/vs/workbench/api/browser/mainThreadNotebookEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
*--------------------------------------------------------------------------------------------*/

// --- Start Positron ---
import { POSITRON_NOTEBOOK_EDITOR_ID } from '../../contrib/positronNotebook/common/positronNotebookCommon.js';
import { POSITRON_NOTEBOOK_EDITOR_ID, usingPositronNotebooks } from '../../contrib/positronNotebook/common/positronNotebookCommon.js';
import { checkPositronNotebookEnabled } from '../../contrib/positronNotebook/browser/positronNotebookExperimentalConfig.js';
import { usingPositronNotebooks } from '../../services/positronNotebook/common/positronNotebookUtils.js';
// --- End Positron ---
import { DisposableStore, dispose } from '../../../base/common/lifecycle.js';
import { equals } from '../../../base/common/objects.js';
Expand Down Expand Up @@ -123,15 +122,6 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
// --- End Positron ---

const editorPane = await this._editorService.openEditor({ resource: URI.revive(resource), options: editorOptions }, columnToEditorGroup(this._editorGroupService, this._configurationService, options.position));
// --- Start Positron ---
if (editorPane?.getId() === POSITRON_NOTEBOOK_EDITOR_ID) {
// Positron notebook is already open, just return a synthetic ID
// We can't return the actual notebook editor ID because Positron notebooks
// don't implement INotebookEditor interface yet (https://github.com/posit-dev/positron/issues/9440)
const uri = URI.revive(resource);
return `positron-notebook-${uri.toString()}`;
}
// --- End Positron ---
const notebookEditor = getNotebookEditorFromEditorPane(editorPane);

if (notebookEditor) {
Expand Down
8 changes: 0 additions & 8 deletions src/vs/workbench/api/common/extHostNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
if (editor) {
return editor;
}
// --- Start Positron ---
// Positron notebooks don't implement INotebookEditor yet, so mock the result.
// This will lead to unexpected errors in extensions that use this API
// until we implement INotebookEditor (https://github.com/posit-dev/positron/issues/9440).
if (editorId.startsWith('positron-notebook-')) {
return {} as any;
}
// --- End Positron ---

if (editorId) {
throw new Error(`Could NOT open editor for "${notebook.uri.toString()}" because another editor opened in the meantime.`);
Expand Down
35 changes: 0 additions & 35 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import { CellUri } from '../../notebook/common/notebookCommon.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { NotebookTextDiffEditor } from '../../notebook/browser/diff/notebookDiffEditor.js';
import { NotebookMultiTextDiffEditor } from '../../notebook/browser/diff/notebookMultiDiffEditor.js';
// --- Start Positron ---
// Imports to support inline chat in Positron notebooks.
import { IPositronNotebookService } from '../../../services/positronNotebook/browser/positronNotebookService.js';
// --- End Positron ---

export class InlineChatNotebookContribution {

Expand All @@ -28,10 +24,6 @@ export class InlineChatNotebookContribution {
@IInlineChatSessionService sessionService: IInlineChatSessionService,
@IEditorService editorService: IEditorService,
@INotebookEditorService notebookEditorService: INotebookEditorService,
// --- Start Positron ---
// Imports to support inline chat in Positron notebooks.
@IPositronNotebookService positronNotebookService: IPositronNotebookService,
// --- End Positron ---
) {

this._store.add(sessionService.registerSessionKeyComputer(Schemas.vscodeNotebookCell, {
Expand Down Expand Up @@ -65,19 +57,6 @@ export class InlineChatNotebookContribution {
// }
}
}
// --- Start Positron ---
// To support inline chat in Positron notebooks:
// construct a session comparison key from the corresponding notebook
for (const positronInstance of positronNotebookService.listInstances(data.notebook)) {
const candidate = `<positron-notebook>${positronInstance.id}#${uri}`;
if (!fallback) {
fallback = candidate;
}
if (positronInstance.hasCodeEditor(editor)) {
return candidate;
}
}
// --- End Positron ---

if (fallback) {
return fallback;
Expand Down Expand Up @@ -117,20 +96,6 @@ export class InlineChatNotebookContribution {
}
}
}
// --- Start Positron ---
// To support inline chat in Positron notebooks:
// cancel existing chat sessions when a new one is started.
for (const positronInstance of positronNotebookService.listInstances(candidate.notebook)) {
if (positronInstance.hasCodeEditor(newSessionEditor)) {
for (const { editor } of positronInstance.cells.get()) {
if (editor && editor !== newSessionEditor) {
InlineChatController.get(editor)?.acceptSession();
}
}
break;
}
}
// --- End Positron ---
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ import { getFormattedNotebookMetadataJSON } from '../common/model/notebookMetada
import { NotebookOutputEditor } from './outputEditor/notebookOutputEditor.js';
import { NotebookOutputEditorInput } from './outputEditor/notebookOutputEditorInput.js';
// --- Start Positron ---
import { IPositronNotebookService } from '../../../services/positronNotebook/browser/positronNotebookService.js';
import { IPositronNotebookService } from '../../positronNotebook/browser/positronNotebookService.js';
// --- End Positron ---

/*--------------------------------------------------------------------------------------------- */
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import { IContextKeyService } from '../../../../platform/contextkey/common/conte
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
import { IObservable } from '../../../../base/common/observable.js';
import { INotebookTextDiffEditor } from './diff/notebookDiffEditorBrowser.js';
// --- Start Positron ---
import { POSITRON_NOTEBOOK_EDITOR_ID } from '../../positronNotebook/common/positronNotebookCommon.js';
// --- End Positron ---

//#region Shared commands
export const EXPAND_CELL_INPUT_COMMAND_ID = 'notebook.cell.expandCellInput';
Expand Down Expand Up @@ -926,7 +929,9 @@ export function getNotebookEditorFromEditorPane(editorPane?: IEditorPane): INote
return;
}

if (editorPane.getId() === NOTEBOOK_EDITOR_ID) {
// --- Start Positron ---
if (editorPane.getId() === NOTEBOOK_EDITOR_ID || editorPane.getId() === POSITRON_NOTEBOOK_EDITOR_ID) {
// --- End Positron ---
return editorPane.getControl() as INotebookEditor | undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ICustomEditorLabelService } from '../../../services/editor/common/custo
// --- Start Positron ---
import { IRuntimeSessionService } from '../../../services/runtimeSession/common/runtimeSessionService.js';
import { ILogService } from '../../../../platform/log/common/log.js';
import { POSITRON_NOTEBOOK_EDITOR_INPUT_ID } from '../../positronNotebook/common/positronNotebookCommon.js';
// --- End Positron ---

export interface NotebookEditorInputOptions {
Expand Down Expand Up @@ -419,5 +420,8 @@ export function isCompositeNotebookEditorInput(thing: unknown): thing is ICompos
export function isNotebookEditorInput(thing: EditorInput | undefined): thing is NotebookEditorInput {
return !!thing
&& typeof thing === 'object'
&& thing.typeId === NotebookEditorInput.ID;
// --- Start Positron ---
// && thing.typeId === NotebookEditorInput.ID;
&& (thing.typeId === NotebookEditorInput.ID || thing.typeId === POSITRON_NOTEBOOK_EDITOR_INPUT_ID);
// --- End Positron ---
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { IPositronConsoleService, POSITRON_CONSOLE_VIEW_ID } from '../../../serv
import { IExecutionHistoryService } from '../../../services/positronHistory/common/executionHistoryService.js';
import { CodeAttributionSource, IConsoleCodeAttribution } from '../../../services/positronConsole/common/positronConsoleCodeExecution.js';
import { ICommandService } from '../../../../platform/commands/common/commands.js';
import { POSITRON_NOTEBOOK_CELL_EDITOR_FOCUSED } from '../../../services/positronNotebook/browser/ContextKeysManager.js';
import { POSITRON_NOTEBOOK_CELL_EDITOR_FOCUSED } from '../../positronNotebook/browser/ContextKeysManager.js';
import { getContextFromActiveEditor } from '../../notebook/browser/controller/coreActions.js';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as DOM from '../../../../base/browser/dom.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { IContextKey, IContextKeyService, IScopedContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { IContextKey, IScopedContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';

/**
* Context key that is set when the Positron notebook editor container is focused. This will _not_ be true when the user is editing a cell.
Expand Down Expand Up @@ -97,28 +97,17 @@ export function resetCellContextKeys(keys: IPositronNotebookCellContextKeys | un
*/
export class PositronNotebookContextKeyManager extends Disposable {
//#region Private Properties
private _container?: HTMLElement;
private _scopedContextKeyService?: IScopedContextKeyService;
//#endregion Private Properties

//#region Public Properties
positronEditorFocus?: IContextKey<boolean>;
//#endregion Public Properties

//#region Constructor & Dispose
constructor(
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
) {
super();
}

//#endregion Constructor & Dispose

//#region Public Methods
setContainer(container: HTMLElement, scopedContextKeyService?: IScopedContextKeyService) {
this._container = container;
setContainer(container: HTMLElement, scopedContextKeyService: IScopedContextKeyService) {
this.positronEditorFocus?.reset();
this._scopedContextKeyService = scopedContextKeyService ?? this._contextKeyService.createScoped(this._container);
this._scopedContextKeyService = scopedContextKeyService;

this.positronEditorFocus = POSITRON_NOTEBOOK_EDITOR_CONTAINER_FOCUSED.bindTo(this._scopedContextKeyService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { SelectionStateMachine } from './selectionMachine.js';
import { ILanguageRuntimeSession } from '../../../services/runtimeSession/common/runtimeSessionService.js';
import { Event } from '../../../../base/common/event.js';
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
import { NotebookOptions } from '../../notebook/browser/notebookOptions.js';
import { NotebookTextModel } from '../../notebook/common/model/notebookTextModel.js';
import { IBaseCellEditorOptions, INotebookEditorOptions, INotebookEditorViewState } from '../../notebook/browser/notebookBrowser.js';
import { INotebookKernel } from '../../notebook/common/notebookKernelService.js';
/**
* Represents the possible states of a notebook's kernel connection
*/
Expand Down Expand Up @@ -99,17 +103,42 @@ export interface IPositronNotebookInstance {
*/
readonly isDisposed: boolean;

/**
* The current text model for the notebook, representing its content and structure.
*/
readonly textModel: NotebookTextModel | undefined;

/**
* Event that fires when the notebook's text model changes.
*/
readonly onDidChangeModel: Event<NotebookTextModel | undefined>;

/**
* Indicates whether this notebook is read-only and cannot be edited.
*/
readonly isReadOnly: boolean;

/**
* Options for how the notebook should be displayed. Currently not really used but will be as
* notebook gets fleshed out.
*/
readonly notebookOptions: NotebookOptions;

/**
* The current selected kernel for the notebook, if any.
*/
readonly kernel: IObservable<INotebookKernel | undefined>;

/**
* Event that fires when the cells container is scrolled
*/
readonly onDidScrollCellsContainer: Event<void>;

// ===== Methods =====
getEditorViewState(): INotebookEditorViewState;
getBaseCellEditorOptions(language: string): IBaseCellEditorOptions;
setOptions(options: INotebookEditorOptions | undefined): Promise<void>;

/**
* Executes the specified cells in order.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ import { PositronNotebookEditorInput } from './PositronNotebookEditorInput.js';
import { ILogService } from '../../../../platform/log/common/log.js';
import { NotebookVisibilityProvider } from './NotebookVisibilityContext.js';
import { observableValue } from '../../../../base/common/observable.js';
import { PositronNotebookEditorControl } from './PositronNotebookEditorControl.js';
import { PositronNotebookEditorControl } from './adapters/PositronNotebookEditorControl.js';
import { POSITRON_NOTEBOOK_EDITOR_ID } from '../common/positronNotebookCommon.js';
import { AbstractEditorWithViewState } from '../../../browser/parts/editor/editorWithViewState.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { URI } from '../../../../base/common/uri.js';
import { isEqual } from '../../../../base/common/resources.js';
import { EditorInput } from '../../../common/editor/editorInput.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { PositronNotebookInstance } from './PositronNotebookInstance.js';


/**
Expand Down Expand Up @@ -75,6 +76,8 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo

private _containerScopedContextKeyService: IScopedContextKeyService | undefined;

private notebookInstance: PositronNotebookInstance | undefined;

/**
* The editor control, used by other features to access the code editor widget of the selected cell.
*/
Expand Down Expand Up @@ -110,7 +113,7 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo

}

//#region AbstractEditorWithViewState implementation
//#region AbstractEditorWithViewState

/**
* The actual method to provide for gathering the view state
Expand Down Expand Up @@ -158,7 +161,9 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo
return input.resource;
}

//#endregion AbstractEditorWithViewState implementation
//#endregion AbstractEditorWithViewState

//#region EditorPane

/**
* Event emitter for letting the IDE know that there has been a selection change in the
Expand All @@ -184,12 +189,6 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo
*/
private readonly _isVisible = observableValue<boolean>('isVisible', false);


// Getter for notebook instance to avoid having to cast the input every time.
get notebookInstance() {
return this._input?.notebookInstance;
}

protected override setEditorVisible(visible: boolean): void {
this._isVisible.set(visible, undefined);
super.setEditorVisible(visible);
Expand Down Expand Up @@ -239,12 +238,14 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo
// without having to pass the options to the resolve method.
input.editorOptions = options;

// TODO: Who should dispose notebook instances?
this.notebookInstance = PositronNotebookInstance.getOrCreate(input, undefined, this.instantiationService);

// Update the editor control given the notebook instance.
// This has to be done before we `await super.setInput` since that fires events
// with listeners that call `this.getControl()` expecting an up-to-date control
// i.e. with `activeCodeEditor` being the editor of the selected cell in the notebook.
const { notebookInstance } = input;
this._control.value = new PositronNotebookEditorControl(notebookInstance);
this._control.value = this.instantiationService.createInstance(PositronNotebookEditorControl, this.notebookInstance);

await super.setInput(input, options, context, token);

Expand All @@ -261,7 +262,7 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo
}

// Set the notebook instance model
notebookInstance.setModel(model.notebook, options?.viewState);
this.notebookInstance.setModel(model.notebook, options?.viewState);

// Trigger the selection change event when the notebook was edited.
this._instanceDisposableStore.add(
Expand All @@ -274,7 +275,7 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo

const scopedContextKeyService = this._renderReact();

notebookInstance.attachView(this._parentDiv, scopedContextKeyService);
this.notebookInstance.attachView(this._parentDiv, scopedContextKeyService);
}

override clearInput(): void {
Expand Down Expand Up @@ -318,6 +319,10 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo
return this._control.value;
}

//#endregion EditorPane

//#region React

/**
* Gets or sets the PositronReactRenderer for the PositronNotebook component.
*/
Expand Down Expand Up @@ -371,6 +376,7 @@ export class PositronNotebookEditor extends AbstractEditorWithViewState<INoteboo
return scopedContextKeyService;
}

//#endregion React

/**
* dispose override method.
Expand Down
Loading