-
Notifications
You must be signed in to change notification settings - Fork 350
/
Copy pathJavaInlineValueProvider.ts
81 lines (70 loc) · 4.21 KB
/
JavaInlineValueProvider.ts
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { debug, InlineValue, InlineValueContext, InlineValueEvaluatableExpression, InlineValuesProvider, InlineValueText, InlineValueVariableLookup,
Range, TextDocument } 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";
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: codeConverter.asRange(viewPort),
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();
}
}