Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better API to associate a notebook cell document with its notebook #102091

Open
jrieken opened this issue Jul 10, 2020 · 6 comments
Open

Better API to associate a notebook cell document with its notebook #102091

jrieken opened this issue Jul 10, 2020 · 6 comments
Assignees
Labels
api-finalization feature-request Request for new features or functionality notebook-api

Comments

@jrieken
Copy link
Member

jrieken commented Jul 10, 2020

A notebook document contains cell documents, which are vscode.TextDocument types. There is no easy/nice way to get to a notebook from a document. Ideas

  • add a util like notebook.findContainerNotebook(document: TextDocument): NotebookDocument | undefined
  • add a pointer from the document, e.g TextDocument#notebook: NotebookDocument | undefined
@jrieken jrieken self-assigned this Jul 10, 2020
@jrieken jrieken added api-proposal feature-request Request for new features or functionality notebook labels Jul 10, 2020
@jrieken jrieken modified the milestones: Backlog, July 2020 Jul 10, 2020
@jrieken jrieken modified the milestones: July 2020, August 2020 Jul 17, 2020
@jrieken
Copy link
Member Author

jrieken commented Jul 17, 2020

fyi @rebornix

@jrieken
Copy link
Member Author

jrieken commented Sep 15, 2020

Closing, the proposal is done but currently unused. We'll see if we keep this when finalizing the whole API

@jrieken jrieken closed this as completed Sep 15, 2020
@jrieken jrieken added the verification-needed Verification of issue is requested label Sep 29, 2020
@roblourens roblourens added the verified Verification succeeded label Sep 30, 2020
@jrieken jrieken added the on-release-notes Issue/pull request mentioned in release notes label Oct 1, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2020
@jrieken jrieken reopened this May 31, 2021
@microsoft microsoft unlocked this conversation May 31, 2021
@jrieken jrieken added api-finalization and removed api-proposal on-release-notes Issue/pull request mentioned in release notes verification-needed Verification of issue is requested verified Verification succeeded labels May 31, 2021
@jrieken jrieken modified the milestones: September 2020, June 2021 May 31, 2021
@jrieken
Copy link
Member Author

jrieken commented Jun 8, 2021

  • Relation is: text document to notebook cell (not notebook itself)
  • Challenge: text document doesn't own the cell
  • Maybe: explicit find function might be better

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Jun 15, 2021

@jrieken Thought I'd let u know how I'm using this today in my personal extensions:

  • In Kusto notebook extension
    • I use this in completions provider, I need a way to determine whether a text document belongs to a Notebook document or not (and then get information about that notebook document/metadata).
    • Toady when documents are opened (even triggered for notebook cells), i get the corresponding notebook information of the associated cell, I send this information to the language server
    • Now the language server can map the text Uri back to a notebook (if it is a cell text document)
  • In an extension for Jupyter notebooks
    • I change the language of cells based on the contents of the cell (e.g. if cell has %kql, then I change the language of that cell from Python to to kusto (again, this can only be done if I know for a fact this text document belongs to a Notebook cell)
  • Also using in another editor to add line/column numbers for cell statusbar.

For all of these, I also need the window.activeNotebookEditor API (which too is a proposed API).

@jrieken
Copy link
Member Author

jrieken commented Jun 21, 2021

The plan is to replace TextDocument#notebook: NotebookDocument | undefined with a util-function because (a) the reference would be text document to notebook cell (not notebook) and (b) it is a bit of a weird reference cycle because the cell is composed of the text document and other properties and these "child properties" usually don't point to the container.

@jrieken
Copy link
Member Author

jrieken commented Jun 21, 2021

Idea/sketch:

namespace notebooks {
  /**
   * @returns A notebook cell which contents are represented by the given text document
   */
  export function getNotebookCell(textDocument: TextDocument): NotebookCell | undefined;
}

@jrieken jrieken modified the milestones: June 2021, July 2021 Jun 23, 2021
@jrieken jrieken removed this from the July 2021 milestone Jul 7, 2021
@rebornix rebornix removed the notebook label Oct 21, 2021
sourcegraph-bot pushed a commit to sgtest/megarepo that referenced this issue Dec 23, 2021
Commit: 5d3b6fb70eb39badfe4bb32ee9331434b4aec507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-finalization feature-request Request for new features or functionality notebook-api
Projects
None yet
Development

No branches or pull requests

5 participants