microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.23k stars 29.29k forks source link

API request - Support interactive window natively #154983

Open rchiodo opened 2 years ago

rchiodo commented 2 years ago

As described in https://github.com/microsoft/vscode/issues/151994 extensions have to have special knowledge about the interactive window URI in order to handle things like inserting new cells and intellisense.

This issue is to:

  // Under vscode.workspace namespace
        /**
         * Creates a new interactive window
         * @param resource interactive resource uri 
         * @param title title of the editor
         * @param initialController controller to start with
         * @param options options for viewing
         */
        export function openInteractiveWindow(resource?: Uri, title?: string, initialController?: NotebookController, options?: { viewColumn?: ViewColumn; preserveFocus?: boolean }): Thenable<NotebookDocument>;

// Under vscode.NotebookEdit class

        /**
         * Utility to create an edit that adds to an interactive window
         * @param newCells the new cells
         */
        static addInteractiveCells(newCells: NotebookCellData[]): NotebookEdit;

Additionally the notebook API for the interactive window should include the input box in its list of cells.

amunger commented 2 years ago

an alternative to addInteractiveCells could be to add an override to insertCells with no index parameter. VS Code could determine that the notebook represents an Interactive window and insert to the correct place (n-1), otherwise just append to the end.

                 /**
         * Utility to create an edit that appends cells to a notebook or interactive window.
         *
         * @param newCells The new notebook cells.
         */
        static insertCells(newCells: NotebookCellData[]): NotebookEdit;
jrieken commented 2 years ago

Some post-sync findings/thoughts:

rchiodo commented 2 years ago

/cc @rebornix

amunger commented 2 months ago

with the flag set only some edit operations are allowed, namely only to insert above the "input cell" add some suger-edit-functions to make the former restriction simpler

https://github.com/microsoft/vscode/pull/227258 would enforce the edit restrictions, but adding the more convenient API functions looks pretty tricky since notebook edits are created without any reference to a model:

static insertCells(index: number, newCells: NotebookCellData[]): NotebookEdit;

and the NotebookEdit object returned has a required range field. Making a NotebookEdit object that represents cells that should be appended to the end would likely break any type checking.