forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathoutputChannel.ts
More file actions
55 lines (48 loc) · 1.98 KB
/
outputChannel.ts
File metadata and controls
55 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { IApplicationShell, ICommandManager } from '../../common/application/types';
import '../../common/extensions';
import { IDisposable, ILogOutputChannel } from '../../common/types';
import { OutputChannelNames } from '../../common/utils/localize';
import { ILanguageServerOutputChannel } from '../types';
@injectable()
export class LanguageServerOutputChannel implements ILanguageServerOutputChannel {
public output: ILogOutputChannel | undefined;
private disposables: IDisposable[] = [];
private registered = false;
constructor(
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
@inject(ICommandManager) private readonly commandManager: ICommandManager,
) {}
public dispose(): void {
this.disposables.forEach((d) => d && d.dispose());
this.disposables = [];
}
public get channel(): ILogOutputChannel {
if (!this.output) {
this.output = this.appShell.createOutputChannel(OutputChannelNames.JediLanguageServer);
this.disposables.push(this.output);
this.registerCommand().ignoreErrors();
}
return this.output;
}
private async registerCommand() {
if (this.registered) {
return;
}
this.registered = true;
// This controls the visibility of the command used to display the LS Output panel.
// We don't want to display it when Jedi is used instead of LS.
await this.commandManager.executeCommand('setContext', 'python.hasLanguageServerOutputChannel', true);
this.disposables.push(
this.commandManager.registerCommand('python.viewLanguageServerOutput', () => this.output?.show(true)),
);
this.disposables.push({
dispose: () => {
this.registered = false;
},
});
}
}