Skip to content

API request - Support interactive window natively #154983

Open

Description

@rchiodo

As described in #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:

  • Eliminate URI parsing in extensions and language servers
  • Eliminate the usage of a command to create an interactive window
  • Propose an API for creating interactive windows (based on the 'interactive.open' command used now)
  • Propose an API for adding new cells into the history
  • Change the current notebook API to include the special 'input' cell as part of the interactive notebook.
  // 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.

Activity

  1. added
    feature-request
    on Jul 12, 2022
  2. amunger commented on Jul 12, 2022

    @amunger
    Collaborator

    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;
    
  3. jrieken commented on Jul 19, 2022

    @jrieken
    Contributor

    Some post-sync findings/thoughts:

    • interactive window should be fully backed by notebook document, e.g also include the "input cell"
    • the NotebookDocument should have a flag to signal that it is in interactive mode
    • 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
    • add some way to open a new notebook as interactive
    • ? figure out if the NotebookController#updateAffinity is good enough to strong-bind a controller to an interactive document
    • ? should/can all notebook types support interactive mode
  4. rchiodo commented on Jul 19, 2022

    @rchiodo
    ContributorAuthor
  5. amunger commented on Sep 3, 2024

    @amunger
    Collaborator

    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

    #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.

  6. amunger commented on Nov 11, 2024

    @amunger
    Collaborator

    Current proposed API

    export interface NotebookDocumentShowOptions {
    	/**
    	 * The notebook should be opened in a REPL editor,
    	 * where the last cell of the notebook is an input box and the other cells are the read-only history.
    	 * When the value is a string, it will be used as the label for the editor tab.
    	 */
    	readonly asRepl?: boolean | string | {
    		/**
    		* The label to be used for the editor tab.
    		*/
    		readonly label: string;
    	};
    }
    
    export interface NotebookEditor {
    	/**
    	 * Information about the REPL editor if the notebook was opened as a repl.
    	 */
    	replOptions?: {
    		/**
    		 * The index where new cells should be appended.
    		 */
    		appendIndex: number;
    	};
    }
    

    Notes

    • The asRepl flag only has an effect if the notebook is not already shown
    • The appendIndex on the editor means you need the editor object to edit the document
      • Getting an editor instance requires(?) calling openEditor, or holding that object from a previous call
  7. removed their assignment
    on Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api-proposalfeature-requestinteractive-window

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions