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

[plugin] start document listening when all clients are ready #6321

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions packages/plugin-ext/src/main/browser/editors-and-documents-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export class EditorsAndDocumentsMain implements Disposable {
this.toDispose.push(this.onDocumentRemoveEmitter);
}

listen(): void {
this.stateComputer.listen();
}

dispose(): void {
this.toDispose.dispose();
}
Expand Down Expand Up @@ -177,17 +181,22 @@ class EditorAndDocumentStateComputer implements Disposable {
private callback: (delta: EditorAndDocumentStateDelta) => void,
private readonly editorService: TextEditorService,
private readonly modelService: EditorModelService
) {
this.toDispose.push(editorService.onTextEditorAdd(e => {
) { }

listen(): void {
if (this.toDispose.disposed) {
return;
}
this.toDispose.push(this.editorService.onTextEditorAdd(e => {
this.onTextEditorAdd(e);
}));
this.toDispose.push(editorService.onTextEditorRemove(e => {
this.toDispose.push(this.editorService.onTextEditorRemove(e => {
this.onTextEditorRemove(e);
}));
this.toDispose.push(modelService.onModelAdded(this.onModelAdded, this));
this.toDispose.push(modelService.onModelRemoved(() => this.update()));
this.toDispose.push(this.modelService.onModelAdded(this.onModelAdded, this));
this.toDispose.push(this.modelService.onModelRemoved(() => this.update()));

editorService.listTextEditors().forEach(e => this.onTextEditorAdd(e));
this.editorService.listTextEditors().forEach(e => this.onTextEditorAdd(e));
this.update();
}

Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/main/browser/main-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container
rpc.set(PLUGIN_RPC_CONTEXT.PREFERENCE_REGISTRY_MAIN, preferenceRegistryMain);

const editorsAndDocuments = new EditorsAndDocumentsMain(rpc, container);

const modelService = container.get(EditorModelService);
const editorManager = container.get(EditorManager);
const openerService = container.get<OpenerService>(OpenerService);
Expand All @@ -80,6 +81,9 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container
const editorsMain = new TextEditorsMainImpl(editorsAndDocuments, rpc, bulkEditService, monacoEditorService);
rpc.set(PLUGIN_RPC_CONTEXT.TEXT_EDITORS_MAIN, editorsMain);

// start listening only after all clients are subscribed to events
editorsAndDocuments.listen();

const statusBarMessageRegistryMain = new StatusBarMessageRegistryMainImpl(container);
rpc.set(PLUGIN_RPC_CONTEXT.STATUS_BAR_MESSAGE_REGISTRY_MAIN, statusBarMessageRegistryMain);

Expand Down