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

feat(trace-viewer): refactor trace viewer #509

Merged
merged 7 commits into from
Aug 6, 2024

Conversation

ruifigueira
Copy link
Contributor

Refactoring before introducing embedded mode.

src/extension.ts Outdated Show resolved Hide resolved
src/testModel.ts Outdated Show resolved Hide resolved
src/testModel.ts Outdated Show resolved Hide resolved
@ruifigueira ruifigueira force-pushed the feat/refactor-trace-viewer branch from 23a6af8 to 76373da Compare July 26, 2024 11:27
Copy link
Member

@pavelfeldman pavelfeldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the test coverage!

src/extension.ts Outdated Show resolved Hide resolved
src/testModel.ts Outdated Show resolved Hide resolved
src/traceViewer.ts Outdated Show resolved Hide resolved
tests/spawn-trace-viewer.spec.ts Outdated Show resolved Hide resolved
tests/spawn-trace-viewer.spec.ts Show resolved Hide resolved
@ruifigueira ruifigueira force-pushed the feat/refactor-trace-viewer branch 2 times, most recently from abca7bb to 308cba7 Compare July 29, 2024 19:37
src/testModel.ts Outdated
@@ -615,12 +640,22 @@ export class TestModelCollection extends DisposableBase {
private _didUpdate: vscodeTypes.EventEmitter<void>;
readonly onUpdated: vscodeTypes.Event<void>;
private _context: vscodeTypes.ExtensionContext;
private _modelsDisposables: vscodeTypes.Disposable[] = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still quite confusing, sorry. We should be able to handle this use case without additional complexity. All the objects we operate have nested lifetimes:

  • TestModelCollection outlives models that it contains
  • TestModels contain respective trace viewers
  • There is a way to clear the collection that destroys all the models due to containment
  • There is a way to reset the model while maintaining it alive.

I'm not sure why we can't keep things straightforward, but maybe it is the view aspect that makes us keep just one trace viewer open that stands in the way?

Copy link
Contributor Author

@ruifigueira ruifigueira Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current TestModelCollection in main branch is not included in the extensions disposables, and I needed to add it to ensure it was properly released in case the extension is deactivated. But TestModelCollection dispose in main branch doesn't reset its models, only disposes the model.onUpdate event handlers (it uses the DisposableBase implementation).

So, to make this step clear, I creaed another PR just trying to fix that: #511.

But then there's the difficulty of adding another disposables that should not be disposed on reset / clear , like event handlers. If I just add them to this._disposables, those handlers will be disposed on TestModelCollection.clear and therefore won't receive the correponding events afterwards.

An option for TestModelCollection is to add event handler disposables to ExtensionContext.subscption, since its lifetime is the same as the extension, but that doesn't seem right to me, because it should be TestModelCollection's responsability to actually dispose all its internal state.

Copy link
Contributor Author

@ruifigueira ruifigueira Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes it's better to take one step back: if we move trace viewer instances back into the Extension class, we can avoid registering event handlers in TestModelCollection and TestModel, so basically I'm rolling back changes in those classes.

So:

  • TraceViewer implementations become shallow objects once again, with the same lifetime as the extension (right now, it's only SpawnTraceViewer, but the same logic will be applied to EmbeddedTraceViewer in the next phase)
  • They keep a reference to TestModelCollection so that they can get the current configuration / server URL
  • All event handling that can impact trace viewers (models.onUpdated / showTrace.onChange, embeddedTraceViewer.onChange) are handled in extensions

Let me know if this approach is better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is hard for me to give a good advice without doing the actual work. My naive thought process is as follows:

  • User selects test item in the tree
  • Extension (controller) handles this change and makes a decision that trace for the test result should be shown
  • Extension creates (or reuses) trace viewer for this test via the test model.
  • Extension takes owership of the trace viewer and listens for the model to be disabled and/or removed, destroys dangling trace viewer when needed.
  • Extension opens trace in the created trace viewer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok my latest commit no longer makes sense with the changes you introduced. I'll drop it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I changed anything fundamentally, but you would know better what applies and what does not. Please let me know which patch I should be reviewing!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can review the current one, I already rolled back the "step back" solution.

@ruifigueira ruifigueira force-pushed the feat/refactor-trace-viewer branch from 308cba7 to b4cbe7b Compare July 31, 2024 17:33
@ruifigueira ruifigueira force-pushed the feat/refactor-trace-viewer branch from 1579b33 to d97f60e Compare August 1, 2024 23:32
…tModel

Also, spawnTraceViewer as is doesn't need to be disposed, all its resources are properly released on close, and TestModel.reset ensures that.
@ruifigueira ruifigueira force-pushed the feat/refactor-trace-viewer branch from d97f60e to 935ac17 Compare August 1, 2024 23:36
@pavelfeldman pavelfeldman merged commit 98c19d6 into microsoft:main Aug 6, 2024
6 checks passed
Skn0tt added a commit to Skn0tt/playwright-vscode that referenced this pull request Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants