Skip to content

Commit

Permalink
Merge pull request #163 from kaitai-io/webide-repr-on-imported
Browse files Browse the repository at this point in the history
Fix -webide-representation on imported types
  • Loading branch information
generalmimon authored Jan 21, 2024
2 parents 7dc1e11 + dd2d0ce commit 92ee05b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/v1/KaitaiServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class SchemaUtils {
}

class JsImporter implements IYamlImporter {
rootFsItem: IFsItem;
constructor(private rootFsItem: IFsItem, private ksyTypes: IKsyTypes) {
}

async importYaml(name: string, mode: string) {
var loadFn;
Expand Down Expand Up @@ -78,7 +79,11 @@ class JsImporter implements IYamlImporter {
throw error;
}
const ksyModel = <KsySchema.IKsyFile>YAML.parse(<string>ksyContent);
return ksyModel;
Object.assign(this.ksyTypes, SchemaUtils.collectKsyTypes(ksyModel));

// we have to modify the schema (add typesByJsName for example) before sending into the compiler, so we need a copy
const compilerSchema = <KsySchema.IKsyFile>YAML.parse(<string>ksyContent);
return compilerSchema;
}
}

Expand All @@ -87,25 +92,25 @@ export class CompilationError {
}

export class CompilerService {
jsImporter = new JsImporter();
jsImporter: JsImporter;
ksySchema: KsySchema.IKsyFile;
ksyTypes: IKsyTypes;

compile(srcYamlFsItem: IFsItem, srcYaml: string, kslang: string, debug: true | false | "both"): Promise<any> {
var perfYamlParse = performanceHelper.measureAction("YAML parsing");

this.jsImporter.rootFsItem = srcYamlFsItem;

try {
this.ksySchema = <KsySchema.IKsyFile>YAML.parse(srcYaml);
this.ksyTypes = SchemaUtils.collectKsyTypes(this.ksySchema);

// we have to modify the schema (add typesByJsName for example) before sending into the compiler so we need a copy
// we have to modify the schema (add typesByJsName for example) before sending into the compiler, so we need a copy
var compilerSchema = <KsySchema.IKsyFile>YAML.parse(srcYaml);
} catch (parseErr) {
return Promise.reject(new CompilationError("yaml", parseErr));
}

this.jsImporter = new JsImporter(srcYamlFsItem, this.ksyTypes);

perfYamlParse.done();

//console.log("ksySchema", ksySchema);
Expand Down

0 comments on commit 92ee05b

Please sign in to comment.