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

untitled - use ref counted lifecycle #194371

Merged
merged 9 commits into from Nov 6, 2023
Merged

untitled - use ref counted lifecycle #194371

merged 9 commits into from Nov 6, 2023

Conversation

bpasero
Copy link
Member

@bpasero bpasero commented Sep 28, 2023

Fixes #192356

This starts to use references for untitled text model lifecycle. Upon revert, the model gets reset to be empty but not disposed. Those that create the reference dispose it by listening to the revert.

@bpasero bpasero self-assigned this Sep 28, 2023
@bpasero bpasero added this to the October 2023 milestone Sep 28, 2023
@bpasero bpasero marked this pull request as ready for review September 29, 2023 07:53
@bpasero
Copy link
Member Author

bpasero commented Sep 29, 2023

@jrieken might need your help with the failing test [Bug] Failed to create new test file when in an untitled file #1261.

@jrieken
Copy link
Member

jrieken commented Oct 17, 2023

@bpasero I debugged into this and what is happens is the following

  • the workspace edit for a new file is dispatched
  • this makes its way into BulkTextEdits
  • per file/uri we create an EditTask which holds a reference to the respected model
  • when the edit task is done the model reference is released/disposed
  • since nobody else is holding a reference the model is disposed again
  • the integration test now fails because the disposed model doesn't have any contents (anymore)
Screenshot 2023-10-17 at 15 03 51

It feels that someone, e.g the workbench, should also reference the newly created model so that a tab is opened for it?

@bpasero bpasero removed this from the October 2023 milestone Oct 17, 2023
@bpasero
Copy link
Member Author

bpasero commented Oct 17, 2023

Yeah, good finding. We do track dirty untitled models and force open them, but with a delay of 800ms to reduce the spam this can generate when the editor is then actually saved shortly after:

this._register(this.textFileService.untitled.onDidChangeDirty(model => this.ensureDirtyFilesAreOpenedWorker.work(model.resource)));

Even when I change that to open instantly, the test fails and that is probably due to the async nature of the editor opening.

Then I remember how this issue is addressed with file models, which are model reference backed. We prevent disposal of the underlying model until the dirty state is changed. Otherwise we would see a similar issue with text files.

I pushed a change to adopt this concept also for untitled files and the test seems to pass now.

@bpasero bpasero added this to the November 2023 milestone Oct 18, 2023
@bpasero bpasero requested review from jrieken and removed request for jrieken October 30, 2023 06:03
@bpasero bpasero merged commit 6786b8f into main Nov 6, 2023
6 checks passed
@bpasero bpasero deleted the ben/untitled-wip branch November 6, 2023 11:58
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
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.

Inline chat widget not disposed when closing untitled editor with pending edits
2 participants