forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathapplicationShell.ts
193 lines (184 loc) · 7.18 KB
/
applicationShell.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { injectable } from 'inversify';
import {
CancellationToken,
CancellationTokenSource,
Disposable,
DocumentSelector,
env,
Event,
EventEmitter,
InputBox,
InputBoxOptions,
languages,
LanguageStatusItem,
LogOutputChannel,
MessageItem,
MessageOptions,
OpenDialogOptions,
Progress,
ProgressOptions,
QuickPick,
QuickPickItem,
QuickPickOptions,
SaveDialogOptions,
StatusBarAlignment,
StatusBarItem,
TextDocument,
TextEditor,
TreeView,
TreeViewOptions,
Uri,
ViewColumn,
window,
WindowState,
WorkspaceFolder,
WorkspaceFolderPickOptions,
} from 'vscode';
import { traceError } from '../../logging';
import { IApplicationShell, TerminalDataWriteEvent, TerminalExecutedCommand } from './types';
@injectable()
export class ApplicationShell implements IApplicationShell {
public get onDidChangeWindowState(): Event<WindowState> {
return window.onDidChangeWindowState;
}
public showInformationMessage(message: string, ...items: string[]): Thenable<string>;
public showInformationMessage(message: string, options: MessageOptions, ...items: string[]): Thenable<string>;
public showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>;
public showInformationMessage<T extends MessageItem>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T>;
public showInformationMessage(message: string, options?: any, ...items: any[]): Thenable<any> {
return window.showInformationMessage(message, options, ...items);
}
public showWarningMessage(message: string, ...items: string[]): Thenable<string>;
public showWarningMessage(message: string, options: MessageOptions, ...items: string[]): Thenable<string>;
public showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>;
public showWarningMessage<T extends MessageItem>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T>;
public showWarningMessage(message: any, options?: any, ...items: any[]) {
return window.showWarningMessage(message, options, ...items);
}
public showErrorMessage(message: string, ...items: string[]): Thenable<string>;
public showErrorMessage(message: string, options: MessageOptions, ...items: string[]): Thenable<string>;
public showErrorMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>;
public showErrorMessage<T extends MessageItem>(
message: string,
options: MessageOptions,
...items: T[]
): Thenable<T>;
public showErrorMessage(message: any, options?: any, ...items: any[]) {
return window.showErrorMessage(message, options, ...items);
}
public showQuickPick(
items: string[] | Thenable<string[]>,
options?: QuickPickOptions,
token?: CancellationToken,
): Thenable<string>;
public showQuickPick<T extends QuickPickItem>(
items: T[] | Thenable<T[]>,
options?: QuickPickOptions,
token?: CancellationToken,
): Thenable<T>;
public showQuickPick(items: any, options?: any, token?: any): Thenable<any> {
return window.showQuickPick(items, options, token);
}
public showOpenDialog(options: OpenDialogOptions): Thenable<Uri[] | undefined> {
return window.showOpenDialog(options);
}
public showSaveDialog(options: SaveDialogOptions): Thenable<Uri | undefined> {
return window.showSaveDialog(options);
}
public showInputBox(options?: InputBoxOptions, token?: CancellationToken): Thenable<string | undefined> {
return window.showInputBox(options, token);
}
public showTextDocument(
document: TextDocument,
column?: ViewColumn,
preserveFocus?: boolean,
): Thenable<TextEditor> {
return window.showTextDocument(document, column, preserveFocus);
}
public openUrl(url: string): void {
env.openExternal(Uri.parse(url));
}
public setStatusBarMessage(text: string, hideAfterTimeout: number): Disposable;
public setStatusBarMessage(text: string, hideWhenDone: Thenable<any>): Disposable;
public setStatusBarMessage(text: string): Disposable;
public setStatusBarMessage(text: string, arg?: any): Disposable {
return window.setStatusBarMessage(text, arg);
}
public createStatusBarItem(
alignment?: StatusBarAlignment,
priority?: number,
id?: string | undefined,
): StatusBarItem {
return id
? window.createStatusBarItem(id, alignment, priority)
: window.createStatusBarItem(alignment, priority);
}
public showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions): Thenable<WorkspaceFolder | undefined> {
return window.showWorkspaceFolderPick(options);
}
public withProgress<R>(
options: ProgressOptions,
task: (progress: Progress<{ message?: string; increment?: number }>, token: CancellationToken) => Thenable<R>,
): Thenable<R> {
return window.withProgress<R>(options, task);
}
public withProgressCustomIcon<R>(
icon: string,
task: (progress: Progress<{ message?: string; increment?: number }>, token: CancellationToken) => Thenable<R>,
): Thenable<R> {
const token = new CancellationTokenSource().token;
const statusBarProgress = this.createStatusBarItem(StatusBarAlignment.Left);
const progress = {
report: (value: { message?: string; increment?: number }) => {
statusBarProgress.text = `${icon} ${value.message}`;
},
};
statusBarProgress.show();
return task(progress, token).then((result) => {
statusBarProgress.dispose();
return result;
});
}
public createQuickPick<T extends QuickPickItem>(): QuickPick<T> {
return window.createQuickPick<T>();
}
public createInputBox(): InputBox {
return window.createInputBox();
}
public createTreeView<T>(viewId: string, options: TreeViewOptions<T>): TreeView<T> {
return window.createTreeView<T>(viewId, options);
}
public createOutputChannel(name: string): LogOutputChannel {
return window.createOutputChannel(name, { log: true });
}
public createLanguageStatusItem(id: string, selector: DocumentSelector): LanguageStatusItem {
return languages.createLanguageStatusItem(id, selector);
}
public get onDidWriteTerminalData(): Event<TerminalDataWriteEvent> {
try {
return window.onDidWriteTerminalData;
} catch (ex) {
traceError('Failed to get proposed API onDidWriteTerminalData', ex);
return new EventEmitter<TerminalDataWriteEvent>().event;
}
}
public get onDidExecuteTerminalCommand(): Event<TerminalExecutedCommand> | undefined {
try {
return window.onDidExecuteTerminalCommand;
} catch (ex) {
traceError('Failed to get proposed API TerminalExecutedCommand', ex);
return undefined;
}
}
}