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

[preferences] use the editor manager instead of reimplementing it #2615

Merged
merged 2 commits into from
Aug 20, 2018

Conversation

akosyakov
Copy link
Member

The internal contract between the editor manager and the editor was changed, but the preference widget relying on it was not.

This PR refactors the preferences widget to rely on the editor manger instead of its implementation details.

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
@akosyakov akosyakov changed the title WIP [preferences] use the editor manager instead of reimplementing it [preferences] use the editor manager instead of reimplementing it Aug 20, 2018
@akosyakov
Copy link
Member Author

@elaihau I've refactored the workspace service since it was bogusly mutating _roots instead of atomically updating it. It caused issues like #2546.

@marechal-p it should fix gitpod-io/gitpod#21

Copy link
Contributor

@svenefftinge svenefftinge left a comment

Choose a reason for hiding this comment

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

LGTM

this.rootWatchers[validRoot.uri] = watcher;
protected readonly watchers = new Map<string, Disposable>();

protected async watchRoots(): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this function stop all the watchers, and start a subset of them over again, when users add/remove roots? do we want to only deal with the diff ?

Copy link
Member Author

Choose a reason for hiding this comment

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

does this function stop all the watchers, and start a subset of them over again, when users add/remove roots?

it stops a watcher only if a root is removed

return { stat, roots: this._workspaceFolder && roots.length === 0 ? [this._workspaceFolder.uri] : roots };
// FIXME use jsonc + ajx to parse & validate content
const roots: string[] = JSON.parse(content).roots || [];
return { stat, roots };
Copy link
Contributor

Choose a reason for hiding this comment

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

in the case that roots == [ ], all watchers are disposed - at this point if the user adds a new root to the workspace, s/he wouldn't see that new root, because the workspace config file is not being watched anymore.

but it is ok - my PR in review makes the config file independent from the root folders, so it is not going to be an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh, you are right !

@akosyakov akosyakov merged commit eef9ede into master Aug 20, 2018
@akosyakov akosyakov deleted the ak/preferences_editor branch August 20, 2018 11:36
this._roots = await this.computeRoots();
this.deferredRoots.resolve(this._roots); // in order to resolve first
this.deferredRoots = new Deferred<FileStat[]>();
this.deferredRoots.resolve(this._roots);
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please explain why we need to resolve it twice ? Thank you !

Copy link
Member Author

Choose a reason for hiding this comment

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

The first resolve is only needed to resolve a promise created in the constructor, otherwise, it won't be ever resolved. I don't like it much either.

I don't see it much in other APIs. Usually, I use a promise if a single action should be awaited, but if there is a value which changes over the time, like _roots then synchronous access + an event is usually enough. We could analyze clients to see whether we can get rid of a promise.

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.

None yet

3 participants