@theia/terminal 1.42.1 → 1.43.0
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/lib/browser/base/terminal-widget.d.ts +1 -1
- package/lib/browser/base/terminal-widget.d.ts.map +1 -1
- package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/terminal-frontend-contribution.js +4 -5
- package/lib/browser/terminal-frontend-contribution.js.map +1 -1
- package/lib/browser/terminal-preferences.js +1 -1
- package/lib/browser/terminal-preferences.js.map +1 -1
- package/lib/browser/terminal-widget-impl.d.ts +1 -1
- package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
- package/lib/browser/terminal-widget-impl.js +12 -10
- package/lib/browser/terminal-widget-impl.js.map +1 -1
- package/lib/common/base-terminal-protocol.d.ts +0 -59
- package/lib/common/base-terminal-protocol.d.ts.map +1 -1
- package/lib/common/base-terminal-protocol.js +1 -13
- package/lib/common/base-terminal-protocol.js.map +1 -1
- package/lib/common/shell-terminal-protocol.d.ts +37 -0
- package/lib/common/shell-terminal-protocol.d.ts.map +1 -1
- package/lib/common/shell-terminal-protocol.js +14 -1
- package/lib/common/shell-terminal-protocol.js.map +1 -1
- package/lib/node/base-terminal-server.d.ts +1 -17
- package/lib/node/base-terminal-server.d.ts.map +1 -1
- package/lib/node/base-terminal-server.js +1 -111
- package/lib/node/base-terminal-server.js.map +1 -1
- package/lib/node/shell-process.d.ts +1 -0
- package/lib/node/shell-process.d.ts.map +1 -1
- package/lib/node/shell-process.js +2 -1
- package/lib/node/shell-process.js.map +1 -1
- package/lib/node/shell-terminal-server.d.ts +18 -2
- package/lib/node/shell-terminal-server.d.ts.map +1 -1
- package/lib/node/shell-terminal-server.js +99 -1
- package/lib/node/shell-terminal-server.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/base/terminal-widget.ts +1 -1
- package/src/browser/terminal-frontend-contribution.ts +2 -6
- package/src/browser/terminal-preferences.ts +1 -1
- package/src/browser/terminal-widget-impl.ts +12 -10
- package/src/common/base-terminal-protocol.ts +0 -74
- package/src/common/shell-terminal-protocol.ts +53 -0
- package/src/node/base-terminal-server.ts +1 -136
- package/src/node/shell-process.ts +1 -1
- package/src/node/shell-terminal-server.ts +132 -6
|
@@ -17,18 +17,32 @@
|
|
|
17
17
|
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
18
18
|
import { ILogger } from '@theia/core/lib/common/logger';
|
|
19
19
|
import { EnvironmentUtils } from '@theia/core/lib/node/environment-utils';
|
|
20
|
-
import { IShellTerminalServerOptions } from '../common/shell-terminal-protocol';
|
|
21
20
|
import { BaseTerminalServer } from './base-terminal-server';
|
|
22
|
-
import { ShellProcessFactory } from './shell-process';
|
|
23
|
-
import { ProcessManager } from '@theia/process/lib/node';
|
|
21
|
+
import { ShellProcessFactory, getRootPath } from './shell-process';
|
|
22
|
+
import { ProcessManager, TerminalProcess } from '@theia/process/lib/node';
|
|
24
23
|
import { isWindows } from '@theia/core/lib/common/os';
|
|
25
24
|
import * as cp from 'child_process';
|
|
25
|
+
import {
|
|
26
|
+
EnvironmentVariableCollectionWithPersistence, EnvironmentVariableMutatorType, NO_ROOT_URI, SerializableEnvironmentVariableCollection,
|
|
27
|
+
IShellTerminalServer, IShellTerminalServerOptions
|
|
28
|
+
}
|
|
29
|
+
from '../common/shell-terminal-protocol';
|
|
30
|
+
import { URI } from '@theia/core';
|
|
31
|
+
import { MultiKeyMap } from '@theia/core/lib/common/collections';
|
|
32
|
+
import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
interface SerializedExtensionEnvironmentVariableCollection {
|
|
35
|
+
extensionIdentifier: string,
|
|
36
|
+
rootUri: string,
|
|
37
|
+
collection: SerializableEnvironmentVariableCollection,
|
|
38
|
+
}
|
|
29
39
|
|
|
40
|
+
@injectable()
|
|
41
|
+
export class ShellTerminalServer extends BaseTerminalServer implements IShellTerminalServer {
|
|
30
42
|
@inject(EnvironmentUtils) protected environmentUtils: EnvironmentUtils;
|
|
31
43
|
|
|
44
|
+
readonly collections: MultiKeyMap<string, EnvironmentVariableCollectionWithPersistence> = new MultiKeyMap(2);
|
|
45
|
+
|
|
32
46
|
constructor(
|
|
33
47
|
@inject(ShellProcessFactory) protected readonly shellFactory: ShellProcessFactory,
|
|
34
48
|
@inject(ProcessManager) processManager: ProcessManager,
|
|
@@ -40,7 +54,7 @@ export class ShellTerminalServer extends BaseTerminalServer {
|
|
|
40
54
|
try {
|
|
41
55
|
if (options.strictEnv !== true) {
|
|
42
56
|
options.env = this.environmentUtils.mergeProcessEnv(options.env);
|
|
43
|
-
this.
|
|
57
|
+
this.applyToProcessEnvironment(URI.fromFilePath(getRootPath(options.rootURI)), options.env);
|
|
44
58
|
}
|
|
45
59
|
const term = this.shellFactory(options);
|
|
46
60
|
this.postCreate(term);
|
|
@@ -92,4 +106,116 @@ export class ShellTerminalServer extends BaseTerminalServer {
|
|
|
92
106
|
// fall back to safe side
|
|
93
107
|
return Promise.resolve(true);
|
|
94
108
|
}
|
|
109
|
+
|
|
110
|
+
applyToProcessEnvironment(cwdUri: URI, env: { [key: string]: string | null }): void {
|
|
111
|
+
let lowerToActualVariableNames: {
|
|
112
|
+
[lowerKey: string]: string | undefined
|
|
113
|
+
} | undefined;
|
|
114
|
+
if (isWindows) {
|
|
115
|
+
lowerToActualVariableNames = {};
|
|
116
|
+
Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e);
|
|
117
|
+
}
|
|
118
|
+
this.collections.forEach((mutators, [extensionIdentifier, rootUri]) => {
|
|
119
|
+
if (rootUri === NO_ROOT_URI || this.matchesRootUri(cwdUri, rootUri)) {
|
|
120
|
+
mutators.variableMutators.forEach((mutator, variable) => {
|
|
121
|
+
const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable;
|
|
122
|
+
switch (mutator.type) {
|
|
123
|
+
case EnvironmentVariableMutatorType.Append:
|
|
124
|
+
env[actualVariable] = (env[actualVariable] || '') + mutator.value;
|
|
125
|
+
break;
|
|
126
|
+
case EnvironmentVariableMutatorType.Prepend:
|
|
127
|
+
env[actualVariable] = mutator.value + (env[actualVariable] || '');
|
|
128
|
+
break;
|
|
129
|
+
case EnvironmentVariableMutatorType.Replace:
|
|
130
|
+
env[actualVariable] = mutator.value;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
matchesRootUri(cwdUri: URI, rootUri: string): boolean {
|
|
139
|
+
return new URI(rootUri).isEqualOrParent(cwdUri);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/*---------------------------------------------------------------------------------------------
|
|
143
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
144
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
145
|
+
*--------------------------------------------------------------------------------------------*/
|
|
146
|
+
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
|
|
147
|
+
|
|
148
|
+
setCollection(extensionIdentifier: string, baseUri: string, persistent: boolean,
|
|
149
|
+
collection: SerializableEnvironmentVariableCollection): void {
|
|
150
|
+
this.doSetCollection(extensionIdentifier, baseUri, persistent, collection);
|
|
151
|
+
this.updateCollections();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private doSetCollection(extensionIdentifier: string, baseUri: string, persistent: boolean,
|
|
155
|
+
collection: SerializableEnvironmentVariableCollection): void {
|
|
156
|
+
this.collections.set([extensionIdentifier, baseUri], {
|
|
157
|
+
persistent: persistent,
|
|
158
|
+
description: collection.description,
|
|
159
|
+
variableMutators: new Map(collection.mutators)
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
restorePersisted(jsonValue: string): void {
|
|
164
|
+
const collectionsJson: SerializedExtensionEnvironmentVariableCollection[] = JSON.parse(jsonValue);
|
|
165
|
+
collectionsJson.forEach(c => this.doSetCollection(c.extensionIdentifier, c.rootUri ?? NO_ROOT_URI, true, c.collection));
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
deleteCollection(extensionIdentifier: string): void {
|
|
170
|
+
this.collections.delete([extensionIdentifier]);
|
|
171
|
+
this.updateCollections();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private updateCollections(): void {
|
|
175
|
+
this.persistCollections();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
protected persistCollections(): void {
|
|
179
|
+
const collectionsJson: SerializedExtensionEnvironmentVariableCollection[] = [];
|
|
180
|
+
this.collections.forEach((collection, [extensionIdentifier, rootUri]) => {
|
|
181
|
+
if (collection.persistent) {
|
|
182
|
+
collectionsJson.push({
|
|
183
|
+
extensionIdentifier,
|
|
184
|
+
rootUri,
|
|
185
|
+
collection: {
|
|
186
|
+
description: collection.description,
|
|
187
|
+
mutators: [...this.collections.get([extensionIdentifier, rootUri])!.variableMutators.entries()]
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
if (this.client) {
|
|
193
|
+
const stringifiedJson = JSON.stringify(collectionsJson);
|
|
194
|
+
this.client.storeTerminalEnvVariables(stringifiedJson);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async getEnvVarCollectionDescriptionsByExtension(id: number): Promise<Map<string, (string | MarkdownString | undefined)[]>> {
|
|
199
|
+
const terminal = this.processManager.get(id);
|
|
200
|
+
if (!(terminal instanceof TerminalProcess)) {
|
|
201
|
+
throw new Error(`terminal "${id}" does not exist`);
|
|
202
|
+
}
|
|
203
|
+
const result = new Map<string, (string | MarkdownString | undefined)[]>();
|
|
204
|
+
this.collections.forEach((value, key) => {
|
|
205
|
+
const prev = result.get(key[0]) || [];
|
|
206
|
+
prev.push(value.description);
|
|
207
|
+
result.set(key[0], prev);
|
|
208
|
+
});
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async getEnvVarCollections(): Promise<[string, string, boolean, SerializableEnvironmentVariableCollection][]> {
|
|
213
|
+
const result: [string, string, boolean, SerializableEnvironmentVariableCollection][] = [];
|
|
214
|
+
|
|
215
|
+
this.collections.forEach((value, [extensionIdentifier, rootUri]) => {
|
|
216
|
+
result.push([extensionIdentifier, rootUri, value.persistent, { description: value.description, mutators: [...value.variableMutators.entries()] }]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
95
221
|
}
|