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

New notebook from the command line issues #127757

Closed
wants to merge 3 commits into from
Closed

New notebook from the command line issues #127757

wants to merge 3 commits into from

Conversation

bpasero
Copy link
Member

@bpasero bpasero commented Jul 1, 2021

This is for #125028 and not the full fix yet but I want to get some feedback if the direction makes sense.

The challenge is that we seem to have some logic how to create a untitled notebook URI in mainThreadNotebookDocuments.ts but we also need it for the untitled editor factory where we have to create a notebook editor:

const notebookUntitledEditorFactory: UntitledEditorInputFactoryFunction = ({ resource, options }) => {

This method is responsible for converting a simple JSON object ("untyped editor input") to a real untitled notebook editor input. With this PR, the behaviour of both are aligned with regards to:

  • we ensure an untitled notebook doesn't exist yet by incrementing a counter
  • we add the proper suffix via possibleFileEnding usage (unless a resource is associated)
  • we define a query param (query: notebookProviderInfo.id)

One missing aspect is how to forward the information down to where the working copy is being created that we have an untitled resource with associated file path. Basically this code:

this._workingCopy = await this._workingCopyManager.resolve({ untitledResource: this.resource });

Needs to change in a way that it continues to call resolve({ untitledResource: this.resource }) for normal untitled editors and resolve({ associatedResource: this.resource }) for untitled with associated path. This distinction makes it possible to get the right behaviour which is:

  • untitled with associated path do not ask for a file path when saving
  • they are dirty from the beginning

One idea I had was to also encode this info into the URI as query param, but I am not sure where this resource is travelling and if that is a safe thing to do.

Thoughts?

@bpasero bpasero requested a review from jrieken July 1, 2021 10:18
@bpasero bpasero self-assigned this Jul 1, 2021
@jrieken
Copy link
Member

jrieken commented Jul 1, 2021

Thoughts?

Idk - It's the first time I hear about UntitledEditorInputFactoryFunction. Is the contract that it must be created with the final untitled URI or can the URI change later? In a way, I am wishing for generating the untitled-uri right before creating the model, like here. And only have the logic once, e.g not in mainThreadNotebook and the factory function.

I think this needs further clarification. Let's reserve some 1-1 time tomorrow or next week

@bpasero
Copy link
Member Author

bpasero commented Jul 1, 2021

@jrieken the factory was added only recently (last week?) to distinguish normal editors from untitled editors (and diff editors have their own factory too), but it doesn't really matter and is just there for convenience.

The underlying contract is that you get a lightweight "untyped" JSON editor input and have to return a heavy "typed" editor input that is then opened in an editor. There are only a few untyped editors:

  • the 99% case: just a resource ({ resource: ...})
  • the untitled case: most often {}, in some cases a resource is provided (only when e.g. run from command line with a path)
  • the diff editor case: looks mostly like this: { originalInput: URI, modifiedInput: URI }

The URI of the editor input does not have to be known up front, in fact it is even optional for editor inputs so notebooks are free to do whatever they want, even if that means to resolve the URI only in the resolve method of the input.

1on1 sounds good, we can do next week since this probably is not making it for June anyway.

@bpasero bpasero added this to the July 2021 milestone Jul 1, 2021
@bpasero
Copy link
Member Author

bpasero commented Jul 1, 2021

Btw I like the idea of having this logic somewhere here:

async resolve(resource: URI, viewType?: string): Promise<IReference<IResolvedNotebookEditorModel>> {

It would however require that for the aquire here:

const reference = this._data.acquire(resource.toString(), viewType);

We can pass on additional context to pipe through the untitled with associated file path case. Could be just a boolean too.

@bpasero
Copy link
Member Author

bpasero commented Aug 6, 2021

Continues in #130236, I can walk you through when you are back.

@bpasero bpasero closed this Aug 6, 2021
@bpasero bpasero deleted the ben/125028 branch August 6, 2021 06:51
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants