@theia/terminal 1.45.1 → 1.46.0-next.72

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.
Files changed (126) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/base/terminal-service.d.ts +34 -34
  3. package/lib/browser/base/terminal-service.js +7 -7
  4. package/lib/browser/base/terminal-widget.d.ts +192 -192
  5. package/lib/browser/base/terminal-widget.js +34 -34
  6. package/lib/browser/index.d.ts +1 -1
  7. package/lib/browser/index.js +28 -28
  8. package/lib/browser/search/terminal-search-container.d.ts +3 -3
  9. package/lib/browser/search/terminal-search-container.js +28 -28
  10. package/lib/browser/search/terminal-search-widget.d.ts +30 -30
  11. package/lib/browser/search/terminal-search-widget.js +147 -147
  12. package/lib/browser/shell-terminal-profile.d.ts +20 -20
  13. package/lib/browser/shell-terminal-profile.js +42 -42
  14. package/lib/browser/terminal-contribution.d.ts +3 -3
  15. package/lib/browser/terminal-contribution.js +20 -20
  16. package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
  17. package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
  18. package/lib/browser/terminal-file-link-provider.d.ts +24 -24
  19. package/lib/browser/terminal-file-link-provider.js +200 -200
  20. package/lib/browser/terminal-frontend-contribution.d.ts +115 -115
  21. package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
  22. package/lib/browser/terminal-frontend-contribution.js +1078 -1056
  23. package/lib/browser/terminal-frontend-contribution.js.map +1 -1
  24. package/lib/browser/terminal-frontend-module.d.ts +5 -5
  25. package/lib/browser/terminal-frontend-module.js +117 -117
  26. package/lib/browser/terminal-link-helpers.d.ts +27 -27
  27. package/lib/browser/terminal-link-helpers.js +155 -155
  28. package/lib/browser/terminal-link-provider.d.ts +51 -51
  29. package/lib/browser/terminal-link-provider.js +197 -197
  30. package/lib/browser/terminal-preferences.d.ts +61 -61
  31. package/lib/browser/terminal-preferences.d.ts.map +1 -1
  32. package/lib/browser/terminal-preferences.js +357 -356
  33. package/lib/browser/terminal-preferences.js.map +1 -1
  34. package/lib/browser/terminal-profile-service.d.ts +58 -58
  35. package/lib/browser/terminal-profile-service.js +158 -158
  36. package/lib/browser/terminal-quick-open-service.d.ts +36 -36
  37. package/lib/browser/terminal-quick-open-service.js +137 -137
  38. package/lib/browser/terminal-theme-service.d.ts +21 -21
  39. package/lib/browser/terminal-theme-service.d.ts.map +1 -1
  40. package/lib/browser/terminal-theme-service.js +222 -218
  41. package/lib/browser/terminal-theme-service.js.map +1 -1
  42. package/lib/browser/terminal-url-link-provider.d.ts +11 -11
  43. package/lib/browser/terminal-url-link-provider.js +76 -76
  44. package/lib/browser/terminal-widget-impl.d.ts +180 -187
  45. package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
  46. package/lib/browser/terminal-widget-impl.js +857 -867
  47. package/lib/browser/terminal-widget-impl.js.map +1 -1
  48. package/lib/common/base-terminal-protocol.d.ts +55 -55
  49. package/lib/common/base-terminal-protocol.js +84 -84
  50. package/lib/common/shell-terminal-protocol.d.ts +66 -66
  51. package/lib/common/shell-terminal-protocol.js +35 -35
  52. package/lib/common/terminal-common-module.d.ts +7 -7
  53. package/lib/common/terminal-common-module.js +31 -31
  54. package/lib/common/terminal-protocol.d.ts +12 -12
  55. package/lib/common/terminal-protocol.js +21 -21
  56. package/lib/common/terminal-watcher.d.ts +13 -13
  57. package/lib/common/terminal-watcher.js +70 -70
  58. package/lib/node/base-terminal-server.d.ts +24 -24
  59. package/lib/node/base-terminal-server.js +168 -168
  60. package/lib/node/buffering-stream.d.ts +39 -39
  61. package/lib/node/buffering-stream.js +75 -75
  62. package/lib/node/buffering-stream.spec.d.ts +1 -1
  63. package/lib/node/buffering-stream.spec.js +43 -43
  64. package/lib/node/index.d.ts +1 -1
  65. package/lib/node/index.js +28 -28
  66. package/lib/node/shell-process.d.ts +27 -27
  67. package/lib/node/shell-process.js +107 -107
  68. package/lib/node/shell-process.js.map +1 -1
  69. package/lib/node/shell-terminal-server.d.ts +30 -30
  70. package/lib/node/shell-terminal-server.js +212 -212
  71. package/lib/node/shell-terminal-server.spec.d.ts +1 -1
  72. package/lib/node/shell-terminal-server.spec.js +35 -35
  73. package/lib/node/terminal-backend-contribution.d.ts +9 -9
  74. package/lib/node/terminal-backend-contribution.js +75 -75
  75. package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
  76. package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
  77. package/lib/node/terminal-backend-module.d.ts +11 -11
  78. package/lib/node/terminal-backend-module.js +69 -69
  79. package/lib/node/terminal-server.d.ts +9 -9
  80. package/lib/node/terminal-server.js +64 -64
  81. package/lib/node/terminal-server.spec.d.ts +1 -1
  82. package/lib/node/terminal-server.spec.js +41 -41
  83. package/lib/node/test/terminal-test-container.d.ts +2 -2
  84. package/lib/node/test/terminal-test-container.js +40 -40
  85. package/lib/package.spec.js +25 -25
  86. package/package.json +12 -12
  87. package/src/browser/base/terminal-service.ts +60 -60
  88. package/src/browser/base/terminal-widget.ts +254 -254
  89. package/src/browser/index.ts +17 -17
  90. package/src/browser/search/terminal-search-container.ts +28 -28
  91. package/src/browser/search/terminal-search-widget.tsx +161 -161
  92. package/src/browser/shell-terminal-profile.ts +45 -45
  93. package/src/browser/style/terminal-search.css +99 -99
  94. package/src/browser/style/terminal.css +32 -32
  95. package/src/browser/terminal-contribution.ts +19 -19
  96. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  97. package/src/browser/terminal-file-link-provider.ts +200 -200
  98. package/src/browser/terminal-frontend-contribution.ts +1120 -1098
  99. package/src/browser/terminal-frontend-module.ts +136 -136
  100. package/src/browser/terminal-link-helpers.ts +187 -187
  101. package/src/browser/terminal-link-provider.ts +203 -203
  102. package/src/browser/terminal-preferences.ts +428 -427
  103. package/src/browser/terminal-profile-service.ts +180 -180
  104. package/src/browser/terminal-quick-open-service.ts +132 -132
  105. package/src/browser/terminal-theme-service.ts +213 -209
  106. package/src/browser/terminal-url-link-provider.ts +66 -66
  107. package/src/browser/terminal-widget-impl.ts +939 -936
  108. package/src/common/base-terminal-protocol.ts +125 -125
  109. package/src/common/shell-terminal-protocol.ts +103 -103
  110. package/src/common/terminal-common-module.ts +30 -30
  111. package/src/common/terminal-protocol.ts +32 -32
  112. package/src/common/terminal-watcher.ts +69 -69
  113. package/src/node/base-terminal-server.ts +173 -173
  114. package/src/node/buffering-stream.spec.ts +46 -46
  115. package/src/node/buffering-stream.ts +95 -95
  116. package/src/node/index.ts +17 -17
  117. package/src/node/shell-process.ts +101 -101
  118. package/src/node/shell-terminal-server.spec.ts +40 -40
  119. package/src/node/shell-terminal-server.ts +221 -221
  120. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  121. package/src/node/terminal-backend-contribution.ts +60 -60
  122. package/src/node/terminal-backend-module.ts +82 -82
  123. package/src/node/terminal-server.spec.ts +47 -47
  124. package/src/node/terminal-server.ts +52 -52
  125. package/src/node/test/terminal-test-container.ts +39 -39
  126. package/src/package.spec.ts +28 -28
