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

Implement file system watcher plugin API #3576

Merged
merged 1 commit into from
Nov 22, 2018
Merged

Implement file system watcher plugin API #3576

merged 1 commit into from
Nov 22, 2018

Conversation

mmorhun
Copy link
Contributor

@mmorhun mmorhun commented Nov 21, 2018

The implementation is done in following way: a plugin subscribes for file system evens and specifies filters if any. In plugin thread there is a proxy which sends request to Theia side to register subscriber (and gets back an subscriber id). On Theia side there is manager which stores subscriber's requirements. When an event happens it will be checked by the manager and if it matches - only then - will sent it back to plugin side with subscriber id, so the proxy redirects it to needed client by id without any processing. This approach helps in reducing traffic between main and plugin side.

Resolves #3163

}

dispose(): void {
if (this.subscriberData.unsubscribe) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you, but it would be nice dispose onDidCreateEmitter, onDidUpdateEmitter, onDidDeleteEmitter too. Example: https://github.com/theia-ide/theia/blob/master/packages/core/src/browser/connection-status-service.ts#L100
Also you could create dispose collection protected readonly toDispose = new DisposableCollection(); and push all Emitters here, and then toDispose.dispose() utilize each of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, will fix.

@@ -28,3 +30,13 @@ export namespace Schemes {
export const File = 'file';
export const Untitled = 'untitled';
}

export function theiaUritoUriCompponents(uri: URI): UriComponents {
Copy link
Contributor

Choose a reason for hiding this comment

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

hello, FYI typo on the function name (two p at Components)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you, I'll rename the function.

type: FileChangeEventType
}

export type FileChangeEventType = 'created' | 'updated' | 'deleted';
Copy link
Contributor

Choose a reason for hiding this comment

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

should created/updated/deleted be constants as well (to use it in uri-components.ts for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, they might be, but it is widely spread practice to have enum types of strings. They are safe (compiler cares of it) and even IDE's tools are dealing well with them (so I still have autocompletion and so on).

import { FileWatcherSubscriberOptions, FileChangeEventType } from '../api/model';
import URI from 'vscode-uri';

export class InPluginFileSystemWatcherProxy {
Copy link
Contributor

Choose a reason for hiding this comment

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

some documentation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense, will add.

perSubscriberEventEmitter.fire({ uri, type });
} else {
// shouldn't happen
// if it happans then a message was lost, unsubscribe to make state consistent
Copy link
Contributor

Choose a reason for hiding this comment

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

-happans+happens

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx


constructor(
subscriberData: SubscriberData,
ignoreCreateEvents: boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just use private keyword there (so no need to add it few lines before) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not like to mix fields declaration types.
But ok, I will change it, here is some special case: the fields is assigned in constructor and never changes after, so it is kind of constants just to complete the specification.

const fileWatcherSubscriberOptions: FileWatcherSubscriberOptions = { globPattern, ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents };
// ids are generated by server side to be able handle several subscribers.
this.proxy.$registerFileSystemWatcher(fileWatcherSubscriberOptions).then((id: string) => {
// this is safe, because actual subscription happans on server side and response is
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// this is safe, because actual subscription happans on server side and response is
// this is safe, because actual subscription happens on server side and response is

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
@mmorhun mmorhun merged commit 18d3fe1 into master Nov 22, 2018
@mmorhun mmorhun deleted the theia-3163 branch November 22, 2018 14:59
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.

5 participants