@codingame/monaco-vscode-api 1.83.15-next.0 → 1.83.16
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/README.md +430 -0
- package/contributions.js +3 -0
- package/localExtensionHost.js +3 -2
- package/missing-services.js +57 -1
- package/monaco-editor-treemending.patch +3375 -3375
- package/package.json +6 -6
- package/vscode/src/vs/base/common/prefixTree.js +130 -0
- package/vscode/src/vs/platform/actions/browser/floatingMenu.js +26 -2
- package/vscode/src/vs/platform/terminal/common/capabilities/bufferMarkCapability.js +41 -0
- package/vscode/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.js +566 -0
- package/vscode/src/vs/platform/terminal/common/capabilities/cwdDetectionCapability.js +29 -0
- package/vscode/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.js +48 -0
- package/vscode/src/vs/platform/terminal/common/capabilities/terminalCapabilityStore.js +94 -0
- package/vscode/src/vs/platform/terminal/common/terminalEnvironment.js +37 -0
- package/vscode/src/vs/platform/terminal/common/terminalStrings.js +16 -0
- package/vscode/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.js +319 -0
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.js +91 -1
- package/vscode/src/vs/workbench/contrib/format/browser/formatActionsMultiple.js +423 -0
- package/vscode/src/vs/workbench/contrib/format/browser/formatActionsNone.js +82 -0
- package/vscode/src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.js +564 -11
- package/vscode/src/vs/workbench/contrib/scm/common/scm.js +9 -1
- package/vscode/src/vs/workbench/contrib/terminal/browser/detachedTerminal.js +67 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/terminalExtensions.js +25 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/terminalIcons.js +64 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/widgets/widgetManager.js +36 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.js +538 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/decorationStyles.js +104 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/markNavigationAddon.js +416 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/suggestAddon.js +390 -0
- package/vscode/src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.js +799 -0
- package/vscode/src/vs/workbench/contrib/testing/common/getComputedState.js +101 -0
- package/vscode/src/vs/workbench/contrib/testing/common/observableValue.js +30 -0
- package/vscode/src/vs/workbench/contrib/testing/common/storedValue.js +36 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testExplorerFilterState.js +116 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testProfileService.js +172 -1
- package/vscode/src/vs/workbench/contrib/testing/common/testResult.js +384 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testResultService.js +156 -1
- package/vscode/src/vs/workbench/contrib/testing/common/testResultStorage.js +156 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testService.js +75 -1
- package/vscode/src/vs/workbench/contrib/testing/common/testTypes.js +9 -1
- package/vscode/src/vs/workbench/contrib/testing/common/testingContextKeys.js +179 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testingContinuousRunService.js +102 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testingDecorations.js +29 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testingPeekOpener.js +3 -0
- package/vscode/src/vs/workbench/contrib/testing/common/testingStates.js +47 -0
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationService.js +594 -2
- package/vscode/src/vs/workbench/services/extensions/browser/extensionUrlHandler.js +307 -1
- package/vscode/src/vs/workbench/services/suggest/browser/media/suggest.css.js +4 -0
- package/vscode/src/vs/workbench/services/suggest/browser/simpleCompletionItem.js +10 -0
- package/vscode/src/vs/workbench/services/suggest/browser/simpleCompletionModel.js +98 -0
- package/vscode/src/vs/workbench/services/suggest/browser/simpleSuggestWidget.js +428 -0
- package/vscode/src/vs/workbench/services/suggest/browser/simpleSuggestWidgetRenderer.js +83 -0
- package/vscode/src/vs/workbench/services/textfile/common/textfiles.js +6 -2
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import { __decorate } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { timeout } from 'monaco-editor/esm/vs/base/common/async.js';
|
|
3
|
+
import { debounce } from 'monaco-editor/esm/vs/base/common/decorators.js';
|
|
4
|
+
import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
|
|
5
|
+
import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
6
|
+
class CommandDetectionCapability extends Disposable {
|
|
7
|
+
get commands() { return this._commands; }
|
|
8
|
+
get executingCommand() { return this._currentCommand.command; }
|
|
9
|
+
get executingCommandObject() {
|
|
10
|
+
if (this._currentCommand.commandStartMarker) {
|
|
11
|
+
return { marker: this._currentCommand.commandStartMarker };
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
get currentCommand() {
|
|
16
|
+
return this._currentCommand;
|
|
17
|
+
}
|
|
18
|
+
get cwd() { return this._cwd; }
|
|
19
|
+
get _isInputting() {
|
|
20
|
+
return !!(this._currentCommand.commandStartMarker && !this._currentCommand.commandExecutedMarker);
|
|
21
|
+
}
|
|
22
|
+
get hasInput() {
|
|
23
|
+
if (!this._isInputting || !this._currentCommand?.commandStartMarker) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
if (this._terminal.buffer.active.baseY + this._terminal.buffer.active.cursorY === this._currentCommand.commandStartMarker?.line) {
|
|
27
|
+
const line = this._terminal.buffer.active.getLine(this._terminal.buffer.active.cursorY)?.translateToString(true, this._currentCommand.commandStartX);
|
|
28
|
+
if (line === undefined) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return line.length > 0;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
constructor(_terminal, _logService) {
|
|
36
|
+
super();
|
|
37
|
+
this._terminal = _terminal;
|
|
38
|
+
this._logService = _logService;
|
|
39
|
+
this.type = 2 ;
|
|
40
|
+
this._commands = [];
|
|
41
|
+
this._currentCommand = {};
|
|
42
|
+
this._isWindowsPty = false;
|
|
43
|
+
this._commandMarkers = [];
|
|
44
|
+
this.__isCommandStorageDisabled = false;
|
|
45
|
+
this._onCommandStarted = this._register(( new Emitter()));
|
|
46
|
+
this.onCommandStarted = this._onCommandStarted.event;
|
|
47
|
+
this._onBeforeCommandFinished = this._register(( new Emitter()));
|
|
48
|
+
this.onBeforeCommandFinished = this._onBeforeCommandFinished.event;
|
|
49
|
+
this._onCommandFinished = this._register(( new Emitter()));
|
|
50
|
+
this.onCommandFinished = this._onCommandFinished.event;
|
|
51
|
+
this._onCommandExecuted = this._register(( new Emitter()));
|
|
52
|
+
this.onCommandExecuted = this._onCommandExecuted.event;
|
|
53
|
+
this._onCommandInvalidated = this._register(( new Emitter()));
|
|
54
|
+
this.onCommandInvalidated = this._onCommandInvalidated.event;
|
|
55
|
+
this._onCurrentCommandInvalidated = this._register(( new Emitter()));
|
|
56
|
+
this.onCurrentCommandInvalidated = this._onCurrentCommandInvalidated.event;
|
|
57
|
+
this._dimensions = {
|
|
58
|
+
cols: this._terminal.cols,
|
|
59
|
+
rows: this._terminal.rows
|
|
60
|
+
};
|
|
61
|
+
this._register(this._terminal.onResize(e => this._handleResize(e)));
|
|
62
|
+
this._register(this._terminal.onCursorMove(() => this._handleCursorMove()));
|
|
63
|
+
this._setupClearListeners();
|
|
64
|
+
}
|
|
65
|
+
_handleResize(e) {
|
|
66
|
+
if (this._isWindowsPty) {
|
|
67
|
+
this._preHandleResizeWindows(e);
|
|
68
|
+
}
|
|
69
|
+
this._dimensions.cols = e.cols;
|
|
70
|
+
this._dimensions.rows = e.rows;
|
|
71
|
+
}
|
|
72
|
+
_handleCursorMove() {
|
|
73
|
+
if (this._terminal.buffer.active === this._terminal.buffer.normal && this._currentCommand.commandStartMarker) {
|
|
74
|
+
if (this._terminal.buffer.active.baseY + this._terminal.buffer.active.cursorY < this._currentCommand.commandStartMarker.line) {
|
|
75
|
+
this._clearCommandsInViewport();
|
|
76
|
+
this._currentCommand.isInvalid = true;
|
|
77
|
+
this._onCurrentCommandInvalidated.fire({ reason: "windows" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
_setupClearListeners() {
|
|
82
|
+
this._register(this.onBeforeCommandFinished(command => {
|
|
83
|
+
if (this._isWindowsPty) {
|
|
84
|
+
if (command.command.trim().toLowerCase() === 'clear' || command.command.trim().toLowerCase() === 'cls') {
|
|
85
|
+
this._clearCommandsInViewport();
|
|
86
|
+
this._currentCommand.isInvalid = true;
|
|
87
|
+
this._onCurrentCommandInvalidated.fire({ reason: "windows" });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
this._terminal.parser.registerCsiHandler({ final: 'J' }, params => {
|
|
92
|
+
if (!this._isWindowsPty) {
|
|
93
|
+
if (params.length >= 1 && (params[0] === 2 || params[0] === 3)) {
|
|
94
|
+
this._clearCommandsInViewport();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
_preHandleResizeWindows(e) {
|
|
101
|
+
const baseY = this._terminal.buffer.active.baseY;
|
|
102
|
+
const rowsDifference = e.rows - this._dimensions.rows;
|
|
103
|
+
if (rowsDifference > 0) {
|
|
104
|
+
this._waitForCursorMove().then(() => {
|
|
105
|
+
const potentialShiftedLineCount = Math.min(rowsDifference, baseY);
|
|
106
|
+
for (let i = this.commands.length - 1; i >= 0; i--) {
|
|
107
|
+
const command = this.commands[i];
|
|
108
|
+
if (!command.marker || command.marker.line < baseY || command.commandStartLineContent === undefined) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
const line = this._terminal.buffer.active.getLine(command.marker.line);
|
|
112
|
+
if (!line || line.translateToString(true) === command.commandStartLineContent) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const shiftedY = command.marker.line - potentialShiftedLineCount;
|
|
116
|
+
const shiftedLine = this._terminal.buffer.active.getLine(shiftedY);
|
|
117
|
+
if (shiftedLine?.translateToString(true) !== command.commandStartLineContent) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
this._terminal._core._bufferService.buffer.lines.onDeleteEmitter.fire({
|
|
121
|
+
index: this._terminal.buffer.active.baseY,
|
|
122
|
+
amount: potentialShiftedLineCount
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
_clearCommandsInViewport() {
|
|
129
|
+
let count = 0;
|
|
130
|
+
for (let i = this._commands.length - 1; i >= 0; i--) {
|
|
131
|
+
const line = this._commands[i].marker?.line;
|
|
132
|
+
if (line && line < this._terminal.buffer.active.baseY) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
count++;
|
|
136
|
+
}
|
|
137
|
+
if (count > 0) {
|
|
138
|
+
this._onCommandInvalidated.fire(this._commands.splice(this._commands.length - count, count));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
_waitForCursorMove() {
|
|
142
|
+
const cursorX = this._terminal.buffer.active.cursorX;
|
|
143
|
+
const cursorY = this._terminal.buffer.active.cursorY;
|
|
144
|
+
let totalDelay = 0;
|
|
145
|
+
return ( new Promise((resolve, reject) => {
|
|
146
|
+
const interval = setInterval(() => {
|
|
147
|
+
if (cursorX !== this._terminal.buffer.active.cursorX || cursorY !== this._terminal.buffer.active.cursorY) {
|
|
148
|
+
resolve();
|
|
149
|
+
clearInterval(interval);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
totalDelay += 10;
|
|
153
|
+
if (totalDelay > 1000) {
|
|
154
|
+
clearInterval(interval);
|
|
155
|
+
resolve();
|
|
156
|
+
}
|
|
157
|
+
}, 10);
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
setCwd(value) {
|
|
161
|
+
this._cwd = value;
|
|
162
|
+
}
|
|
163
|
+
setIsWindowsPty(value) {
|
|
164
|
+
this._isWindowsPty = value;
|
|
165
|
+
}
|
|
166
|
+
setIsCommandStorageDisabled() {
|
|
167
|
+
this.__isCommandStorageDisabled = true;
|
|
168
|
+
}
|
|
169
|
+
getCwdForLine(line) {
|
|
170
|
+
if (this._currentCommand.promptStartMarker && line >= this._currentCommand.promptStartMarker?.line) {
|
|
171
|
+
return this._cwd;
|
|
172
|
+
}
|
|
173
|
+
const reversed = [...this._commands].reverse();
|
|
174
|
+
return reversed.find(c => c.marker.line <= line - 1)?.cwd;
|
|
175
|
+
}
|
|
176
|
+
handlePromptStart(options) {
|
|
177
|
+
this._currentCommand.promptStartMarker = options?.marker || this._terminal.registerMarker(0);
|
|
178
|
+
this._logService.debug('CommandDetectionCapability#handlePromptStart', this._terminal.buffer.active.cursorX, this._currentCommand.promptStartMarker?.line);
|
|
179
|
+
}
|
|
180
|
+
handleContinuationStart() {
|
|
181
|
+
this._currentCommand.currentContinuationMarker = this._terminal.registerMarker(0);
|
|
182
|
+
this._logService.debug('CommandDetectionCapability#handleContinuationStart', this._currentCommand.currentContinuationMarker);
|
|
183
|
+
}
|
|
184
|
+
handleContinuationEnd() {
|
|
185
|
+
if (!this._currentCommand.currentContinuationMarker) {
|
|
186
|
+
this._logService.warn('CommandDetectionCapability#handleContinuationEnd Received continuation end without start');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!this._currentCommand.continuations) {
|
|
190
|
+
this._currentCommand.continuations = [];
|
|
191
|
+
}
|
|
192
|
+
this._currentCommand.continuations.push({
|
|
193
|
+
marker: this._currentCommand.currentContinuationMarker,
|
|
194
|
+
end: this._terminal.buffer.active.cursorX
|
|
195
|
+
});
|
|
196
|
+
this._currentCommand.currentContinuationMarker = undefined;
|
|
197
|
+
this._logService.debug('CommandDetectionCapability#handleContinuationEnd', this._currentCommand.continuations[this._currentCommand.continuations.length - 1]);
|
|
198
|
+
}
|
|
199
|
+
handleRightPromptStart() {
|
|
200
|
+
this._currentCommand.commandRightPromptStartX = this._terminal.buffer.active.cursorX;
|
|
201
|
+
this._logService.debug('CommandDetectionCapability#handleRightPromptStart', this._currentCommand.commandRightPromptStartX);
|
|
202
|
+
}
|
|
203
|
+
handleRightPromptEnd() {
|
|
204
|
+
this._currentCommand.commandRightPromptEndX = this._terminal.buffer.active.cursorX;
|
|
205
|
+
this._logService.debug('CommandDetectionCapability#handleRightPromptEnd', this._currentCommand.commandRightPromptEndX);
|
|
206
|
+
}
|
|
207
|
+
handleCommandStart(options) {
|
|
208
|
+
this._handleCommandStartOptions = options;
|
|
209
|
+
this._currentCommand.commandStartMarker = options?.marker || this._currentCommand.commandStartMarker;
|
|
210
|
+
if (this._currentCommand.commandStartMarker?.line === this._terminal.buffer.active.cursorY) {
|
|
211
|
+
this._currentCommand.commandStartX = this._terminal.buffer.active.cursorX;
|
|
212
|
+
this._logService.debug('CommandDetectionCapability#handleCommandStart', this._currentCommand.commandStartX, this._currentCommand.commandStartMarker?.line);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (this._isWindowsPty) {
|
|
216
|
+
this._handleCommandStartWindows();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
this._currentCommand.commandStartX = this._terminal.buffer.active.cursorX;
|
|
220
|
+
this._currentCommand.commandStartMarker = options?.marker || this._terminal.registerMarker(0);
|
|
221
|
+
this._currentCommand.commandExecutedMarker?.dispose();
|
|
222
|
+
this._currentCommand.commandExecutedMarker = undefined;
|
|
223
|
+
this._currentCommand.commandExecutedX = undefined;
|
|
224
|
+
for (const m of this._commandMarkers) {
|
|
225
|
+
m.dispose();
|
|
226
|
+
}
|
|
227
|
+
this._commandMarkers.length = 0;
|
|
228
|
+
this._onCommandStarted.fire({ marker: options?.marker || this._currentCommand.commandStartMarker, markProperties: options?.markProperties });
|
|
229
|
+
this._logService.debug('CommandDetectionCapability#handleCommandStart', this._currentCommand.commandStartX, this._currentCommand.commandStartMarker?.line);
|
|
230
|
+
}
|
|
231
|
+
_handleCommandStartWindows() {
|
|
232
|
+
this._currentCommand.commandStartX = this._terminal.buffer.active.cursorX;
|
|
233
|
+
this._commandMarkers.length = 0;
|
|
234
|
+
timeout(0).then(() => {
|
|
235
|
+
if (!this._currentCommand.commandExecutedMarker) {
|
|
236
|
+
this._onCursorMoveListener = this._terminal.onCursorMove(() => {
|
|
237
|
+
if (this._commandMarkers.length === 0 || this._commandMarkers[this._commandMarkers.length - 1].line !== this._terminal.buffer.active.cursorY) {
|
|
238
|
+
const marker = this._terminal.registerMarker(0);
|
|
239
|
+
if (marker) {
|
|
240
|
+
this._commandMarkers.push(marker);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
this._currentCommand.commandStartMarker = this._terminal.registerMarker(0);
|
|
246
|
+
if (this._currentCommand.commandStartMarker) {
|
|
247
|
+
const line = this._terminal.buffer.active.getLine(this._currentCommand.commandStartMarker.line);
|
|
248
|
+
if (line) {
|
|
249
|
+
this._currentCommand.commandStartLineContent = line.translateToString(true);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
this._onCommandStarted.fire({ marker: this._currentCommand.commandStartMarker });
|
|
253
|
+
this._logService.debug('CommandDetectionCapability#_handleCommandStartWindows', this._currentCommand.commandStartX, this._currentCommand.commandStartMarker?.line);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
handleGenericCommand(options) {
|
|
257
|
+
if (options?.markProperties?.disableCommandStorage) {
|
|
258
|
+
this.setIsCommandStorageDisabled();
|
|
259
|
+
}
|
|
260
|
+
this.handlePromptStart(options);
|
|
261
|
+
this.handleCommandStart(options);
|
|
262
|
+
this.handleCommandExecuted(options);
|
|
263
|
+
this.handleCommandFinished(undefined, options);
|
|
264
|
+
}
|
|
265
|
+
handleCommandExecuted(options) {
|
|
266
|
+
if (this._isWindowsPty) {
|
|
267
|
+
this._handleCommandExecutedWindows();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this._currentCommand.commandExecutedMarker = options?.marker || this._terminal.registerMarker(0);
|
|
271
|
+
this._currentCommand.commandExecutedX = this._terminal.buffer.active.cursorX;
|
|
272
|
+
this._logService.debug('CommandDetectionCapability#handleCommandExecuted', this._currentCommand.commandExecutedX, this._currentCommand.commandExecutedMarker?.line);
|
|
273
|
+
if (!this._currentCommand.commandStartMarker || !this._currentCommand.commandExecutedMarker || this._currentCommand.commandStartX === undefined) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this._currentCommand.command = this.__isCommandStorageDisabled ? '' : this._terminal.buffer.active.getLine(this._currentCommand.commandStartMarker.line)?.translateToString(true, this._currentCommand.commandStartX, this._currentCommand.commandRightPromptStartX).trim();
|
|
277
|
+
let y = this._currentCommand.commandStartMarker.line + 1;
|
|
278
|
+
const commandExecutedLine = this._currentCommand.commandExecutedMarker.line;
|
|
279
|
+
for (; y < commandExecutedLine; y++) {
|
|
280
|
+
const line = this._terminal.buffer.active.getLine(y);
|
|
281
|
+
if (line) {
|
|
282
|
+
const continuation = this._currentCommand.continuations?.find(e => e.marker.line === y);
|
|
283
|
+
if (continuation) {
|
|
284
|
+
this._currentCommand.command += '\n';
|
|
285
|
+
}
|
|
286
|
+
const startColumn = continuation?.end ?? 0;
|
|
287
|
+
this._currentCommand.command += line.translateToString(true, startColumn);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (y === commandExecutedLine) {
|
|
291
|
+
this._currentCommand.command += this._terminal.buffer.active.getLine(commandExecutedLine)?.translateToString(true, undefined, this._currentCommand.commandExecutedX) || '';
|
|
292
|
+
}
|
|
293
|
+
this._onCommandExecuted.fire();
|
|
294
|
+
}
|
|
295
|
+
_handleCommandExecutedWindows() {
|
|
296
|
+
this._onCursorMoveListener?.dispose();
|
|
297
|
+
this._onCursorMoveListener = undefined;
|
|
298
|
+
this._evaluateCommandMarkersWindows();
|
|
299
|
+
this._currentCommand.commandExecutedX = this._terminal.buffer.active.cursorX;
|
|
300
|
+
this._onCommandExecuted.fire();
|
|
301
|
+
this._logService.debug('CommandDetectionCapability#handleCommandExecuted', this._currentCommand.commandExecutedX, this._currentCommand.commandExecutedMarker?.line);
|
|
302
|
+
}
|
|
303
|
+
invalidateCurrentCommand(request) {
|
|
304
|
+
this._currentCommand.isInvalid = true;
|
|
305
|
+
this._onCurrentCommandInvalidated.fire(request);
|
|
306
|
+
}
|
|
307
|
+
handleCommandFinished(exitCode, options) {
|
|
308
|
+
if (this._isWindowsPty) {
|
|
309
|
+
this._preHandleCommandFinishedWindows();
|
|
310
|
+
}
|
|
311
|
+
this._currentCommand.commandFinishedMarker = options?.marker || this._terminal.registerMarker(0);
|
|
312
|
+
let command = this._currentCommand.command;
|
|
313
|
+
this._logService.debug('CommandDetectionCapability#handleCommandFinished', this._terminal.buffer.active.cursorX, this._currentCommand.commandFinishedMarker?.line, this._currentCommand.command, this._currentCommand);
|
|
314
|
+
this._exitCode = exitCode;
|
|
315
|
+
if (this._exitCode === undefined) {
|
|
316
|
+
const lastCommand = this.commands.length > 0 ? this.commands[this.commands.length - 1] : undefined;
|
|
317
|
+
if (command && command.length > 0 && lastCommand?.command === command) {
|
|
318
|
+
this._exitCode = lastCommand.exitCode;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (this._currentCommand.commandStartMarker === undefined || !this._terminal.buffer.active) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (this._exitCode === undefined && command === undefined) {
|
|
325
|
+
command = '';
|
|
326
|
+
}
|
|
327
|
+
if ((command !== undefined && !command.startsWith('\\')) || this._handleCommandStartOptions?.ignoreCommandLine) {
|
|
328
|
+
const buffer = this._terminal.buffer.active;
|
|
329
|
+
const timestamp = Date.now();
|
|
330
|
+
const executedMarker = this._currentCommand.commandExecutedMarker;
|
|
331
|
+
const endMarker = this._currentCommand.commandFinishedMarker;
|
|
332
|
+
const newCommand = {
|
|
333
|
+
command: this._handleCommandStartOptions?.ignoreCommandLine ? '' : (command || ''),
|
|
334
|
+
isTrusted: !!this._currentCommand.isTrusted,
|
|
335
|
+
marker: this._currentCommand.commandStartMarker,
|
|
336
|
+
endMarker,
|
|
337
|
+
executedMarker,
|
|
338
|
+
timestamp,
|
|
339
|
+
cwd: this._cwd,
|
|
340
|
+
exitCode: this._exitCode,
|
|
341
|
+
commandStartLineContent: this._currentCommand.commandStartLineContent,
|
|
342
|
+
hasOutput: () => !executedMarker?.isDisposed && !endMarker?.isDisposed && !!(executedMarker && endMarker && executedMarker?.line < endMarker.line),
|
|
343
|
+
getOutput: () => getOutputForCommand(executedMarker, endMarker, buffer),
|
|
344
|
+
getOutputMatch: (outputMatcher) => getOutputMatchForCommand(this._isWindowsPty && (executedMarker?.line === endMarker?.line) ? this._currentCommand.commandStartMarker : executedMarker, endMarker, buffer, this._terminal.cols, outputMatcher),
|
|
345
|
+
markProperties: options?.markProperties
|
|
346
|
+
};
|
|
347
|
+
this._commands.push(newCommand);
|
|
348
|
+
this._logService.debug('CommandDetectionCapability#onCommandFinished', newCommand);
|
|
349
|
+
this._onBeforeCommandFinished.fire(newCommand);
|
|
350
|
+
if (!this._currentCommand.isInvalid) {
|
|
351
|
+
this._onCommandFinished.fire(newCommand);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
this._currentCommand.previousCommandMarker = this._currentCommand.commandStartMarker;
|
|
355
|
+
this._currentCommand = {};
|
|
356
|
+
this._handleCommandStartOptions = undefined;
|
|
357
|
+
}
|
|
358
|
+
_preHandleCommandFinishedWindows() {
|
|
359
|
+
if (this._currentCommand.commandExecutedMarker) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (this._commandMarkers.length === 0) {
|
|
363
|
+
if (!this._currentCommand.commandStartMarker) {
|
|
364
|
+
this._currentCommand.commandStartMarker = this._terminal.registerMarker(0);
|
|
365
|
+
}
|
|
366
|
+
if (this._currentCommand.commandStartMarker) {
|
|
367
|
+
this._commandMarkers.push(this._currentCommand.commandStartMarker);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
this._evaluateCommandMarkersWindows();
|
|
371
|
+
}
|
|
372
|
+
_evaluateCommandMarkersWindows() {
|
|
373
|
+
if (this._commandMarkers.length === 0) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
this._commandMarkers = this._commandMarkers.sort((a, b) => a.line - b.line);
|
|
377
|
+
this._currentCommand.commandStartMarker = this._commandMarkers[0];
|
|
378
|
+
if (this._currentCommand.commandStartMarker) {
|
|
379
|
+
const line = this._terminal.buffer.active.getLine(this._currentCommand.commandStartMarker.line);
|
|
380
|
+
if (line) {
|
|
381
|
+
this._currentCommand.commandStartLineContent = line.translateToString(true);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
this._currentCommand.commandExecutedMarker = this._commandMarkers[this._commandMarkers.length - 1];
|
|
385
|
+
}
|
|
386
|
+
setCommandLine(commandLine, isTrusted) {
|
|
387
|
+
this._logService.debug('CommandDetectionCapability#setCommandLine', commandLine, isTrusted);
|
|
388
|
+
this._currentCommand.command = commandLine;
|
|
389
|
+
this._currentCommand.isTrusted = isTrusted;
|
|
390
|
+
}
|
|
391
|
+
serialize() {
|
|
392
|
+
const commands = ( this.commands.map(e => {
|
|
393
|
+
return {
|
|
394
|
+
startLine: e.marker?.line,
|
|
395
|
+
startX: undefined,
|
|
396
|
+
endLine: e.endMarker?.line,
|
|
397
|
+
executedLine: e.executedMarker?.line,
|
|
398
|
+
command: this.__isCommandStorageDisabled ? '' : e.command,
|
|
399
|
+
isTrusted: e.isTrusted,
|
|
400
|
+
cwd: e.cwd,
|
|
401
|
+
exitCode: e.exitCode,
|
|
402
|
+
commandStartLineContent: e.commandStartLineContent,
|
|
403
|
+
timestamp: e.timestamp,
|
|
404
|
+
markProperties: e.markProperties,
|
|
405
|
+
aliases: e.aliases
|
|
406
|
+
};
|
|
407
|
+
}));
|
|
408
|
+
if (this._currentCommand.commandStartMarker) {
|
|
409
|
+
commands.push({
|
|
410
|
+
startLine: this._currentCommand.commandStartMarker.line,
|
|
411
|
+
startX: this._currentCommand.commandStartX,
|
|
412
|
+
endLine: undefined,
|
|
413
|
+
executedLine: undefined,
|
|
414
|
+
command: '',
|
|
415
|
+
isTrusted: true,
|
|
416
|
+
cwd: this._cwd,
|
|
417
|
+
exitCode: undefined,
|
|
418
|
+
commandStartLineContent: undefined,
|
|
419
|
+
timestamp: 0,
|
|
420
|
+
markProperties: undefined
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
isWindowsPty: this._isWindowsPty,
|
|
425
|
+
commands
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
deserialize(serialized) {
|
|
429
|
+
if (serialized.isWindowsPty) {
|
|
430
|
+
this.setIsWindowsPty(serialized.isWindowsPty);
|
|
431
|
+
}
|
|
432
|
+
const buffer = this._terminal.buffer.normal;
|
|
433
|
+
for (const e of serialized.commands) {
|
|
434
|
+
const marker = e.startLine !== undefined ? this._terminal.registerMarker(e.startLine - (buffer.baseY + buffer.cursorY)) : undefined;
|
|
435
|
+
if (!marker) {
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
if (!e.endLine) {
|
|
439
|
+
this._currentCommand.commandStartMarker = marker;
|
|
440
|
+
this._currentCommand.commandStartX = e.startX;
|
|
441
|
+
this._cwd = e.cwd;
|
|
442
|
+
this._onCommandStarted.fire({ marker });
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
const endMarker = e.endLine !== undefined ? this._terminal.registerMarker(e.endLine - (buffer.baseY + buffer.cursorY)) : undefined;
|
|
446
|
+
const executedMarker = e.executedLine !== undefined ? this._terminal.registerMarker(e.executedLine - (buffer.baseY + buffer.cursorY)) : undefined;
|
|
447
|
+
const newCommand = {
|
|
448
|
+
command: this.__isCommandStorageDisabled ? '' : e.command,
|
|
449
|
+
isTrusted: e.isTrusted,
|
|
450
|
+
marker,
|
|
451
|
+
endMarker,
|
|
452
|
+
executedMarker,
|
|
453
|
+
timestamp: e.timestamp,
|
|
454
|
+
cwd: e.cwd,
|
|
455
|
+
commandStartLineContent: e.commandStartLineContent,
|
|
456
|
+
exitCode: e.exitCode,
|
|
457
|
+
hasOutput: () => !executedMarker?.isDisposed && !endMarker?.isDisposed && !!(executedMarker && endMarker && executedMarker.line < endMarker.line),
|
|
458
|
+
getOutput: () => getOutputForCommand(executedMarker, endMarker, buffer),
|
|
459
|
+
getOutputMatch: (outputMatcher) => getOutputMatchForCommand(this._isWindowsPty && (executedMarker?.line === endMarker?.line) ? marker : executedMarker, endMarker, buffer, this._terminal.cols, outputMatcher),
|
|
460
|
+
markProperties: e.markProperties,
|
|
461
|
+
wasReplayed: true
|
|
462
|
+
};
|
|
463
|
+
this._commands.push(newCommand);
|
|
464
|
+
this._logService.debug('CommandDetectionCapability#onCommandFinished', newCommand);
|
|
465
|
+
this._onCommandFinished.fire(newCommand);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
CommandDetectionCapability.__decorator = ( __decorate([
|
|
470
|
+
debounce(500)
|
|
471
|
+
], CommandDetectionCapability.prototype, "_handleCursorMove", null));
|
|
472
|
+
function getOutputForCommand(executedMarker, endMarker, buffer) {
|
|
473
|
+
if (!executedMarker || !endMarker) {
|
|
474
|
+
return undefined;
|
|
475
|
+
}
|
|
476
|
+
const startLine = executedMarker.line;
|
|
477
|
+
const endLine = endMarker.line;
|
|
478
|
+
if (startLine === endLine) {
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
let output = '';
|
|
482
|
+
let line;
|
|
483
|
+
for (let i = startLine; i < endLine; i++) {
|
|
484
|
+
line = buffer.getLine(i);
|
|
485
|
+
if (!line) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
output += line.translateToString(!line.isWrapped) + (line.isWrapped ? '' : '\n');
|
|
489
|
+
}
|
|
490
|
+
return output === '' ? undefined : output;
|
|
491
|
+
}
|
|
492
|
+
function getOutputMatchForCommand(executedMarker, endMarker, buffer, cols, outputMatcher) {
|
|
493
|
+
if (!executedMarker || !endMarker) {
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
const endLine = endMarker.line;
|
|
497
|
+
if (endLine === -1) {
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
const startLine = Math.max(executedMarker.line, 0);
|
|
501
|
+
const matcher = outputMatcher.lineMatcher;
|
|
502
|
+
const linesToCheck = typeof matcher === 'string' ? 1 : outputMatcher.length || countNewLines(matcher);
|
|
503
|
+
const lines = [];
|
|
504
|
+
let match;
|
|
505
|
+
if (outputMatcher.anchor === 'bottom') {
|
|
506
|
+
for (let i = endLine - (outputMatcher.offset || 0); i >= startLine; i--) {
|
|
507
|
+
let wrappedLineStart = i;
|
|
508
|
+
const wrappedLineEnd = i;
|
|
509
|
+
while (wrappedLineStart >= startLine && buffer.getLine(wrappedLineStart)?.isWrapped) {
|
|
510
|
+
wrappedLineStart--;
|
|
511
|
+
}
|
|
512
|
+
i = wrappedLineStart;
|
|
513
|
+
lines.unshift(getXtermLineContent(buffer, wrappedLineStart, wrappedLineEnd, cols));
|
|
514
|
+
if (!match) {
|
|
515
|
+
match = lines[0].match(matcher);
|
|
516
|
+
}
|
|
517
|
+
if (lines.length >= linesToCheck) {
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
for (let i = startLine + (outputMatcher.offset || 0); i < endLine; i++) {
|
|
524
|
+
const wrappedLineStart = i;
|
|
525
|
+
let wrappedLineEnd = i;
|
|
526
|
+
while (wrappedLineEnd + 1 < endLine && buffer.getLine(wrappedLineEnd + 1)?.isWrapped) {
|
|
527
|
+
wrappedLineEnd++;
|
|
528
|
+
}
|
|
529
|
+
i = wrappedLineEnd;
|
|
530
|
+
lines.push(getXtermLineContent(buffer, wrappedLineStart, wrappedLineEnd, cols));
|
|
531
|
+
if (!match) {
|
|
532
|
+
match = lines[lines.length - 1].match(matcher);
|
|
533
|
+
}
|
|
534
|
+
if (lines.length >= linesToCheck) {
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return match ? { regexMatch: match, outputLines: lines } : undefined;
|
|
540
|
+
}
|
|
541
|
+
function getXtermLineContent(buffer, lineStart, lineEnd, cols) {
|
|
542
|
+
const maxLineLength = Math.max(2048 / cols * 2);
|
|
543
|
+
lineEnd = Math.min(lineEnd, lineStart + maxLineLength);
|
|
544
|
+
let content = '';
|
|
545
|
+
for (let i = lineStart; i <= lineEnd; i++) {
|
|
546
|
+
const line = buffer.getLine(i);
|
|
547
|
+
if (line) {
|
|
548
|
+
content += line.translateToString(true, 0, cols);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return content;
|
|
552
|
+
}
|
|
553
|
+
function countNewLines(regex) {
|
|
554
|
+
if (!regex.multiline) {
|
|
555
|
+
return 1;
|
|
556
|
+
}
|
|
557
|
+
const source = regex.source;
|
|
558
|
+
let count = 1;
|
|
559
|
+
let i = source.indexOf('\\n');
|
|
560
|
+
while (i !== -1) {
|
|
561
|
+
count++;
|
|
562
|
+
i = source.indexOf('\\n', i + 1);
|
|
563
|
+
}
|
|
564
|
+
return count;
|
|
565
|
+
}
|
|
566
|
+
export { CommandDetectionCapability };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
|
|
2
|
+
import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
3
|
+
class CwdDetectionCapability extends Disposable {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.type = 0 ;
|
|
7
|
+
this._cwd = '';
|
|
8
|
+
this._cwds = ( new Map());
|
|
9
|
+
this._onDidChangeCwd = this._register(( new Emitter()));
|
|
10
|
+
this.onDidChangeCwd = this._onDidChangeCwd.event;
|
|
11
|
+
}
|
|
12
|
+
get cwds() {
|
|
13
|
+
return Array.from(( this._cwds.keys()));
|
|
14
|
+
}
|
|
15
|
+
getCwd() {
|
|
16
|
+
return this._cwd;
|
|
17
|
+
}
|
|
18
|
+
updateCwd(cwd) {
|
|
19
|
+
const didChange = this._cwd !== cwd;
|
|
20
|
+
this._cwd = cwd;
|
|
21
|
+
const count = this._cwds.get(this._cwd) || 0;
|
|
22
|
+
this._cwds.delete(this._cwd);
|
|
23
|
+
this._cwds.set(this._cwd, count + 1);
|
|
24
|
+
if (didChange) {
|
|
25
|
+
this._onDidChangeCwd.fire(cwd);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export { CwdDetectionCapability };
|
package/vscode/src/vs/platform/terminal/common/capabilities/partialCommandDetectionCapability.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
|
|
2
|
+
import { DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
3
|
+
class PartialCommandDetectionCapability extends DisposableStore {
|
|
4
|
+
get commands() { return this._commands; }
|
|
5
|
+
constructor(_terminal) {
|
|
6
|
+
super();
|
|
7
|
+
this._terminal = _terminal;
|
|
8
|
+
this.type = 3 ;
|
|
9
|
+
this._commands = [];
|
|
10
|
+
this._onCommandFinished = this.add(( new Emitter()));
|
|
11
|
+
this.onCommandFinished = this._onCommandFinished.event;
|
|
12
|
+
this.add(this._terminal.onData(e => this._onData(e)));
|
|
13
|
+
this.add(this._terminal.parser.registerCsiHandler({ final: 'J' }, params => {
|
|
14
|
+
if (params.length >= 1 && (params[0] === 2 || params[0] === 3)) {
|
|
15
|
+
this._clearCommandsInViewport();
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
_onData(data) {
|
|
21
|
+
if (data === '\x0d') {
|
|
22
|
+
this._onEnter();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
_onEnter() {
|
|
26
|
+
if (!this._terminal) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (this._terminal.buffer.active.cursorX >= 2 ) {
|
|
30
|
+
const marker = this._terminal.registerMarker(0);
|
|
31
|
+
if (marker) {
|
|
32
|
+
this._commands.push(marker);
|
|
33
|
+
this._onCommandFinished.fire(marker);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
_clearCommandsInViewport() {
|
|
38
|
+
let count = 0;
|
|
39
|
+
for (let i = this._commands.length - 1; i >= 0; i--) {
|
|
40
|
+
if (this._commands[i].line < this._terminal.buffer.active.baseY) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
count++;
|
|
44
|
+
}
|
|
45
|
+
this._commands.splice(this._commands.length - count, count);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export { PartialCommandDetectionCapability };
|