@@ -1,221 +1,221 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable, named } from '@theia/core/shared/inversify';
18
- import { ILogger } from '@theia/core/lib/common/logger';
19
- import { EnvironmentUtils } from '@theia/core/lib/node/environment-utils';
20
- import { BaseTerminalServer } from './base-terminal-server';
21
- import { ShellProcessFactory, getRootPath } from './shell-process';
22
- import { ProcessManager, TerminalProcess } from '@theia/process/lib/node';
23
- import { isWindows } from '@theia/core/lib/common/os';
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';
33
-
34
- interface SerializedExtensionEnvironmentVariableCollection {
35
- extensionIdentifier: string,
36
- rootUri: string,
37
- collection: SerializableEnvironmentVariableCollection,
38
- }
39
-
40
- @injectable()
41
- export class ShellTerminalServer extends BaseTerminalServer implements IShellTerminalServer {
42
- @inject(EnvironmentUtils) protected environmentUtils: EnvironmentUtils;
43
-
44
- readonly collections: MultiKeyMap<string, EnvironmentVariableCollectionWithPersistence> = new MultiKeyMap(2);
45
-
46
- constructor(
47
- @inject(ShellProcessFactory) protected readonly shellFactory: ShellProcessFactory,
48
- @inject(ProcessManager) processManager: ProcessManager,
49
- @inject(ILogger) @named('terminal') logger: ILogger) {
50
- super(processManager, logger);
51
- }
52
-
53
- async create(options: IShellTerminalServerOptions): Promise<number> {
54
- try {
55
- if (options.strictEnv !== true) {
56
- options.env = this.environmentUtils.mergeProcessEnv(options.env);
57
- this.applyToProcessEnvironment(URI.fromFilePath(getRootPath(options.rootURI)), options.env);
58
- }
59
- const term = this.shellFactory(options);
60
- this.postCreate(term);
61
- return term.id;
62
- } catch (error) {
63
- this.logger.error('Error while creating terminal', error);
64
- return -1;
65
- }
66
- }
67
-
68
- // copied and modified from https://github.com/microsoft/vscode/blob/4636be2b71c87bfb0bfe3c94278b447a5efcc1f1/src/vs/workbench/contrib/debug/node/terminals.ts#L32-L75
69
- private spawnAsPromised(command: string, args: string[]): Promise<string> {
70
- return new Promise((resolve, reject) => {
71
- let stdout = '';
72
- const child = cp.spawn(command, args);
73
- if (child.pid) {
74
- child.stdout.on('data', (data: Buffer) => {
75
- stdout += data.toString();
76
- });
77
- }
78
- child.on('error', err => {
79
- reject(err);
80
- });
81
- child.on('close', code => {
82
- resolve(stdout);
83
- });
84
- });
85
- }
86
-
87
- public hasChildProcesses(processId: number | undefined): Promise<boolean> {
88
- if (processId) {
89
- // if shell has at least one child process, assume that shell is busy
90
- if (isWindows) {
91
- return this.spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
92
- const pids = stdout.split('\r\n');
93
- return pids.some(p => parseInt(p) === processId);
94
- }, error => true);
95
- } else {
96
- return this.spawnAsPromised('/usr/bin/pgrep', ['-lP', String(processId)]).then(stdout => {
97
- const r = stdout.trim();
98
- if (r.length === 0 || r.indexOf(' tmux') >= 0) { // ignore 'tmux';
99
- return false;
100
- } else {
101
- return true;
102
- }
103
- }, error => true);
104
- }
105
- }
106
- // fall back to safe side
107
- return Promise.resolve(true);
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
- }
221
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable, named } from '@theia/core/shared/inversify';
18
+ import { ILogger } from '@theia/core/lib/common/logger';
19
+ import { EnvironmentUtils } from '@theia/core/lib/node/environment-utils';
20
+ import { BaseTerminalServer } from './base-terminal-server';
21
+ import { ShellProcessFactory, getRootPath } from './shell-process';
22
+ import { ProcessManager, TerminalProcess } from '@theia/process/lib/node';
23
+ import { isWindows } from '@theia/core/lib/common/os';
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';
33
+
34
+ interface SerializedExtensionEnvironmentVariableCollection {
35
+ extensionIdentifier: string,
36
+ rootUri: string,
37
+ collection: SerializableEnvironmentVariableCollection,
38
+ }
39
+
40
+ @injectable()
41
+ export class ShellTerminalServer extends BaseTerminalServer implements IShellTerminalServer {
42
+ @inject(EnvironmentUtils) protected environmentUtils: EnvironmentUtils;
43
+
44
+ readonly collections: MultiKeyMap<string, EnvironmentVariableCollectionWithPersistence> = new MultiKeyMap(2);
45
+
46
+ constructor(
47
+ @inject(ShellProcessFactory) protected readonly shellFactory: ShellProcessFactory,
48
+ @inject(ProcessManager) processManager: ProcessManager,
49
+ @inject(ILogger) @named('terminal') logger: ILogger) {
50
+ super(processManager, logger);
51
+ }
52
+
53
+ async create(options: IShellTerminalServerOptions): Promise<number> {
54
+ try {
55
+ if (options.strictEnv !== true) {
56
+ options.env = this.environmentUtils.mergeProcessEnv(options.env);
57
+ this.applyToProcessEnvironment(URI.fromFilePath(getRootPath(options.rootURI)), options.env);
58
+ }
59
+ const term = this.shellFactory(options);
60
+ this.postCreate(term);
61
+ return term.id;
62
+ } catch (error) {
63
+ this.logger.error('Error while creating terminal', error);
64
+ return -1;
65
+ }
66
+ }
67
+
68
+ // copied and modified from https://github.com/microsoft/vscode/blob/4636be2b71c87bfb0bfe3c94278b447a5efcc1f1/src/vs/workbench/contrib/debug/node/terminals.ts#L32-L75
69
+ private spawnAsPromised(command: string, args: string[]): Promise<string> {
70
+ return new Promise((resolve, reject) => {
71
+ let stdout = '';
72
+ const child = cp.spawn(command, args);
73
+ if (child.pid) {
74
+ child.stdout.on('data', (data: Buffer) => {
75
+ stdout += data.toString();
76
+ });
77
+ }
78
+ child.on('error', err => {
79
+ reject(err);
80
+ });
81
+ child.on('close', code => {
82
+ resolve(stdout);
83
+ });
84
+ });
85
+ }
86
+
87
+ public hasChildProcesses(processId: number | undefined): Promise<boolean> {
88
+ if (processId) {
89
+ // if shell has at least one child process, assume that shell is busy
90
+ if (isWindows) {
91
+ return this.spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
92
+ const pids = stdout.split('\r\n');
93
+ return pids.some(p => parseInt(p) === processId);
94
+ }, error => true);
95
+ } else {
96
+ return this.spawnAsPromised('/usr/bin/pgrep', ['-lP', String(processId)]).then(stdout => {
97
+ const r = stdout.trim();
98
+ if (r.length === 0 || r.indexOf(' tmux') >= 0) { // ignore 'tmux';
99
+ return false;
100
+ } else {
101
+ return true;
102
+ }
103
+ }, error => true);
104
+ }
105
+ }
106
+ // fall back to safe side
107
+ return Promise.resolve(true);
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
+ }
221
+ }
@@ -1,63 +1,63 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { createTerminalTestContainer } from './test/terminal-test-container';
18
- import { BackendApplication } from '@theia/core/lib/node/backend-application';
19
- import { IShellTerminalServer } from '../common/shell-terminal-protocol';
20
- import * as http from 'http';
21
- import * as https from 'https';
22
- import { terminalsPath } from '../common/terminal-protocol';
23
- import { TestWebSocketChannelSetup } from '@theia/core/lib/node/messaging/test/test-web-socket-channel';
24
-
25
- describe('Terminal Backend Contribution', function (): void {
26
-
27
- this.timeout(10000);
28
- let server: http.Server | https.Server;
29
- let shellTerminalServer: IShellTerminalServer;
30
-
31
- beforeEach(async () => {
32
- const container = createTerminalTestContainer();
33
- const application = container.get(BackendApplication);
34
- shellTerminalServer = container.get(IShellTerminalServer);
35
- server = await application.start(3000, 'localhost');
36
- });
37
-
38
- afterEach(() => {
39
- const s = server;
40
- server = undefined!;
41
- shellTerminalServer = undefined!;
42
- s.close();
43
- });
44
-
45
- it('is data received from the terminal ws server', async () => {
46
- const terminalId = await shellTerminalServer.create({});
47
- await new Promise<void>((resolve, reject) => {
48
- const path = `${terminalsPath}/${terminalId}`;
49
- const { connectionProvider } = new TestWebSocketChannelSetup({ server, path });
50
-
51
- connectionProvider.listen(path, (path2, channel) => {
52
- channel.onError(reject);
53
- channel.onClose(event => reject(new Error(`channel is closed with '${event.code}' code and '${event.reason}' reason}`)));
54
- if (path2 === path) {
55
- resolve();
56
- channel.close();
57
- }
58
- }, false);
59
-
60
- });
61
- });
62
-
63
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { createTerminalTestContainer } from './test/terminal-test-container';
18
+ import { BackendApplication } from '@theia/core/lib/node/backend-application';
19
+ import { IShellTerminalServer } from '../common/shell-terminal-protocol';
20
+ import * as http from 'http';
21
+ import * as https from 'https';
22
+ import { terminalsPath } from '../common/terminal-protocol';
23
+ import { TestWebSocketChannelSetup } from '@theia/core/lib/node/messaging/test/test-web-socket-channel';
24
+
25
+ describe('Terminal Backend Contribution', function (): void {
26
+
27
+ this.timeout(10000);
28
+ let server: http.Server | https.Server;
29
+ let shellTerminalServer: IShellTerminalServer;
30
+
31
+ beforeEach(async () => {
32
+ const container = createTerminalTestContainer();
33
+ const application = container.get(BackendApplication);
34
+ shellTerminalServer = container.get(IShellTerminalServer);
35
+ server = await application.start(3000, 'localhost');
36
+ });
37
+
38
+ afterEach(() => {
39
+ const s = server;
40
+ server = undefined!;
41
+ shellTerminalServer = undefined!;
42
+ s.close();
43
+ });
44
+
45
+ it('is data received from the terminal ws server', async () => {
46
+ const terminalId = await shellTerminalServer.create({});
47
+ await new Promise<void>((resolve, reject) => {
48
+ const path = `${terminalsPath}/${terminalId}`;
49
+ const { connectionProvider } = new TestWebSocketChannelSetup({ server, path });
50
+
51
+ connectionProvider.listen(path, (path2, channel) => {
52
+ channel.onError(reject);
53
+ channel.onClose(event => reject(new Error(`channel is closed with '${event.code}' code and '${event.reason}' reason}`)));
54
+ if (path2 === path) {
55
+ resolve();
56
+ channel.close();
57
+ }
58
+ }, false);
59
+
60
+ });
61
+ });
62
+
63
+ });