Implements GenericDataExtractionProviderFactory. With this, the debug visualizer can be used with every language that can be debugged in VS Code.
This commit is contained in:
@@ -4,7 +4,9 @@ export type DataExtractionResult = {
|
||||
availableExtractors: DataExtractorInfo[];
|
||||
};
|
||||
|
||||
// Instances must be valid json values.
|
||||
/**
|
||||
* Instances must be valid json values.
|
||||
*/
|
||||
export type ExtractedData = {
|
||||
kind: Record<string, true>;
|
||||
};
|
||||
@@ -18,3 +20,16 @@ export type DataExtractorInfo = {
|
||||
export type DataExtractorId = {
|
||||
__brand: "DataExtractorId";
|
||||
} & string;
|
||||
|
||||
export function isExtractedData(val: unknown): val is ExtractedData {
|
||||
if (typeof val !== "object" || !val || !("kind" in val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const obj = val as any;
|
||||
if (typeof obj.kind !== "object" || !obj.kind) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Object.values(obj.kind).every(val => val === true);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ExtractedData } from "../../../DataExtractionResult";
|
||||
import { ExtractedData, isExtractedData } from "../../../DataExtractionResult";
|
||||
import {
|
||||
DataExtractor,
|
||||
ExtractionCollector,
|
||||
@@ -12,17 +12,7 @@ export class AsIsDataExtractor implements DataExtractor<ExtractedData> {
|
||||
extractionCollector: ExtractionCollector<ExtractedData>,
|
||||
context: DataExtractorContext
|
||||
): void {
|
||||
if (typeof data !== "object" || !data || !("kind" in data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const obj = data as any;
|
||||
if (typeof obj.kind !== "object" || !obj.kind) {
|
||||
return;
|
||||
}
|
||||
|
||||
const areAllTrue = Object.values(obj.kind).every(val => val === true);
|
||||
if (!areAllTrue) {
|
||||
if (!isExtractedData(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,7 +21,7 @@ export class AsIsDataExtractor implements DataExtractor<ExtractedData> {
|
||||
name: "As Is",
|
||||
priority: 500,
|
||||
extractData() {
|
||||
return obj;
|
||||
return data;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user