Skip to content

Commit 7926965

Browse files
committed
async for notifyUpdateSourceRefs
1 parent a82a935 commit 7926965

1 file changed

Lines changed: 58 additions & 46 deletions

File tree

src/EIDEProject.ts

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,64 +2669,76 @@ class EIDEProject extends AbstractProject {
26692669

26702670
private srcRefMap: Map<string, File[]> = new Map();
26712671

2672-
public async notifyUpdateSourceRefs(toolchain_: ToolchainName | undefined) {
2672+
public async notifyUpdateSourceRefs(toolchain_: ToolchainName | undefined): Promise<boolean> {
26732673

2674-
/* clear old */
2675-
this.srcRefMap.clear();
2674+
return new Promise((resolve) => {
26762675

2677-
/* check source references is enabled ? */
2678-
if (!SettingManager.GetInstance().isDisplaySourceRefs()) return;
2676+
/* clear old */
2677+
this.srcRefMap.clear();
26792678

2680-
let compiler_cmd_db: CompilerCommandsDatabaseItem[] = [];
2681-
let generate_dep_file: ((cmd_db: CompilerCommandsDatabaseItem[], srcpath: string, deppath: string) => void) | undefined;
2679+
/* check source references is enabled ? */
2680+
if (!SettingManager.GetInstance().isDisplaySourceRefs()) {
2681+
resolve(false);
2682+
return; /* no refs list file, exit */
2683+
}
26822684

2683-
// for COSMIC STM8, we need manual generate .d files
2684-
if (this.getToolchain().name == 'COSMIC_STM8') {
2685-
const compilerDBFile = File.fromArray([this.getOutputFolder().path, 'compile_commands.json']);
2686-
if (compilerDBFile.IsFile()) {
2687-
try {
2688-
compiler_cmd_db = jsonc.parse(compilerDBFile.Read());
2689-
generate_dep_file = (cmd_db: CompilerCommandsDatabaseItem[], srcpath: string, deppath: string) => {
2690-
let idx = cmd_db.findIndex((e) => e.file == srcpath);
2691-
if (idx != -1) {
2692-
try {
2693-
let cmd_item = cmd_db[idx];
2694-
let command = cmd_item.command.replace('-co', '-sm -co');
2695-
const depcont = child_process.execSync(command, { cwd: cmd_item.directory }).toString();
2696-
fs.writeFileSync(deppath, depcont);
2697-
} catch (error) {
2698-
GlobalEvent.emit('globalLog', newMessage('Warning', `Failed to make '${deppath}', msg: ${(<Error>error).message}`));
2699-
try { fs.unlinkSync(deppath) } catch (error) { } // del old .d file
2685+
let compiler_cmd_db: CompilerCommandsDatabaseItem[] = [];
2686+
let generate_dep_file: ((cmd_db: CompilerCommandsDatabaseItem[], srcpath: string, deppath: string) => void) | undefined;
2687+
2688+
// for COSMIC STM8, we need manual generate .d files
2689+
if (this.getToolchain().name == 'COSMIC_STM8') {
2690+
const compilerDBFile = File.fromArray([this.getOutputFolder().path, 'compile_commands.json']);
2691+
if (compilerDBFile.IsFile()) {
2692+
try {
2693+
compiler_cmd_db = jsonc.parse(compilerDBFile.Read());
2694+
generate_dep_file = (cmd_db: CompilerCommandsDatabaseItem[], srcpath: string, deppath: string) => {
2695+
let idx = cmd_db.findIndex((e) => e.file == srcpath);
2696+
if (idx != -1) {
2697+
try {
2698+
let cmd_item = cmd_db[idx];
2699+
let command = cmd_item.command.replace('-co', '-sm -co');
2700+
const depcont = child_process.execSync(command, { cwd: cmd_item.directory }).toString();
2701+
fs.writeFileSync(deppath, depcont);
2702+
} catch (error) {
2703+
GlobalEvent.emit('globalLog', newMessage('Warning', `Failed to make '${deppath}', msg: ${(<Error>error).message}`));
2704+
try { fs.unlinkSync(deppath) } catch (error) { } // del old .d file
2705+
}
27002706
}
2701-
}
2702-
};
2703-
} catch (error) {
2704-
GlobalEvent.emit('globalLog', ExceptionToMessage(error, 'Warning'));
2707+
};
2708+
} catch (error) {
2709+
GlobalEvent.emit('globalLog', ExceptionToMessage(error, 'Warning'));
2710+
}
27052711
}
27062712
}
2707-
}
27082713

2709-
const toolName = toolchain_ || this.getToolchain().name;
2714+
const toolName = toolchain_ || this.getToolchain().name;
27102715

2711-
const outFolder = this.getOutputFolder();
2712-
const refListFile = File.fromArray([outFolder.path, 'ref.json']);
2713-
if (!refListFile.IsFile()) return; /* no refs list file, exit */
2716+
const outFolder = this.getOutputFolder();
2717+
const refListFile = File.fromArray([outFolder.path, 'ref.json']);
27142718

2715-
try {
2716-
const refMap = JSON.parse(refListFile.Read());
2717-
for (const srcpath in refMap) {
2718-
const refFile = new File((<string>refMap[srcpath]).replace(/\.[^\\\/\.]+$/, '.d'));
2719-
if (generate_dep_file) generate_dep_file(compiler_cmd_db, srcpath, refFile.path);
2720-
if (!refFile.IsFile()) continue;
2721-
const refs = this.parseRefFile(refFile, toolName).filter(p => p != srcpath);
2722-
this.srcRefMap.set(srcpath, refs.map((path) => new File(path)));
2719+
if (!refListFile.IsFile()) {
2720+
resolve(false);
2721+
return; /* no refs list file, exit */
27232722
}
2724-
} catch (error) {
2725-
GlobalEvent.emit('msg', ExceptionToMessage(error, 'Hidden'));
2726-
}
27272723

2728-
// notify update src view
2729-
this.emit('dataChanged', 'files');
2724+
try {
2725+
const refMap = JSON.parse(refListFile.Read());
2726+
for (const srcpath in refMap) {
2727+
const refFile = new File((<string>refMap[srcpath]).replace(/\.[^\\\/\.]+$/, '.d'));
2728+
if (generate_dep_file) generate_dep_file(compiler_cmd_db, srcpath, refFile.path);
2729+
if (!refFile.IsFile()) continue;
2730+
const refs = this.parseRefFile(refFile, toolName).filter(p => p != srcpath);
2731+
this.srcRefMap.set(srcpath, refs.map((path) => new File(path)));
2732+
}
2733+
} catch (error) {
2734+
GlobalEvent.emit('msg', ExceptionToMessage(error, 'Hidden'));
2735+
}
2736+
2737+
// notify update src view
2738+
this.emit('dataChanged', 'files');
2739+
2740+
resolve(true);
2741+
});
27302742
}
27312743

27322744
public getSourceRefs(file: File): File[] {

0 commit comments

Comments
 (0)