@theia/debug 1.53.0-next.5 → 1.53.0-next.55
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 +62 -62
- package/lib/browser/debug-configuration-manager.js +6 -6
- package/lib/browser/debug-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/debug-frontend-application-contribution.js.map +1 -1
- package/lib/common/inline-debug-adapter.d.ts +1 -0
- package/lib/common/inline-debug-adapter.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
- package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
- package/src/browser/console/debug-console-contribution.tsx +240 -240
- package/src/browser/console/debug-console-items.tsx +384 -384
- package/src/browser/console/debug-console-session.ts +205 -205
- package/src/browser/debug-call-stack-item-type-key.ts +20 -20
- package/src/browser/debug-configuration-manager.ts +591 -591
- package/src/browser/debug-configuration-model.ts +100 -100
- package/src/browser/debug-contribution.ts +43 -43
- package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
- package/src/browser/debug-frontend-module.ts +133 -133
- package/src/browser/debug-package.spec.ts +20 -20
- package/src/browser/debug-preferences.ts +98 -98
- package/src/browser/debug-prefix-configuration.ts +195 -195
- package/src/browser/debug-resource.ts +59 -59
- package/src/browser/debug-schema-updater.ts +149 -149
- package/src/browser/debug-session-connection.ts +357 -357
- package/src/browser/debug-session-contribution.ts +157 -157
- package/src/browser/debug-session-manager.ts +683 -683
- package/src/browser/debug-session-options.ts +120 -120
- package/src/browser/debug-session.tsx +974 -974
- package/src/browser/debug-tab-bar-decorator.ts +57 -57
- package/src/browser/debug-watch-manager.ts +93 -93
- package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
- package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
- package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
- package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
- package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
- package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
- package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
- package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
- package/src/browser/editor/debug-editor-model.ts +529 -529
- package/src/browser/editor/debug-editor-service.ts +192 -192
- package/src/browser/editor/debug-editor.ts +20 -20
- package/src/browser/editor/debug-exception-widget.tsx +122 -122
- package/src/browser/editor/debug-expression-provider.ts +78 -78
- package/src/browser/editor/debug-hover-source.tsx +105 -105
- package/src/browser/editor/debug-hover-widget.ts +298 -298
- package/src/browser/editor/debug-inline-value-decorator.ts +373 -373
- package/src/browser/model/debug-breakpoint.tsx +151 -151
- package/src/browser/model/debug-function-breakpoint.tsx +101 -101
- package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
- package/src/browser/model/debug-source-breakpoint.tsx +237 -237
- package/src/browser/model/debug-source.ts +93 -93
- package/src/browser/model/debug-stack-frame.tsx +177 -177
- package/src/browser/model/debug-thread.tsx +292 -292
- package/src/browser/preferences/launch-preferences.ts +38 -38
- package/src/browser/style/index.css +453 -453
- package/src/browser/view/debug-action.tsx +57 -57
- package/src/browser/view/debug-breakpoints-source.tsx +53 -53
- package/src/browser/view/debug-breakpoints-widget.ts +71 -71
- package/src/browser/view/debug-configuration-select.tsx +269 -269
- package/src/browser/view/debug-configuration-widget.tsx +121 -121
- package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
- package/src/browser/view/debug-session-widget.ts +124 -124
- package/src/browser/view/debug-stack-frames-source.tsx +75 -75
- package/src/browser/view/debug-stack-frames-widget.ts +135 -135
- package/src/browser/view/debug-threads-source.tsx +48 -48
- package/src/browser/view/debug-threads-widget.ts +126 -126
- package/src/browser/view/debug-toolbar-widget.tsx +145 -145
- package/src/browser/view/debug-variables-source.ts +43 -43
- package/src/browser/view/debug-variables-widget.ts +61 -61
- package/src/browser/view/debug-view-model.ts +230 -230
- package/src/browser/view/debug-watch-expression.tsx +88 -88
- package/src/browser/view/debug-watch-source.ts +41 -41
- package/src/browser/view/debug-watch-widget.ts +61 -61
- package/src/browser/view/debug-widget.ts +97 -97
- package/src/common/debug-adapter-contribution-registry.ts +206 -206
- package/src/common/debug-adapter-session.ts +102 -102
- package/src/common/debug-common.ts +19 -19
- package/src/common/debug-compound.ts +33 -33
- package/src/common/debug-configuration.ts +112 -112
- package/src/common/debug-model.ts +200 -200
- package/src/common/debug-service.ts +184 -184
- package/src/common/debug-uri-utils.ts +24 -24
- package/src/common/inline-debug-adapter.ts +47 -47
- package/src/node/debug-adapter-factory.ts +107 -107
- package/src/node/debug-adapter-session-manager.ts +106 -106
- package/src/node/debug-backend-module.ts +57 -57
- package/src/node/debug-service-impl.ts +119 -119
- package/src/node/stream-debug-adapter.ts +126 -126
|
@@ -1,373 +1,373 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 TypeFox 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
|
-
/*---------------------------------------------------------------------------------------------
|
|
18
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
20
|
-
*--------------------------------------------------------------------------------------------*/
|
|
21
|
-
// Based on https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts
|
|
22
|
-
|
|
23
|
-
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application-contribution';
|
|
24
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
25
|
-
import * as monaco from '@theia/monaco-editor-core';
|
|
26
|
-
import { CancellationTokenSource } from '@theia/monaco-editor-core/esm/vs/base/common/cancellation';
|
|
27
|
-
import { DEFAULT_WORD_REGEXP } from '@theia/monaco-editor-core/esm/vs/editor/common/core/wordHelper';
|
|
28
|
-
import { IDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon';
|
|
29
|
-
import { StandardTokenType } from '@theia/monaco-editor-core/esm/vs/editor/common/encodedTokenAttributes';
|
|
30
|
-
import { InlineValueContext } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
|
|
31
|
-
import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
|
|
32
|
-
import { ILanguageFeaturesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/languageFeatures';
|
|
33
|
-
import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
|
|
34
|
-
import { DebugVariable, ExpressionContainer, ExpressionItem } from '../console/debug-console-items';
|
|
35
|
-
import { DebugPreferences } from '../debug-preferences';
|
|
36
|
-
import { DebugStackFrame } from '../model/debug-stack-frame';
|
|
37
|
-
import { DebugEditorModel } from './debug-editor-model';
|
|
38
|
-
import { ICodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/codeEditorService';
|
|
39
|
-
|
|
40
|
-
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L40-L43
|
|
41
|
-
export const INLINE_VALUE_DECORATION_KEY = 'inlinevaluedecoration';
|
|
42
|
-
const MAX_NUM_INLINE_VALUES = 100; // JS Global scope can have 700+ entries. We want to limit ourselves for perf reasons
|
|
43
|
-
const MAX_INLINE_DECORATOR_LENGTH = 150; // Max string length of each inline decorator when debugging. If exceeded ... is added
|
|
44
|
-
const MAX_TOKENIZATION_LINE_LEN = 500; // If line is too long, then inline values for the line are skipped
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* MAX SMI (SMall Integer) as defined in v8.
|
|
48
|
-
* one bit is lost for boxing/unboxing flag.
|
|
49
|
-
* one bit is lost for sign flag.
|
|
50
|
-
* See https://thibaultlaurens.github.io/javascript/2013/04/29/how-the-v8-engine-works/#tagged-values
|
|
51
|
-
*/
|
|
52
|
-
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/base/common/uint.ts#L7-L13
|
|
53
|
-
const MAX_SAFE_SMALL_INTEGER = 1 << 30;
|
|
54
|
-
|
|
55
|
-
class InlineSegment {
|
|
56
|
-
constructor(public column: number, public text: string) {
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@injectable()
|
|
61
|
-
export class DebugInlineValueDecorator implements FrontendApplicationContribution {
|
|
62
|
-
@inject(DebugPreferences)
|
|
63
|
-
protected readonly preferences: DebugPreferences;
|
|
64
|
-
|
|
65
|
-
protected enabled = false;
|
|
66
|
-
protected wordToLineNumbersMap: Map<string, monaco.Position[]> | undefined = new Map();
|
|
67
|
-
|
|
68
|
-
onStart(): void {
|
|
69
|
-
StandaloneServices.get(ICodeEditorService).registerDecorationType('Inline debug decorations', INLINE_VALUE_DECORATION_KEY, {});
|
|
70
|
-
this.enabled = !!this.preferences['debug.inlineValues'];
|
|
71
|
-
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
|
|
72
|
-
if (preferenceName === 'debug.inlineValues' && !!newValue !== this.enabled) {
|
|
73
|
-
this.enabled = !!newValue;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async calculateDecorations(debugEditorModel: DebugEditorModel, stackFrame: DebugStackFrame | undefined): Promise<IDecorationOptions[]> {
|
|
79
|
-
this.wordToLineNumbersMap = undefined;
|
|
80
|
-
const model = debugEditorModel.editor.getControl().getModel() || undefined;
|
|
81
|
-
return this.updateInlineValueDecorations(debugEditorModel, model, stackFrame);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L382-L408
|
|
85
|
-
protected async updateInlineValueDecorations(
|
|
86
|
-
debugEditorModel: DebugEditorModel,
|
|
87
|
-
model: monaco.editor.ITextModel | undefined,
|
|
88
|
-
stackFrame: DebugStackFrame | undefined): Promise<IDecorationOptions[]> {
|
|
89
|
-
|
|
90
|
-
if (!this.enabled || !model || !stackFrame || !stackFrame.source || model.uri.toString() !== stackFrame.source.uri.toString()) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// XXX: Here is a difference between the VS Code's `IStackFrame` and the `DebugProtocol.StackFrame`.
|
|
95
|
-
// In DAP, `source` is optional, hence `range` is optional too.
|
|
96
|
-
const { range: stackFrameRange } = stackFrame;
|
|
97
|
-
if (!stackFrameRange) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const scopes = await stackFrame.getMostSpecificScopes(stackFrameRange);
|
|
102
|
-
// Get all top level children in the scope chain
|
|
103
|
-
const decorationsPerScope = await Promise.all(scopes.map(async scope => {
|
|
104
|
-
const children = Array.from(await scope.getElements());
|
|
105
|
-
let range = new monaco.Range(0, 0, stackFrameRange.startLineNumber, stackFrameRange.startColumn);
|
|
106
|
-
if (scope.range) {
|
|
107
|
-
range = range.setStartPosition(scope.range.startLineNumber, scope.range.startColumn);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return this.createInlineValueDecorationsInsideRange(children, range, model, debugEditorModel, stackFrame);
|
|
111
|
-
}));
|
|
112
|
-
|
|
113
|
-
return decorationsPerScope.reduce((previous, current) => previous.concat(current), []);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L410-L452
|
|
117
|
-
private async createInlineValueDecorationsInsideRange(
|
|
118
|
-
expressions: ReadonlyArray<ExpressionContainer>,
|
|
119
|
-
range: monaco.Range,
|
|
120
|
-
model: monaco.editor.ITextModel,
|
|
121
|
-
debugEditorModel: DebugEditorModel,
|
|
122
|
-
stackFrame: DebugStackFrame): Promise<IDecorationOptions[]> {
|
|
123
|
-
|
|
124
|
-
const decorations: IDecorationOptions[] = [];
|
|
125
|
-
|
|
126
|
-
const inlineValuesProvider = StandaloneServices.get(ILanguageFeaturesService).inlineValuesProvider;
|
|
127
|
-
const textEditorModel = debugEditorModel.editor.document.textEditorModel;
|
|
128
|
-
|
|
129
|
-
if (inlineValuesProvider && inlineValuesProvider.has(textEditorModel)) {
|
|
130
|
-
|
|
131
|
-
const findVariable = async (variableName: string, caseSensitiveLookup: boolean): Promise<DebugVariable | undefined> => {
|
|
132
|
-
const scopes = await stackFrame.getMostSpecificScopes(stackFrame.range!);
|
|
133
|
-
const key = caseSensitiveLookup ? variableName : variableName.toLowerCase();
|
|
134
|
-
for (const scope of scopes) {
|
|
135
|
-
const expressionContainers = await scope.getElements();
|
|
136
|
-
let container = expressionContainers.next();
|
|
137
|
-
while (!container.done) {
|
|
138
|
-
const debugVariable = container.value;
|
|
139
|
-
if (debugVariable && debugVariable instanceof DebugVariable) {
|
|
140
|
-
if (caseSensitiveLookup) {
|
|
141
|
-
if (debugVariable.name === key) {
|
|
142
|
-
return debugVariable;
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
if (debugVariable.name.toLowerCase() === key) {
|
|
146
|
-
return debugVariable;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
container = expressionContainers.next();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return undefined;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const context: InlineValueContext = {
|
|
157
|
-
frameId: stackFrame.raw.id,
|
|
158
|
-
stoppedLocation: range
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const cancellationToken = new CancellationTokenSource().token;
|
|
162
|
-
const registeredProviders = inlineValuesProvider.ordered(textEditorModel).reverse();
|
|
163
|
-
const visibleRanges = debugEditorModel.editor.getControl().getVisibleRanges();
|
|
164
|
-
|
|
165
|
-
const lineDecorations = new Map<number, InlineSegment[]>();
|
|
166
|
-
|
|
167
|
-
for (const provider of registeredProviders) {
|
|
168
|
-
for (const visibleRange of visibleRanges) {
|
|
169
|
-
const result = await provider.provideInlineValues(textEditorModel, visibleRange, context, cancellationToken);
|
|
170
|
-
if (result) {
|
|
171
|
-
for (const inlineValue of result) {
|
|
172
|
-
let text: string | undefined = undefined;
|
|
173
|
-
switch (inlineValue.type) {
|
|
174
|
-
case 'text':
|
|
175
|
-
text = inlineValue.text;
|
|
176
|
-
break;
|
|
177
|
-
case 'variable': {
|
|
178
|
-
let varName = inlineValue.variableName;
|
|
179
|
-
if (!varName) {
|
|
180
|
-
const lineContent = model.getLineContent(inlineValue.range.startLineNumber);
|
|
181
|
-
varName = lineContent.substring(inlineValue.range.startColumn - 1, inlineValue.range.endColumn - 1);
|
|
182
|
-
}
|
|
183
|
-
const variable = await findVariable(varName, inlineValue.caseSensitiveLookup);
|
|
184
|
-
if (variable) {
|
|
185
|
-
text = this.formatInlineValue(varName, variable.value);
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
case 'expression': {
|
|
190
|
-
let expr = inlineValue.expression;
|
|
191
|
-
if (!expr) {
|
|
192
|
-
const lineContent = model.getLineContent(inlineValue.range.startLineNumber);
|
|
193
|
-
expr = lineContent.substring(inlineValue.range.startColumn - 1, inlineValue.range.endColumn - 1);
|
|
194
|
-
}
|
|
195
|
-
if (expr) {
|
|
196
|
-
const expression = new ExpressionItem(expr, () => stackFrame.thread.session);
|
|
197
|
-
await expression.evaluate('watch');
|
|
198
|
-
if (expression.available) {
|
|
199
|
-
text = this.formatInlineValue(expr, expression.value);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (text) {
|
|
207
|
-
const line = inlineValue.range.startLineNumber;
|
|
208
|
-
let lineSegments = lineDecorations.get(line);
|
|
209
|
-
if (!lineSegments) {
|
|
210
|
-
lineSegments = [];
|
|
211
|
-
lineDecorations.set(line, lineSegments);
|
|
212
|
-
}
|
|
213
|
-
if (!lineSegments.some(segment => segment.text === text)) {
|
|
214
|
-
lineSegments.push(new InlineSegment(inlineValue.range.startColumn, text));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// sort line segments and concatenate them into a decoration
|
|
223
|
-
const separator = ', ';
|
|
224
|
-
lineDecorations.forEach((segments, line) => {
|
|
225
|
-
if (segments.length > 0) {
|
|
226
|
-
segments = segments.sort((a, b) => a.column - b.column);
|
|
227
|
-
const text = segments.map(s => s.text).join(separator);
|
|
228
|
-
decorations.push(this.createInlineValueDecoration(line, text));
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
} else { // use fallback if no provider was registered
|
|
233
|
-
const lineToNamesMap: Map<number, string[]> = new Map<number, string[]>();
|
|
234
|
-
const nameValueMap = new Map<string, string>();
|
|
235
|
-
for (const expr of expressions) {
|
|
236
|
-
if (expr instanceof DebugVariable) { // XXX: VS Code uses `IExpression` that has `name` and `value`.
|
|
237
|
-
nameValueMap.set(expr.name, expr.value);
|
|
238
|
-
}
|
|
239
|
-
// Limit the size of map. Too large can have a perf impact
|
|
240
|
-
if (nameValueMap.size >= MAX_NUM_INLINE_VALUES) {
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const wordToPositionsMap = this.getWordToPositionsMap(model);
|
|
246
|
-
|
|
247
|
-
// Compute unique set of names on each line
|
|
248
|
-
nameValueMap.forEach((_, name) => {
|
|
249
|
-
const positions = wordToPositionsMap.get(name);
|
|
250
|
-
if (positions) {
|
|
251
|
-
for (const position of positions) {
|
|
252
|
-
if (range.containsPosition(position)) {
|
|
253
|
-
if (!lineToNamesMap.has(position.lineNumber)) {
|
|
254
|
-
lineToNamesMap.set(position.lineNumber, []);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (lineToNamesMap.get(position.lineNumber)!.indexOf(name) === -1) {
|
|
258
|
-
lineToNamesMap.get(position.lineNumber)!.push(name);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// Compute decorators for each line
|
|
266
|
-
lineToNamesMap.forEach((names, line) => {
|
|
267
|
-
const contentText = names.sort((first, second) => {
|
|
268
|
-
const content = model.getLineContent(line);
|
|
269
|
-
return content.indexOf(first) - content.indexOf(second);
|
|
270
|
-
}).map(name => `${name} = ${nameValueMap.get(name)}`).join(', ');
|
|
271
|
-
decorations.push(this.createInlineValueDecoration(line, contentText));
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return decorations;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
protected formatInlineValue(...args: string[]): string {
|
|
279
|
-
const valuePattern = '{0} = {1}';
|
|
280
|
-
const formatRegExp = /{(\d+)}/g;
|
|
281
|
-
if (args.length === 0) {
|
|
282
|
-
return valuePattern;
|
|
283
|
-
}
|
|
284
|
-
return valuePattern.replace(formatRegExp, (match, group) => {
|
|
285
|
-
const idx = parseInt(group, 10);
|
|
286
|
-
return isNaN(idx) || idx < 0 || idx >= args.length ?
|
|
287
|
-
match :
|
|
288
|
-
args[idx];
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L454-L485
|
|
293
|
-
private createInlineValueDecoration(lineNumber: number, contentText: string): IDecorationOptions {
|
|
294
|
-
// If decoratorText is too long, trim and add ellipses. This could happen for minified files with everything on a single line
|
|
295
|
-
if (contentText.length > MAX_INLINE_DECORATOR_LENGTH) {
|
|
296
|
-
contentText = contentText.substring(0, MAX_INLINE_DECORATOR_LENGTH) + '...';
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return {
|
|
300
|
-
range: {
|
|
301
|
-
startLineNumber: lineNumber,
|
|
302
|
-
endLineNumber: lineNumber,
|
|
303
|
-
startColumn: MAX_SAFE_SMALL_INTEGER,
|
|
304
|
-
endColumn: MAX_SAFE_SMALL_INTEGER
|
|
305
|
-
},
|
|
306
|
-
renderOptions: {
|
|
307
|
-
after: {
|
|
308
|
-
contentText,
|
|
309
|
-
backgroundColor: 'rgba(255, 200, 0, 0.2)',
|
|
310
|
-
margin: '10px'
|
|
311
|
-
},
|
|
312
|
-
dark: {
|
|
313
|
-
after: {
|
|
314
|
-
color: 'rgba(255, 255, 255, 0.5)',
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
light: {
|
|
318
|
-
after: {
|
|
319
|
-
color: 'rgba(0, 0, 0, 0.5)',
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L487-L531
|
|
327
|
-
private getWordToPositionsMap(model: monaco.editor.ITextModel | ITextModel): Map<string, monaco.Position[]> {
|
|
328
|
-
model = model as ITextModel;
|
|
329
|
-
if (!this.wordToLineNumbersMap) {
|
|
330
|
-
this.wordToLineNumbersMap = new Map<string, monaco.Position[]>();
|
|
331
|
-
if (!model) {
|
|
332
|
-
return this.wordToLineNumbersMap;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// For every word in every line, map its ranges for fast lookup
|
|
336
|
-
for (let lineNumber = 1, len = model.getLineCount(); lineNumber <= len; ++lineNumber) {
|
|
337
|
-
const lineContent = model.getLineContent(lineNumber);
|
|
338
|
-
|
|
339
|
-
// If line is too long then skip the line
|
|
340
|
-
if (lineContent.length > MAX_TOKENIZATION_LINE_LEN) {
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
model.tokenization.forceTokenization(lineNumber);
|
|
345
|
-
const lineTokens = model.tokenization.getLineTokens(lineNumber);
|
|
346
|
-
for (let tokenIndex = 0, tokenCount = lineTokens.getCount(); tokenIndex < tokenCount; tokenIndex++) {
|
|
347
|
-
const tokenStartOffset = lineTokens.getStartOffset(tokenIndex);
|
|
348
|
-
const tokenEndOffset = lineTokens.getEndOffset(tokenIndex);
|
|
349
|
-
const tokenType = lineTokens.getStandardTokenType(tokenIndex);
|
|
350
|
-
const tokenStr = lineContent.substring(tokenStartOffset, tokenEndOffset);
|
|
351
|
-
|
|
352
|
-
// Token is a word and not a comment
|
|
353
|
-
if (tokenType === StandardTokenType.Other) {
|
|
354
|
-
DEFAULT_WORD_REGEXP.lastIndex = 0; // We assume tokens will usually map 1:1 to words if they match
|
|
355
|
-
const wordMatch = DEFAULT_WORD_REGEXP.exec(tokenStr);
|
|
356
|
-
|
|
357
|
-
if (wordMatch) {
|
|
358
|
-
const word = wordMatch[0];
|
|
359
|
-
if (!this.wordToLineNumbersMap.has(word)) {
|
|
360
|
-
this.wordToLineNumbersMap.set(word, []);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
this.wordToLineNumbersMap.get(word)!.push(new monaco.Position(lineNumber, tokenStartOffset));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return this.wordToLineNumbersMap;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 TypeFox 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
|
+
/*---------------------------------------------------------------------------------------------
|
|
18
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
20
|
+
*--------------------------------------------------------------------------------------------*/
|
|
21
|
+
// Based on https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts
|
|
22
|
+
|
|
23
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application-contribution';
|
|
24
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
25
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
26
|
+
import { CancellationTokenSource } from '@theia/monaco-editor-core/esm/vs/base/common/cancellation';
|
|
27
|
+
import { DEFAULT_WORD_REGEXP } from '@theia/monaco-editor-core/esm/vs/editor/common/core/wordHelper';
|
|
28
|
+
import { IDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon';
|
|
29
|
+
import { StandardTokenType } from '@theia/monaco-editor-core/esm/vs/editor/common/encodedTokenAttributes';
|
|
30
|
+
import { InlineValueContext } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
|
|
31
|
+
import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
|
|
32
|
+
import { ILanguageFeaturesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/languageFeatures';
|
|
33
|
+
import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
|
|
34
|
+
import { DebugVariable, ExpressionContainer, ExpressionItem } from '../console/debug-console-items';
|
|
35
|
+
import { DebugPreferences } from '../debug-preferences';
|
|
36
|
+
import { DebugStackFrame } from '../model/debug-stack-frame';
|
|
37
|
+
import { DebugEditorModel } from './debug-editor-model';
|
|
38
|
+
import { ICodeEditorService } from '@theia/monaco-editor-core/esm/vs/editor/browser/services/codeEditorService';
|
|
39
|
+
|
|
40
|
+
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L40-L43
|
|
41
|
+
export const INLINE_VALUE_DECORATION_KEY = 'inlinevaluedecoration';
|
|
42
|
+
const MAX_NUM_INLINE_VALUES = 100; // JS Global scope can have 700+ entries. We want to limit ourselves for perf reasons
|
|
43
|
+
const MAX_INLINE_DECORATOR_LENGTH = 150; // Max string length of each inline decorator when debugging. If exceeded ... is added
|
|
44
|
+
const MAX_TOKENIZATION_LINE_LEN = 500; // If line is too long, then inline values for the line are skipped
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* MAX SMI (SMall Integer) as defined in v8.
|
|
48
|
+
* one bit is lost for boxing/unboxing flag.
|
|
49
|
+
* one bit is lost for sign flag.
|
|
50
|
+
* See https://thibaultlaurens.github.io/javascript/2013/04/29/how-the-v8-engine-works/#tagged-values
|
|
51
|
+
*/
|
|
52
|
+
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/base/common/uint.ts#L7-L13
|
|
53
|
+
const MAX_SAFE_SMALL_INTEGER = 1 << 30;
|
|
54
|
+
|
|
55
|
+
class InlineSegment {
|
|
56
|
+
constructor(public column: number, public text: string) {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@injectable()
|
|
61
|
+
export class DebugInlineValueDecorator implements FrontendApplicationContribution {
|
|
62
|
+
@inject(DebugPreferences)
|
|
63
|
+
protected readonly preferences: DebugPreferences;
|
|
64
|
+
|
|
65
|
+
protected enabled = false;
|
|
66
|
+
protected wordToLineNumbersMap: Map<string, monaco.Position[]> | undefined = new Map();
|
|
67
|
+
|
|
68
|
+
onStart(): void {
|
|
69
|
+
StandaloneServices.get(ICodeEditorService).registerDecorationType('Inline debug decorations', INLINE_VALUE_DECORATION_KEY, {});
|
|
70
|
+
this.enabled = !!this.preferences['debug.inlineValues'];
|
|
71
|
+
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
|
|
72
|
+
if (preferenceName === 'debug.inlineValues' && !!newValue !== this.enabled) {
|
|
73
|
+
this.enabled = !!newValue;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async calculateDecorations(debugEditorModel: DebugEditorModel, stackFrame: DebugStackFrame | undefined): Promise<IDecorationOptions[]> {
|
|
79
|
+
this.wordToLineNumbersMap = undefined;
|
|
80
|
+
const model = debugEditorModel.editor.getControl().getModel() || undefined;
|
|
81
|
+
return this.updateInlineValueDecorations(debugEditorModel, model, stackFrame);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L382-L408
|
|
85
|
+
protected async updateInlineValueDecorations(
|
|
86
|
+
debugEditorModel: DebugEditorModel,
|
|
87
|
+
model: monaco.editor.ITextModel | undefined,
|
|
88
|
+
stackFrame: DebugStackFrame | undefined): Promise<IDecorationOptions[]> {
|
|
89
|
+
|
|
90
|
+
if (!this.enabled || !model || !stackFrame || !stackFrame.source || model.uri.toString() !== stackFrame.source.uri.toString()) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// XXX: Here is a difference between the VS Code's `IStackFrame` and the `DebugProtocol.StackFrame`.
|
|
95
|
+
// In DAP, `source` is optional, hence `range` is optional too.
|
|
96
|
+
const { range: stackFrameRange } = stackFrame;
|
|
97
|
+
if (!stackFrameRange) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const scopes = await stackFrame.getMostSpecificScopes(stackFrameRange);
|
|
102
|
+
// Get all top level children in the scope chain
|
|
103
|
+
const decorationsPerScope = await Promise.all(scopes.map(async scope => {
|
|
104
|
+
const children = Array.from(await scope.getElements());
|
|
105
|
+
let range = new monaco.Range(0, 0, stackFrameRange.startLineNumber, stackFrameRange.startColumn);
|
|
106
|
+
if (scope.range) {
|
|
107
|
+
range = range.setStartPosition(scope.range.startLineNumber, scope.range.startColumn);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this.createInlineValueDecorationsInsideRange(children, range, model, debugEditorModel, stackFrame);
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
return decorationsPerScope.reduce((previous, current) => previous.concat(current), []);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L410-L452
|
|
117
|
+
private async createInlineValueDecorationsInsideRange(
|
|
118
|
+
expressions: ReadonlyArray<ExpressionContainer>,
|
|
119
|
+
range: monaco.Range,
|
|
120
|
+
model: monaco.editor.ITextModel,
|
|
121
|
+
debugEditorModel: DebugEditorModel,
|
|
122
|
+
stackFrame: DebugStackFrame): Promise<IDecorationOptions[]> {
|
|
123
|
+
|
|
124
|
+
const decorations: IDecorationOptions[] = [];
|
|
125
|
+
|
|
126
|
+
const inlineValuesProvider = StandaloneServices.get(ILanguageFeaturesService).inlineValuesProvider;
|
|
127
|
+
const textEditorModel = debugEditorModel.editor.document.textEditorModel;
|
|
128
|
+
|
|
129
|
+
if (inlineValuesProvider && inlineValuesProvider.has(textEditorModel)) {
|
|
130
|
+
|
|
131
|
+
const findVariable = async (variableName: string, caseSensitiveLookup: boolean): Promise<DebugVariable | undefined> => {
|
|
132
|
+
const scopes = await stackFrame.getMostSpecificScopes(stackFrame.range!);
|
|
133
|
+
const key = caseSensitiveLookup ? variableName : variableName.toLowerCase();
|
|
134
|
+
for (const scope of scopes) {
|
|
135
|
+
const expressionContainers = await scope.getElements();
|
|
136
|
+
let container = expressionContainers.next();
|
|
137
|
+
while (!container.done) {
|
|
138
|
+
const debugVariable = container.value;
|
|
139
|
+
if (debugVariable && debugVariable instanceof DebugVariable) {
|
|
140
|
+
if (caseSensitiveLookup) {
|
|
141
|
+
if (debugVariable.name === key) {
|
|
142
|
+
return debugVariable;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
if (debugVariable.name.toLowerCase() === key) {
|
|
146
|
+
return debugVariable;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
container = expressionContainers.next();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const context: InlineValueContext = {
|
|
157
|
+
frameId: stackFrame.raw.id,
|
|
158
|
+
stoppedLocation: range
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const cancellationToken = new CancellationTokenSource().token;
|
|
162
|
+
const registeredProviders = inlineValuesProvider.ordered(textEditorModel).reverse();
|
|
163
|
+
const visibleRanges = debugEditorModel.editor.getControl().getVisibleRanges();
|
|
164
|
+
|
|
165
|
+
const lineDecorations = new Map<number, InlineSegment[]>();
|
|
166
|
+
|
|
167
|
+
for (const provider of registeredProviders) {
|
|
168
|
+
for (const visibleRange of visibleRanges) {
|
|
169
|
+
const result = await provider.provideInlineValues(textEditorModel, visibleRange, context, cancellationToken);
|
|
170
|
+
if (result) {
|
|
171
|
+
for (const inlineValue of result) {
|
|
172
|
+
let text: string | undefined = undefined;
|
|
173
|
+
switch (inlineValue.type) {
|
|
174
|
+
case 'text':
|
|
175
|
+
text = inlineValue.text;
|
|
176
|
+
break;
|
|
177
|
+
case 'variable': {
|
|
178
|
+
let varName = inlineValue.variableName;
|
|
179
|
+
if (!varName) {
|
|
180
|
+
const lineContent = model.getLineContent(inlineValue.range.startLineNumber);
|
|
181
|
+
varName = lineContent.substring(inlineValue.range.startColumn - 1, inlineValue.range.endColumn - 1);
|
|
182
|
+
}
|
|
183
|
+
const variable = await findVariable(varName, inlineValue.caseSensitiveLookup);
|
|
184
|
+
if (variable) {
|
|
185
|
+
text = this.formatInlineValue(varName, variable.value);
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case 'expression': {
|
|
190
|
+
let expr = inlineValue.expression;
|
|
191
|
+
if (!expr) {
|
|
192
|
+
const lineContent = model.getLineContent(inlineValue.range.startLineNumber);
|
|
193
|
+
expr = lineContent.substring(inlineValue.range.startColumn - 1, inlineValue.range.endColumn - 1);
|
|
194
|
+
}
|
|
195
|
+
if (expr) {
|
|
196
|
+
const expression = new ExpressionItem(expr, () => stackFrame.thread.session);
|
|
197
|
+
await expression.evaluate('watch');
|
|
198
|
+
if (expression.available) {
|
|
199
|
+
text = this.formatInlineValue(expr, expression.value);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (text) {
|
|
207
|
+
const line = inlineValue.range.startLineNumber;
|
|
208
|
+
let lineSegments = lineDecorations.get(line);
|
|
209
|
+
if (!lineSegments) {
|
|
210
|
+
lineSegments = [];
|
|
211
|
+
lineDecorations.set(line, lineSegments);
|
|
212
|
+
}
|
|
213
|
+
if (!lineSegments.some(segment => segment.text === text)) {
|
|
214
|
+
lineSegments.push(new InlineSegment(inlineValue.range.startColumn, text));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// sort line segments and concatenate them into a decoration
|
|
223
|
+
const separator = ', ';
|
|
224
|
+
lineDecorations.forEach((segments, line) => {
|
|
225
|
+
if (segments.length > 0) {
|
|
226
|
+
segments = segments.sort((a, b) => a.column - b.column);
|
|
227
|
+
const text = segments.map(s => s.text).join(separator);
|
|
228
|
+
decorations.push(this.createInlineValueDecoration(line, text));
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
} else { // use fallback if no provider was registered
|
|
233
|
+
const lineToNamesMap: Map<number, string[]> = new Map<number, string[]>();
|
|
234
|
+
const nameValueMap = new Map<string, string>();
|
|
235
|
+
for (const expr of expressions) {
|
|
236
|
+
if (expr instanceof DebugVariable) { // XXX: VS Code uses `IExpression` that has `name` and `value`.
|
|
237
|
+
nameValueMap.set(expr.name, expr.value);
|
|
238
|
+
}
|
|
239
|
+
// Limit the size of map. Too large can have a perf impact
|
|
240
|
+
if (nameValueMap.size >= MAX_NUM_INLINE_VALUES) {
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const wordToPositionsMap = this.getWordToPositionsMap(model);
|
|
246
|
+
|
|
247
|
+
// Compute unique set of names on each line
|
|
248
|
+
nameValueMap.forEach((_, name) => {
|
|
249
|
+
const positions = wordToPositionsMap.get(name);
|
|
250
|
+
if (positions) {
|
|
251
|
+
for (const position of positions) {
|
|
252
|
+
if (range.containsPosition(position)) {
|
|
253
|
+
if (!lineToNamesMap.has(position.lineNumber)) {
|
|
254
|
+
lineToNamesMap.set(position.lineNumber, []);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (lineToNamesMap.get(position.lineNumber)!.indexOf(name) === -1) {
|
|
258
|
+
lineToNamesMap.get(position.lineNumber)!.push(name);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Compute decorators for each line
|
|
266
|
+
lineToNamesMap.forEach((names, line) => {
|
|
267
|
+
const contentText = names.sort((first, second) => {
|
|
268
|
+
const content = model.getLineContent(line);
|
|
269
|
+
return content.indexOf(first) - content.indexOf(second);
|
|
270
|
+
}).map(name => `${name} = ${nameValueMap.get(name)}`).join(', ');
|
|
271
|
+
decorations.push(this.createInlineValueDecoration(line, contentText));
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return decorations;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
protected formatInlineValue(...args: string[]): string {
|
|
279
|
+
const valuePattern = '{0} = {1}';
|
|
280
|
+
const formatRegExp = /{(\d+)}/g;
|
|
281
|
+
if (args.length === 0) {
|
|
282
|
+
return valuePattern;
|
|
283
|
+
}
|
|
284
|
+
return valuePattern.replace(formatRegExp, (match, group) => {
|
|
285
|
+
const idx = parseInt(group, 10);
|
|
286
|
+
return isNaN(idx) || idx < 0 || idx >= args.length ?
|
|
287
|
+
match :
|
|
288
|
+
args[idx];
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L454-L485
|
|
293
|
+
private createInlineValueDecoration(lineNumber: number, contentText: string): IDecorationOptions {
|
|
294
|
+
// If decoratorText is too long, trim and add ellipses. This could happen for minified files with everything on a single line
|
|
295
|
+
if (contentText.length > MAX_INLINE_DECORATOR_LENGTH) {
|
|
296
|
+
contentText = contentText.substring(0, MAX_INLINE_DECORATOR_LENGTH) + '...';
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
range: {
|
|
301
|
+
startLineNumber: lineNumber,
|
|
302
|
+
endLineNumber: lineNumber,
|
|
303
|
+
startColumn: MAX_SAFE_SMALL_INTEGER,
|
|
304
|
+
endColumn: MAX_SAFE_SMALL_INTEGER
|
|
305
|
+
},
|
|
306
|
+
renderOptions: {
|
|
307
|
+
after: {
|
|
308
|
+
contentText,
|
|
309
|
+
backgroundColor: 'rgba(255, 200, 0, 0.2)',
|
|
310
|
+
margin: '10px'
|
|
311
|
+
},
|
|
312
|
+
dark: {
|
|
313
|
+
after: {
|
|
314
|
+
color: 'rgba(255, 255, 255, 0.5)',
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
light: {
|
|
318
|
+
after: {
|
|
319
|
+
color: 'rgba(0, 0, 0, 0.5)',
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts#L487-L531
|
|
327
|
+
private getWordToPositionsMap(model: monaco.editor.ITextModel | ITextModel): Map<string, monaco.Position[]> {
|
|
328
|
+
model = model as ITextModel;
|
|
329
|
+
if (!this.wordToLineNumbersMap) {
|
|
330
|
+
this.wordToLineNumbersMap = new Map<string, monaco.Position[]>();
|
|
331
|
+
if (!model) {
|
|
332
|
+
return this.wordToLineNumbersMap;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// For every word in every line, map its ranges for fast lookup
|
|
336
|
+
for (let lineNumber = 1, len = model.getLineCount(); lineNumber <= len; ++lineNumber) {
|
|
337
|
+
const lineContent = model.getLineContent(lineNumber);
|
|
338
|
+
|
|
339
|
+
// If line is too long then skip the line
|
|
340
|
+
if (lineContent.length > MAX_TOKENIZATION_LINE_LEN) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
model.tokenization.forceTokenization(lineNumber);
|
|
345
|
+
const lineTokens = model.tokenization.getLineTokens(lineNumber);
|
|
346
|
+
for (let tokenIndex = 0, tokenCount = lineTokens.getCount(); tokenIndex < tokenCount; tokenIndex++) {
|
|
347
|
+
const tokenStartOffset = lineTokens.getStartOffset(tokenIndex);
|
|
348
|
+
const tokenEndOffset = lineTokens.getEndOffset(tokenIndex);
|
|
349
|
+
const tokenType = lineTokens.getStandardTokenType(tokenIndex);
|
|
350
|
+
const tokenStr = lineContent.substring(tokenStartOffset, tokenEndOffset);
|
|
351
|
+
|
|
352
|
+
// Token is a word and not a comment
|
|
353
|
+
if (tokenType === StandardTokenType.Other) {
|
|
354
|
+
DEFAULT_WORD_REGEXP.lastIndex = 0; // We assume tokens will usually map 1:1 to words if they match
|
|
355
|
+
const wordMatch = DEFAULT_WORD_REGEXP.exec(tokenStr);
|
|
356
|
+
|
|
357
|
+
if (wordMatch) {
|
|
358
|
+
const word = wordMatch[0];
|
|
359
|
+
if (!this.wordToLineNumbersMap.has(word)) {
|
|
360
|
+
this.wordToLineNumbersMap.set(word, []);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
this.wordToLineNumbersMap.get(word)!.push(new monaco.Position(lineNumber, tokenStartOffset));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return this.wordToLineNumbersMap;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
}
|