Skip to content

Commit cb24571

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Customized channel to cancel the queue on dispose.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 2f8e28b commit cb24571

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ import { ExamplesServicePath, ExamplesService } from '../common/protocol/example
122122
import { BuiltInExamples, LibraryExamples } from './contributions/examples';
123123
import { LibraryServiceProvider } from './library/library-service-provider';
124124
import { IncludeLibrary } from './contributions/include-library';
125+
import { OutputChannelManager as TheiaOutputChannelManager } from '@theia/output/lib/common/output-channel';
126+
import { OutputChannelManager } from './theia/output/output-channel';
125127

126128
const ElementQueries = require('css-element-queries/src/ElementQueries');
127129

@@ -310,6 +312,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
310312
});
311313
bind(OutputWidget).toSelf().inSingletonScope();
312314
rebind(TheiaOutputWidget).toService(OutputWidget);
315+
bind(OutputChannelManager).toSelf().inSingletonScope();
316+
rebind(TheiaOutputChannelManager).toService(OutputChannelManager);
313317

314318
// Show a disconnected status bar, when the daemon is not available
315319
bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as PQueue from 'p-queue';
2+
import { injectable } from 'inversify';
3+
import { Deferred } from '@theia/core/lib/common/promise-util';
4+
import { OutputUri } from '@theia/output/lib/common/output-uri';
5+
import { IReference } from '@theia/monaco/lib/browser/monaco-text-model-service';
6+
import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
7+
import { OutputChannelManager as TheiaOutputChannelManager, OutputChannel as TheiaOutputChannel } from '@theia/output/lib/common/output-channel';
8+
9+
@injectable()
10+
export class OutputChannelManager extends TheiaOutputChannelManager {
11+
12+
getChannel(name: string): TheiaOutputChannel {
13+
const existing = this.channels.get(name);
14+
if (existing) {
15+
return existing;
16+
}
17+
18+
// We have to register the resource first, because `textModelService#createModelReference` will require it
19+
// right after creating the monaco.editor.ITextModel.
20+
// All `append` and `appendLine` will be deferred until the underlying text-model instantiation.
21+
let resource = this.resources.get(name);
22+
if (!resource) {
23+
const uri = OutputUri.create(name);
24+
const editorModelRef = new Deferred<IReference<MonacoEditorModel>>();
25+
resource = this.createResource({ uri, editorModelRef });
26+
this.resources.set(name, resource);
27+
this.textModelService.createModelReference(uri).then(ref => editorModelRef.resolve(ref));
28+
}
29+
30+
const channel = new OutputChannel(resource, this.preferences);
31+
this.channels.set(name, channel);
32+
this.toDisposeOnChannelDeletion.set(name, this.registerListeners(channel));
33+
this.channelAddedEmitter.fire(channel);
34+
if (!this.selectedChannel) {
35+
this.selectedChannel = channel;
36+
}
37+
return channel;
38+
}
39+
40+
}
41+
42+
export class OutputChannel extends TheiaOutputChannel {
43+
44+
dispose(): void {
45+
super.dispose();
46+
if ((this as any).disposed) {
47+
const textModifyQueue: PQueue = (this as any).textModifyQueue;
48+
textModifyQueue.pause();
49+
textModifyQueue.clear();
50+
}
51+
}
52+
53+
}

0 commit comments

Comments
 (0)