Improves error messages and uses repl mode by default.

This commit is contained in:
Henning Dieterichs
2020-05-13 18:20:54 +02:00
parent 410e5d3048
commit b65ba5fdbe
2 changed files with 17 additions and 7 deletions

View File

@@ -51,6 +51,7 @@ export class GenericEvaluator implements Evaluator {
message: {
kind: "list",
items: [
"An error occurred while evaluating the expression:",
error.message,
`Used debug adapter: ${this.session.session.configuration.type}`,
{
@@ -65,7 +66,9 @@ export class GenericEvaluator implements Evaluator {
};
}
return parseEvaluationResultFromGenericDebugAdapter(reply.result);
return parseEvaluationResultFromGenericDebugAdapter(reply.result, {
debugAdapterType: this.session.session.configuration.type,
});
}
protected getFinalExpression(args: {
@@ -76,6 +79,7 @@ export class GenericEvaluator implements Evaluator {
}
protected getContext(): "watch" | "repl" {
return "watch";
// we will use "repl" as default so that results are not truncated.
return "repl";
}
}

View File

@@ -4,8 +4,13 @@ import {
} from "@hediet/debug-visualizer-data-extraction";
import { FormattedMessage } from "../../contract";
export interface ParseEvaluationResultContext {
debugAdapterType: string;
}
export function parseEvaluationResultFromGenericDebugAdapter(
resultText: string
resultText: string,
context: ParseEvaluationResultContext
):
| { kind: "data"; result: DataExtractionResult }
| { kind: "error"; message: FormattedMessage } {
@@ -26,12 +31,12 @@ export function parseEvaluationResultFromGenericDebugAdapter(
// Just in case no quoting is done.
jsonData2 = jsonData;
}
resultObj = parseJson(jsonData2);
resultObj = parseJson(jsonData2, context);
} catch (e) {
// in case of C++: `"{ \"kind\": { ... }, \"text\": \"some\\ntext\" }"`
const str = parseJson(jsonData);
const str = parseJson(jsonData, context);
// str is now `{ "kind": { ... }, "text": "some\ntext" }"`
resultObj = parseJson(str);
resultObj = parseJson(str, context);
// result is now { kind: { ... }, text: "some\ntext" }
}
@@ -85,7 +90,7 @@ function isEnclosedWith(str: string, char: string): boolean {
return str.startsWith(char) && str.endsWith(char);
}
function parseJson(str: string) {
function parseJson(str: string, context: ParseEvaluationResultContext) {
try {
return JSON.parse(str);
} catch (error) {
@@ -104,6 +109,7 @@ function parseJson(str: string) {
},
],
},
`Used debug adapter: ${context.debugAdapterType}`,
],
});
}