-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat(trace-viewer): refactor trace viewer #509
Conversation
c1e9fd8
to
456906e
Compare
456906e
to
f01b9d4
Compare
23a6af8
to
76373da
Compare
There was a problem hiding this 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!
abca7bb
to
308cba7
Compare
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[] = []; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 toEmbeddedTraceViewer
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
308cba7
to
b4cbe7b
Compare
1579b33
to
d97f60e
Compare
…tModel Also, spawnTraceViewer as is doesn't need to be disposed, all its resources are properly released on close, and TestModel.reset ensures that.
d97f60e
to
935ac17
Compare
This reverts commit 98c19d6.
Refactoring before introducing embedded mode.