@theia/terminal 1.34.2 → 1.34.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +641 -641
- package/README.md +30 -30
- package/lib/browser/base/terminal-service.d.ts +34 -34
- package/lib/browser/base/terminal-service.js +7 -7
- package/lib/browser/base/terminal-widget.d.ts +184 -184
- package/lib/browser/base/terminal-widget.js +34 -34
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +28 -28
- package/lib/browser/search/terminal-search-container.d.ts +3 -3
- package/lib/browser/search/terminal-search-container.js +28 -28
- package/lib/browser/search/terminal-search-widget.d.ts +30 -30
- package/lib/browser/search/terminal-search-widget.js +147 -147
- package/lib/browser/shell-terminal-profile.d.ts +19 -19
- package/lib/browser/shell-terminal-profile.js +39 -39
- package/lib/browser/terminal-contribution.d.ts +3 -3
- package/lib/browser/terminal-contribution.js +20 -20
- package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
- package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
- package/lib/browser/terminal-file-link-provider.d.ts +24 -24
- package/lib/browser/terminal-file-link-provider.js +200 -200
- package/lib/browser/terminal-frontend-contribution.d.ts +112 -112
- package/lib/browser/terminal-frontend-contribution.js +994 -994
- package/lib/browser/terminal-frontend-module.d.ts +5 -5
- package/lib/browser/terminal-frontend-module.js +115 -115
- package/lib/browser/terminal-keybinding-contexts.d.ts +15 -15
- package/lib/browser/terminal-keybinding-contexts.js +71 -71
- package/lib/browser/terminal-link-helpers.d.ts +27 -27
- package/lib/browser/terminal-link-helpers.js +155 -155
- package/lib/browser/terminal-link-provider.d.ts +51 -51
- package/lib/browser/terminal-link-provider.js +197 -197
- package/lib/browser/terminal-preferences.d.ts +61 -61
- package/lib/browser/terminal-preferences.js +329 -329
- package/lib/browser/terminal-profile-service.d.ts +55 -55
- package/lib/browser/terminal-profile-service.js +149 -149
- package/lib/browser/terminal-quick-open-service.d.ts +36 -36
- package/lib/browser/terminal-quick-open-service.js +137 -137
- package/lib/browser/terminal-theme-service.d.ts +21 -21
- package/lib/browser/terminal-theme-service.js +218 -218
- package/lib/browser/terminal-url-link-provider.d.ts +11 -11
- package/lib/browser/terminal-url-link-provider.js +76 -76
- package/lib/browser/terminal-widget-impl.d.ts +173 -173
- package/lib/browser/terminal-widget-impl.js +769 -769
- package/lib/common/base-terminal-protocol.d.ts +100 -100
- package/lib/common/base-terminal-protocol.js +88 -88
- package/lib/common/shell-terminal-protocol.d.ts +29 -29
- package/lib/common/shell-terminal-protocol.js +22 -22
- package/lib/common/terminal-common-module.d.ts +7 -7
- package/lib/common/terminal-common-module.js +31 -31
- package/lib/common/terminal-protocol.d.ts +12 -12
- package/lib/common/terminal-protocol.js +21 -21
- package/lib/common/terminal-watcher.d.ts +13 -13
- package/lib/common/terminal-watcher.js +70 -70
- package/lib/node/base-terminal-server.d.ts +36 -36
- package/lib/node/base-terminal-server.js +252 -252
- package/lib/node/buffering-stream.d.ts +39 -39
- package/lib/node/buffering-stream.js +75 -75
- package/lib/node/buffering-stream.spec.d.ts +1 -1
- package/lib/node/buffering-stream.spec.js +43 -43
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.js +28 -28
- package/lib/node/shell-process.d.ts +26 -26
- package/lib/node/shell-process.js +106 -106
- package/lib/node/shell-terminal-server.d.ts +14 -14
- package/lib/node/shell-terminal-server.js +114 -114
- package/lib/node/shell-terminal-server.spec.d.ts +1 -1
- package/lib/node/shell-terminal-server.spec.js +35 -35
- package/lib/node/terminal-backend-contribution.d.ts +9 -9
- package/lib/node/terminal-backend-contribution.js +75 -75
- package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
- package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
- package/lib/node/terminal-backend-module.d.ts +11 -11
- package/lib/node/terminal-backend-module.js +69 -69
- package/lib/node/terminal-server.d.ts +9 -9
- package/lib/node/terminal-server.js +64 -64
- package/lib/node/terminal-server.spec.d.ts +1 -1
- package/lib/node/terminal-server.spec.js +41 -41
- package/lib/node/test/terminal-test-container.d.ts +2 -2
- package/lib/node/test/terminal-test-container.js +40 -40
- package/lib/package.spec.js +25 -25
- package/package.json +9 -9
- package/src/browser/base/terminal-service.ts +60 -60
- package/src/browser/base/terminal-widget.ts +244 -244
- package/src/browser/index.ts +17 -17
- package/src/browser/search/terminal-search-container.ts +28 -28
- package/src/browser/search/terminal-search-widget.tsx +161 -161
- package/src/browser/shell-terminal-profile.ts +40 -40
- package/src/browser/style/terminal-search.css +93 -93
- package/src/browser/style/terminal.css +33 -33
- package/src/browser/terminal-contribution.ts +19 -19
- package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
- package/src/browser/terminal-file-link-provider.ts +200 -200
- package/src/browser/terminal-frontend-contribution.ts +1048 -1048
- package/src/browser/terminal-frontend-module.ts +139 -139
- package/src/browser/terminal-keybinding-contexts.ts +52 -52
- package/src/browser/terminal-link-helpers.ts +187 -187
- package/src/browser/terminal-link-provider.ts +203 -203
- package/src/browser/terminal-preferences.ts +427 -427
- package/src/browser/terminal-profile-service.ts +170 -170
- package/src/browser/terminal-quick-open-service.ts +132 -132
- package/src/browser/terminal-theme-service.ts +209 -209
- package/src/browser/terminal-url-link-provider.ts +66 -66
- package/src/browser/terminal-widget-impl.ts +827 -827
- package/src/common/base-terminal-protocol.ts +183 -183
- package/src/common/shell-terminal-protocol.ts +50 -50
- package/src/common/terminal-common-module.ts +30 -30
- package/src/common/terminal-protocol.ts +32 -32
- package/src/common/terminal-watcher.ts +69 -69
- package/src/node/base-terminal-server.ts +279 -279
- package/src/node/buffering-stream.spec.ts +46 -46
- package/src/node/buffering-stream.ts +95 -95
- package/src/node/index.ts +17 -17
- package/src/node/shell-process.ts +101 -101
- package/src/node/shell-terminal-server.spec.ts +40 -40
- package/src/node/shell-terminal-server.ts +95 -95
- package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
- package/src/node/terminal-backend-contribution.ts +60 -60
- package/src/node/terminal-backend-module.ts +82 -82
- package/src/node/terminal-server.spec.ts +47 -47
- package/src/node/terminal-server.ts +52 -52
- package/src/node/test/terminal-test-container.ts +39 -39
- package/src/package.spec.ts +28 -28
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
18
|
-
import { ILogger, DisposableCollection, isWindows } from '@theia/core/lib/common';
|
|
19
|
-
import {
|
|
20
|
-
IBaseTerminalServer,
|
|
21
|
-
IBaseTerminalServerOptions,
|
|
22
|
-
IBaseTerminalClient,
|
|
23
|
-
TerminalProcessInfo,
|
|
24
|
-
EnvironmentVariableCollection,
|
|
25
|
-
MergedEnvironmentVariableCollection,
|
|
26
|
-
SerializableEnvironmentVariableCollection,
|
|
27
|
-
EnvironmentVariableMutator,
|
|
28
|
-
ExtensionOwnedEnvironmentVariableMutator,
|
|
29
|
-
EnvironmentVariableMutatorType,
|
|
30
|
-
EnvironmentVariableCollectionWithPersistence,
|
|
31
|
-
SerializableExtensionEnvironmentVariableCollection
|
|
32
|
-
} from '../common/base-terminal-protocol';
|
|
33
|
-
import { TerminalProcess, ProcessManager, TaskTerminalProcess } from '@theia/process/lib/node';
|
|
34
|
-
import { ShellProcess } from './shell-process';
|
|
35
|
-
|
|
36
|
-
@injectable()
|
|
37
|
-
export abstract class BaseTerminalServer implements IBaseTerminalServer {
|
|
38
|
-
protected client: IBaseTerminalClient | undefined = undefined;
|
|
39
|
-
protected terminalToDispose = new Map<number, DisposableCollection>();
|
|
40
|
-
|
|
41
|
-
readonly collections: Map<string, EnvironmentVariableCollectionWithPersistence> = new Map();
|
|
42
|
-
mergedCollection: MergedEnvironmentVariableCollection;
|
|
43
|
-
|
|
44
|
-
constructor(
|
|
45
|
-
@inject(ProcessManager) protected readonly processManager: ProcessManager,
|
|
46
|
-
@inject(ILogger) @named('terminal') protected readonly logger: ILogger
|
|
47
|
-
) {
|
|
48
|
-
processManager.onDelete(id => {
|
|
49
|
-
const toDispose = this.terminalToDispose.get(id);
|
|
50
|
-
if (toDispose !== undefined) {
|
|
51
|
-
toDispose.dispose();
|
|
52
|
-
this.terminalToDispose.delete(id);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
this.mergedCollection = this.resolveMergedCollection();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
abstract create(options: IBaseTerminalServerOptions): Promise<number>;
|
|
59
|
-
|
|
60
|
-
async attach(id: number): Promise<number> {
|
|
61
|
-
const term = this.processManager.get(id);
|
|
62
|
-
|
|
63
|
-
if (term && term instanceof TerminalProcess) {
|
|
64
|
-
return term.id;
|
|
65
|
-
} else {
|
|
66
|
-
this.logger.warn(`Couldn't attach - can't find terminal with id: ${id} `);
|
|
67
|
-
return -1;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async onAttachAttempted(id: number): Promise<void> {
|
|
72
|
-
const terminal = this.processManager.get(id);
|
|
73
|
-
if (terminal instanceof TaskTerminalProcess) {
|
|
74
|
-
terminal.attachmentAttempted = true;
|
|
75
|
-
if (terminal.exited) {
|
|
76
|
-
// Didn't execute `unregisterProcess` on terminal `exit` event to enable attaching task output to terminal,
|
|
77
|
-
// Fixes https://github.com/eclipse-theia/theia/issues/2961
|
|
78
|
-
terminal.unregisterProcess();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async getProcessId(id: number): Promise<number> {
|
|
84
|
-
const terminal = this.processManager.get(id);
|
|
85
|
-
if (!(terminal instanceof TerminalProcess)) {
|
|
86
|
-
throw new Error(`terminal "${id}" does not exist`);
|
|
87
|
-
}
|
|
88
|
-
return terminal.pid;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async getProcessInfo(id: number): Promise<TerminalProcessInfo> {
|
|
92
|
-
const terminal = this.processManager.get(id);
|
|
93
|
-
if (!(terminal instanceof TerminalProcess)) {
|
|
94
|
-
throw new Error(`terminal "${id}" does not exist`);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
executable: terminal.executable,
|
|
98
|
-
arguments: terminal.arguments,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async getCwdURI(id: number): Promise<string> {
|
|
103
|
-
const terminal = this.processManager.get(id);
|
|
104
|
-
if (!(terminal instanceof TerminalProcess)) {
|
|
105
|
-
throw new Error(`terminal "${id}" does not exist`);
|
|
106
|
-
}
|
|
107
|
-
return terminal.getCwdURI();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async close(id: number): Promise<void> {
|
|
111
|
-
const term = this.processManager.get(id);
|
|
112
|
-
|
|
113
|
-
if (term instanceof TerminalProcess) {
|
|
114
|
-
term.kill();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async getDefaultShell(): Promise<string> {
|
|
119
|
-
return ShellProcess.getShellExecutablePath();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
dispose(): void {
|
|
123
|
-
// noop
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async resize(id: number, cols: number, rows: number): Promise<void> {
|
|
127
|
-
const term = this.processManager.get(id);
|
|
128
|
-
if (term && term instanceof TerminalProcess) {
|
|
129
|
-
term.resize(cols, rows);
|
|
130
|
-
} else {
|
|
131
|
-
console.warn("Couldn't resize terminal " + id + ", because it doesn't exist.");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/* Set the client to receive notifications on. */
|
|
136
|
-
setClient(client: IBaseTerminalClient | undefined): void {
|
|
137
|
-
this.client = client;
|
|
138
|
-
if (!this.client) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
this.client.updateTerminalEnvVariables();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
protected postCreate(term: TerminalProcess): void {
|
|
145
|
-
const toDispose = new DisposableCollection();
|
|
146
|
-
|
|
147
|
-
toDispose.push(term.onError(error => {
|
|
148
|
-
this.logger.error(`Terminal pid: ${term.pid} error: ${error}, closing it.`);
|
|
149
|
-
|
|
150
|
-
if (this.client !== undefined) {
|
|
151
|
-
this.client.onTerminalError({
|
|
152
|
-
'terminalId': term.id,
|
|
153
|
-
'error': new Error(`Failed to execute terminal process (${error.code})`),
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}));
|
|
157
|
-
|
|
158
|
-
toDispose.push(term.onExit(event => {
|
|
159
|
-
if (this.client !== undefined) {
|
|
160
|
-
this.client.onTerminalExitChanged({
|
|
161
|
-
'terminalId': term.id,
|
|
162
|
-
'code': event.code,
|
|
163
|
-
'signal': event.signal
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}));
|
|
167
|
-
|
|
168
|
-
this.terminalToDispose.set(term.id, toDispose);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/*---------------------------------------------------------------------------------------------
|
|
172
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
173
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
174
|
-
*--------------------------------------------------------------------------------------------*/
|
|
175
|
-
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
|
|
176
|
-
|
|
177
|
-
setCollection(extensionIdentifier: string, persistent: boolean, collection: SerializableEnvironmentVariableCollection): void {
|
|
178
|
-
const translatedCollection = { persistent, map: new Map<string, EnvironmentVariableMutator>(collection) };
|
|
179
|
-
this.collections.set(extensionIdentifier, translatedCollection);
|
|
180
|
-
this.updateCollections();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
deleteCollection(extensionIdentifier: string): void {
|
|
184
|
-
this.collections.delete(extensionIdentifier);
|
|
185
|
-
this.updateCollections();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private updateCollections(): void {
|
|
189
|
-
this.persistCollections();
|
|
190
|
-
this.mergedCollection = this.resolveMergedCollection();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
protected persistCollections(): void {
|
|
194
|
-
const collectionsJson: SerializableExtensionEnvironmentVariableCollection[] = [];
|
|
195
|
-
this.collections.forEach((collection, extensionIdentifier) => {
|
|
196
|
-
if (collection.persistent) {
|
|
197
|
-
collectionsJson.push({
|
|
198
|
-
extensionIdentifier,
|
|
199
|
-
collection: [...this.collections.get(extensionIdentifier)!.map.entries()]
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
if (this.client) {
|
|
204
|
-
const stringifiedJson = JSON.stringify(collectionsJson);
|
|
205
|
-
this.client.storeTerminalEnvVariables(stringifiedJson);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private resolveMergedCollection(): MergedEnvironmentVariableCollection {
|
|
210
|
-
return new MergedEnvironmentVariableCollectionImpl(this.collections);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/*---------------------------------------------------------------------------------------------
|
|
216
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
217
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
218
|
-
*--------------------------------------------------------------------------------------------*/
|
|
219
|
-
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableCollection.ts
|
|
220
|
-
|
|
221
|
-
export class MergedEnvironmentVariableCollectionImpl implements MergedEnvironmentVariableCollection {
|
|
222
|
-
readonly map: Map<string, ExtensionOwnedEnvironmentVariableMutator[]> = new Map();
|
|
223
|
-
|
|
224
|
-
constructor(collections: Map<string, EnvironmentVariableCollection>) {
|
|
225
|
-
collections.forEach((collection, extensionIdentifier) => {
|
|
226
|
-
const it = collection.map.entries();
|
|
227
|
-
let next = it.next();
|
|
228
|
-
while (!next.done) {
|
|
229
|
-
const variable = next.value[0];
|
|
230
|
-
let entry = this.map.get(variable);
|
|
231
|
-
if (!entry) {
|
|
232
|
-
entry = [];
|
|
233
|
-
this.map.set(variable, entry);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// If the first item in the entry is replace ignore any other entries as they would
|
|
237
|
-
// just get replaced by this one.
|
|
238
|
-
if (entry.length > 0 && entry[0].type === EnvironmentVariableMutatorType.Replace) {
|
|
239
|
-
next = it.next();
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Mutators get applied in the reverse order than they are created
|
|
244
|
-
const mutator = next.value[1];
|
|
245
|
-
entry.unshift({
|
|
246
|
-
extensionIdentifier,
|
|
247
|
-
value: mutator.value,
|
|
248
|
-
type: mutator.type
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
next = it.next();
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
applyToProcessEnvironment(env: { [key: string]: string | null }): void {
|
|
257
|
-
let lowerToActualVariableNames: { [lowerKey: string]: string | undefined } | undefined;
|
|
258
|
-
if (isWindows) {
|
|
259
|
-
lowerToActualVariableNames = {};
|
|
260
|
-
Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e);
|
|
261
|
-
}
|
|
262
|
-
this.map.forEach((mutators, variable) => {
|
|
263
|
-
const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable;
|
|
264
|
-
mutators.forEach(mutator => {
|
|
265
|
-
switch (mutator.type) {
|
|
266
|
-
case EnvironmentVariableMutatorType.Append:
|
|
267
|
-
env[actualVariable] = (env[actualVariable] || '') + mutator.value;
|
|
268
|
-
break;
|
|
269
|
-
case EnvironmentVariableMutatorType.Prepend:
|
|
270
|
-
env[actualVariable] = mutator.value + (env[actualVariable] || '');
|
|
271
|
-
break;
|
|
272
|
-
case EnvironmentVariableMutatorType.Replace:
|
|
273
|
-
env[actualVariable] = mutator.value;
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ILogger, DisposableCollection, isWindows } from '@theia/core/lib/common';
|
|
19
|
+
import {
|
|
20
|
+
IBaseTerminalServer,
|
|
21
|
+
IBaseTerminalServerOptions,
|
|
22
|
+
IBaseTerminalClient,
|
|
23
|
+
TerminalProcessInfo,
|
|
24
|
+
EnvironmentVariableCollection,
|
|
25
|
+
MergedEnvironmentVariableCollection,
|
|
26
|
+
SerializableEnvironmentVariableCollection,
|
|
27
|
+
EnvironmentVariableMutator,
|
|
28
|
+
ExtensionOwnedEnvironmentVariableMutator,
|
|
29
|
+
EnvironmentVariableMutatorType,
|
|
30
|
+
EnvironmentVariableCollectionWithPersistence,
|
|
31
|
+
SerializableExtensionEnvironmentVariableCollection
|
|
32
|
+
} from '../common/base-terminal-protocol';
|
|
33
|
+
import { TerminalProcess, ProcessManager, TaskTerminalProcess } from '@theia/process/lib/node';
|
|
34
|
+
import { ShellProcess } from './shell-process';
|
|
35
|
+
|
|
36
|
+
@injectable()
|
|
37
|
+
export abstract class BaseTerminalServer implements IBaseTerminalServer {
|
|
38
|
+
protected client: IBaseTerminalClient | undefined = undefined;
|
|
39
|
+
protected terminalToDispose = new Map<number, DisposableCollection>();
|
|
40
|
+
|
|
41
|
+
readonly collections: Map<string, EnvironmentVariableCollectionWithPersistence> = new Map();
|
|
42
|
+
mergedCollection: MergedEnvironmentVariableCollection;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
@inject(ProcessManager) protected readonly processManager: ProcessManager,
|
|
46
|
+
@inject(ILogger) @named('terminal') protected readonly logger: ILogger
|
|
47
|
+
) {
|
|
48
|
+
processManager.onDelete(id => {
|
|
49
|
+
const toDispose = this.terminalToDispose.get(id);
|
|
50
|
+
if (toDispose !== undefined) {
|
|
51
|
+
toDispose.dispose();
|
|
52
|
+
this.terminalToDispose.delete(id);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.mergedCollection = this.resolveMergedCollection();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
abstract create(options: IBaseTerminalServerOptions): Promise<number>;
|
|
59
|
+
|
|
60
|
+
async attach(id: number): Promise<number> {
|
|
61
|
+
const term = this.processManager.get(id);
|
|
62
|
+
|
|
63
|
+
if (term && term instanceof TerminalProcess) {
|
|
64
|
+
return term.id;
|
|
65
|
+
} else {
|
|
66
|
+
this.logger.warn(`Couldn't attach - can't find terminal with id: ${id} `);
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async onAttachAttempted(id: number): Promise<void> {
|
|
72
|
+
const terminal = this.processManager.get(id);
|
|
73
|
+
if (terminal instanceof TaskTerminalProcess) {
|
|
74
|
+
terminal.attachmentAttempted = true;
|
|
75
|
+
if (terminal.exited) {
|
|
76
|
+
// Didn't execute `unregisterProcess` on terminal `exit` event to enable attaching task output to terminal,
|
|
77
|
+
// Fixes https://github.com/eclipse-theia/theia/issues/2961
|
|
78
|
+
terminal.unregisterProcess();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getProcessId(id: number): Promise<number> {
|
|
84
|
+
const terminal = this.processManager.get(id);
|
|
85
|
+
if (!(terminal instanceof TerminalProcess)) {
|
|
86
|
+
throw new Error(`terminal "${id}" does not exist`);
|
|
87
|
+
}
|
|
88
|
+
return terminal.pid;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async getProcessInfo(id: number): Promise<TerminalProcessInfo> {
|
|
92
|
+
const terminal = this.processManager.get(id);
|
|
93
|
+
if (!(terminal instanceof TerminalProcess)) {
|
|
94
|
+
throw new Error(`terminal "${id}" does not exist`);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
executable: terminal.executable,
|
|
98
|
+
arguments: terminal.arguments,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getCwdURI(id: number): Promise<string> {
|
|
103
|
+
const terminal = this.processManager.get(id);
|
|
104
|
+
if (!(terminal instanceof TerminalProcess)) {
|
|
105
|
+
throw new Error(`terminal "${id}" does not exist`);
|
|
106
|
+
}
|
|
107
|
+
return terminal.getCwdURI();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async close(id: number): Promise<void> {
|
|
111
|
+
const term = this.processManager.get(id);
|
|
112
|
+
|
|
113
|
+
if (term instanceof TerminalProcess) {
|
|
114
|
+
term.kill();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async getDefaultShell(): Promise<string> {
|
|
119
|
+
return ShellProcess.getShellExecutablePath();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
dispose(): void {
|
|
123
|
+
// noop
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async resize(id: number, cols: number, rows: number): Promise<void> {
|
|
127
|
+
const term = this.processManager.get(id);
|
|
128
|
+
if (term && term instanceof TerminalProcess) {
|
|
129
|
+
term.resize(cols, rows);
|
|
130
|
+
} else {
|
|
131
|
+
console.warn("Couldn't resize terminal " + id + ", because it doesn't exist.");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Set the client to receive notifications on. */
|
|
136
|
+
setClient(client: IBaseTerminalClient | undefined): void {
|
|
137
|
+
this.client = client;
|
|
138
|
+
if (!this.client) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.client.updateTerminalEnvVariables();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
protected postCreate(term: TerminalProcess): void {
|
|
145
|
+
const toDispose = new DisposableCollection();
|
|
146
|
+
|
|
147
|
+
toDispose.push(term.onError(error => {
|
|
148
|
+
this.logger.error(`Terminal pid: ${term.pid} error: ${error}, closing it.`);
|
|
149
|
+
|
|
150
|
+
if (this.client !== undefined) {
|
|
151
|
+
this.client.onTerminalError({
|
|
152
|
+
'terminalId': term.id,
|
|
153
|
+
'error': new Error(`Failed to execute terminal process (${error.code})`),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
toDispose.push(term.onExit(event => {
|
|
159
|
+
if (this.client !== undefined) {
|
|
160
|
+
this.client.onTerminalExitChanged({
|
|
161
|
+
'terminalId': term.id,
|
|
162
|
+
'code': event.code,
|
|
163
|
+
'signal': event.signal
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
this.terminalToDispose.set(term.id, toDispose);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/*---------------------------------------------------------------------------------------------
|
|
172
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
173
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
174
|
+
*--------------------------------------------------------------------------------------------*/
|
|
175
|
+
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
|
|
176
|
+
|
|
177
|
+
setCollection(extensionIdentifier: string, persistent: boolean, collection: SerializableEnvironmentVariableCollection): void {
|
|
178
|
+
const translatedCollection = { persistent, map: new Map<string, EnvironmentVariableMutator>(collection) };
|
|
179
|
+
this.collections.set(extensionIdentifier, translatedCollection);
|
|
180
|
+
this.updateCollections();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
deleteCollection(extensionIdentifier: string): void {
|
|
184
|
+
this.collections.delete(extensionIdentifier);
|
|
185
|
+
this.updateCollections();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private updateCollections(): void {
|
|
189
|
+
this.persistCollections();
|
|
190
|
+
this.mergedCollection = this.resolveMergedCollection();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
protected persistCollections(): void {
|
|
194
|
+
const collectionsJson: SerializableExtensionEnvironmentVariableCollection[] = [];
|
|
195
|
+
this.collections.forEach((collection, extensionIdentifier) => {
|
|
196
|
+
if (collection.persistent) {
|
|
197
|
+
collectionsJson.push({
|
|
198
|
+
extensionIdentifier,
|
|
199
|
+
collection: [...this.collections.get(extensionIdentifier)!.map.entries()]
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (this.client) {
|
|
204
|
+
const stringifiedJson = JSON.stringify(collectionsJson);
|
|
205
|
+
this.client.storeTerminalEnvVariables(stringifiedJson);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private resolveMergedCollection(): MergedEnvironmentVariableCollection {
|
|
210
|
+
return new MergedEnvironmentVariableCollectionImpl(this.collections);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/*---------------------------------------------------------------------------------------------
|
|
216
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
217
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
218
|
+
*--------------------------------------------------------------------------------------------*/
|
|
219
|
+
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableCollection.ts
|
|
220
|
+
|
|
221
|
+
export class MergedEnvironmentVariableCollectionImpl implements MergedEnvironmentVariableCollection {
|
|
222
|
+
readonly map: Map<string, ExtensionOwnedEnvironmentVariableMutator[]> = new Map();
|
|
223
|
+
|
|
224
|
+
constructor(collections: Map<string, EnvironmentVariableCollection>) {
|
|
225
|
+
collections.forEach((collection, extensionIdentifier) => {
|
|
226
|
+
const it = collection.map.entries();
|
|
227
|
+
let next = it.next();
|
|
228
|
+
while (!next.done) {
|
|
229
|
+
const variable = next.value[0];
|
|
230
|
+
let entry = this.map.get(variable);
|
|
231
|
+
if (!entry) {
|
|
232
|
+
entry = [];
|
|
233
|
+
this.map.set(variable, entry);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// If the first item in the entry is replace ignore any other entries as they would
|
|
237
|
+
// just get replaced by this one.
|
|
238
|
+
if (entry.length > 0 && entry[0].type === EnvironmentVariableMutatorType.Replace) {
|
|
239
|
+
next = it.next();
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Mutators get applied in the reverse order than they are created
|
|
244
|
+
const mutator = next.value[1];
|
|
245
|
+
entry.unshift({
|
|
246
|
+
extensionIdentifier,
|
|
247
|
+
value: mutator.value,
|
|
248
|
+
type: mutator.type
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
next = it.next();
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
applyToProcessEnvironment(env: { [key: string]: string | null }): void {
|
|
257
|
+
let lowerToActualVariableNames: { [lowerKey: string]: string | undefined } | undefined;
|
|
258
|
+
if (isWindows) {
|
|
259
|
+
lowerToActualVariableNames = {};
|
|
260
|
+
Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e);
|
|
261
|
+
}
|
|
262
|
+
this.map.forEach((mutators, variable) => {
|
|
263
|
+
const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable;
|
|
264
|
+
mutators.forEach(mutator => {
|
|
265
|
+
switch (mutator.type) {
|
|
266
|
+
case EnvironmentVariableMutatorType.Append:
|
|
267
|
+
env[actualVariable] = (env[actualVariable] || '') + mutator.value;
|
|
268
|
+
break;
|
|
269
|
+
case EnvironmentVariableMutatorType.Prepend:
|
|
270
|
+
env[actualVariable] = mutator.value + (env[actualVariable] || '');
|
|
271
|
+
break;
|
|
272
|
+
case EnvironmentVariableMutatorType.Replace:
|
|
273
|
+
env[actualVariable] = mutator.value;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2022 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { wait } from '@theia/core/lib/common/promise-util';
|
|
18
|
-
import { expect } from 'chai';
|
|
19
|
-
import { BufferBufferingStream } from './buffering-stream';
|
|
20
|
-
|
|
21
|
-
describe('BufferringStream', () => {
|
|
22
|
-
|
|
23
|
-
it('should emit whatever data was buffered before the timeout', async () => {
|
|
24
|
-
const buffer = new BufferBufferingStream({ emitInterval: 1000 });
|
|
25
|
-
const chunkPromise = waitForChunk(buffer);
|
|
26
|
-
buffer.push(Buffer.from([0]));
|
|
27
|
-
await wait(100);
|
|
28
|
-
buffer.push(Buffer.from([1]));
|
|
29
|
-
await wait(100);
|
|
30
|
-
buffer.push(Buffer.from([2, 3, 4]));
|
|
31
|
-
const chunk = await chunkPromise;
|
|
32
|
-
expect(chunk).deep.eq(Buffer.from([0, 1, 2, 3, 4]));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should not emit chunks bigger than maxChunkSize', async () => {
|
|
36
|
-
const buffer = new BufferBufferingStream({ maxChunkSize: 2 });
|
|
37
|
-
buffer.push(Buffer.from([0, 1, 2, 3, 4, 5]));
|
|
38
|
-
expect(await waitForChunk(buffer)).deep.eq(Buffer.from([0, 1]));
|
|
39
|
-
expect(await waitForChunk(buffer)).deep.eq(Buffer.from([2, 3]));
|
|
40
|
-
expect(await waitForChunk(buffer)).deep.eq(Buffer.from([4, 5]));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
function waitForChunk(buffer: BufferBufferingStream): Promise<Buffer> {
|
|
44
|
-
return new Promise(resolve => buffer.onData(resolve));
|
|
45
|
-
}
|
|
46
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { wait } from '@theia/core/lib/common/promise-util';
|
|
18
|
+
import { expect } from 'chai';
|
|
19
|
+
import { BufferBufferingStream } from './buffering-stream';
|
|
20
|
+
|
|
21
|
+
describe('BufferringStream', () => {
|
|
22
|
+
|
|
23
|
+
it('should emit whatever data was buffered before the timeout', async () => {
|
|
24
|
+
const buffer = new BufferBufferingStream({ emitInterval: 1000 });
|
|
25
|
+
const chunkPromise = waitForChunk(buffer);
|
|
26
|
+
buffer.push(Buffer.from([0]));
|
|
27
|
+
await wait(100);
|
|
28
|
+
buffer.push(Buffer.from([1]));
|
|
29
|
+
await wait(100);
|
|
30
|
+
buffer.push(Buffer.from([2, 3, 4]));
|
|
31
|
+
const chunk = await chunkPromise;
|
|
32
|
+
expect(chunk).deep.eq(Buffer.from([0, 1, 2, 3, 4]));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should not emit chunks bigger than maxChunkSize', async () => {
|
|
36
|
+
const buffer = new BufferBufferingStream({ maxChunkSize: 2 });
|
|
37
|
+
buffer.push(Buffer.from([0, 1, 2, 3, 4, 5]));
|
|
38
|
+
expect(await waitForChunk(buffer)).deep.eq(Buffer.from([0, 1]));
|
|
39
|
+
expect(await waitForChunk(buffer)).deep.eq(Buffer.from([2, 3]));
|
|
40
|
+
expect(await waitForChunk(buffer)).deep.eq(Buffer.from([4, 5]));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function waitForChunk(buffer: BufferBufferingStream): Promise<Buffer> {
|
|
44
|
+
return new Promise(resolve => buffer.onData(resolve));
|
|
45
|
+
}
|
|
46
|
+
});
|