Skip to content

Commit

Permalink
[plugin] fix #6319: start document listening when all clients are ready
Browse files Browse the repository at this point in the history
Otherwise events for already opened document can be missed.

Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Oct 3, 2019
1 parent 629240b commit 3b4690d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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

0 comments on commit 3b4690d

Please sign in to comment.