forked from microsoft/vscode-java-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaInlineValueProvider.ts
More file actions
86 lines (74 loc) · 4.57 KB
/
JavaInlineValueProvider.ts
File metadata and controls
86 lines (74 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as compareVersions from "compare-versions";
import { debug, InlineValue, InlineValueContext, InlineValueEvaluatableExpression, InlineValuesProvider, InlineValueText, InlineValueVariableLookup,
Range, TextDocument, version } from "vscode";
import { instrumentOperation, instrumentOperationStep, sendInfo } from "vscode-extension-telemetry-wrapper";
import * as CodeConverter from "vscode-languageclient/lib/codeConverter";
import * as ProtocolConverter from "vscode-languageclient/lib/protocolConverter";
import { InlineKind, InlineVariable, resolveInlineVariables } from "./languageServerPlugin";
// In VS Code 1.55.0, viewport doesn't change while scrolling the editor and it's fixed in 1.56.0.
// So dynamically enable viewport support based on the user's VS Code version.
const isViewPortSupported = compareVersions(version.replace(/-insider$/i, ""), "1.56.0") >= 0;
const protoConverter: ProtocolConverter.Converter = ProtocolConverter.createConverter();
const codeConverter: CodeConverter.Converter = CodeConverter.createConverter();
export class JavaInlineValuesProvider implements InlineValuesProvider {
public async provideInlineValues(document: TextDocument, viewPort: Range, context: InlineValueContext): Promise<InlineValue[]> {
const provideInlineValuesOperation = instrumentOperation("provideInlineValues", async (operationId) => {
const resolveInlineVariablesStep = instrumentOperationStep(operationId, "resolveInlineVariables", async () => {
return <InlineVariable[]> (await resolveInlineVariables({
uri: document.uri.toString(),
viewPort: isViewPortSupported ? codeConverter.asRange(viewPort) : undefined,
stoppedLocation: codeConverter.asRange(context.stoppedLocation),
}));
});
const variables: InlineVariable[] = await resolveInlineVariablesStep();
const resolveInlineValuesStep = instrumentOperationStep(operationId, "resolveInlineValues", async () => {
if (!variables || !variables.length) {
sendInfo(operationId, {
inlineVariableCount: 0,
});
return [];
}
const unresolvedVariables: any[] = variables.filter((variable) => variable.kind === InlineKind.Evaluation).map((variable) => {
return {
expression: variable.expression || variable.name,
declaringClass: variable.declaringClass,
};
});
sendInfo(operationId, {
inlineVariableCount: variables.length,
inlineVariableLookupCount: variables.length - unresolvedVariables.length,
inlineVariableEvaluationCount: unresolvedVariables.length,
});
let resolvedVariables: any;
if (unresolvedVariables.length && debug.activeDebugSession) {
const response = await debug.activeDebugSession.customRequest("inlineValues", {
frameId: context.frameId,
variables: unresolvedVariables,
});
resolvedVariables = response?.variables;
}
const result: InlineValue[] = [];
let next = 0;
for (const variable of variables) {
if (variable.kind === InlineKind.VariableLookup) {
result.push(new InlineValueVariableLookup(protoConverter.asRange(variable.range), variable.name, true));
} else if (resolvedVariables && resolvedVariables.length > next) {
const resolvedValue = resolvedVariables[next++];
if (resolvedValue) {
result.push(new InlineValueText(protoConverter.asRange(variable.range), `${variable.name} = ${resolvedValue.value}`));
} else {
result.push(new InlineValueEvaluatableExpression(protoConverter.asRange(variable.range), variable.name));
}
} else {
result.push(new InlineValueEvaluatableExpression(protoConverter.asRange(variable.range), variable.name));
}
}
return result;
});
return resolveInlineValuesStep();
});
return provideInlineValuesOperation();
}
}