From bf061d81a5be1c7e3bf007ad8de96b2a44f73e0c Mon Sep 17 00:00:00 2001 From: Patrick Quist Date: Thu, 26 May 2022 13:50:24 +0200 Subject: [PATCH] urls werent being expanded in tree/ide mode (#3711) * urls werent being expanded in tree/ide mode * also expand mainsource --- static/panes/compiler.js | 50 +++++++++++++++++++++++++-------------- static/panes/executor.js | 51 ++++++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/static/panes/compiler.js b/static/panes/compiler.js index 1d5dad767df..359d81663c0 100644 --- a/static/panes/compiler.js +++ b/static/panes/compiler.js @@ -973,33 +973,49 @@ Compiler.prototype.compileFromTree = function (options, bypassCache) { return; } - var mainsource = tree.multifileService.getMainSource(); - var request = { - source: mainsource, + source: tree.multifileService.getMainSource(), compiler: this.compiler ? this.compiler.id : '', options: options, lang: this.currentLangId, files: tree.multifileService.getFiles(), }; - var treeState = tree.currentState(); - var cmakeProject = tree.multifileService.isACMakeProject(); + const fetches = []; - if (bypassCache) request.bypassCache = true; - if (!this.compiler) { - this.onCompileResponse(request, errorResult(''), false); - } else if (cmakeProject && request.source === '') { - this.onCompileResponse(request, errorResult(''), false); - } else { - if (cmakeProject) { - request.options.compilerOptions.cmakeArgs = treeState.cmakeArgs; - request.options.compilerOptions.customOutputFilename = treeState.customOutputFilename; - this.sendCMakeCompile(request); + fetches.push( + this.compilerService.expand(request.source).then(contents => { + request.source = contents; + }) + ); + + for (let file of request.files) { + fetches.push( + this.compilerService.expand(file.contents).then(contents => { + file.contents = contents; + }) + ); + } + + Promise.all(fetches).then(() => { + var treeState = tree.currentState(); + var cmakeProject = tree.multifileService.isACMakeProject(); + + if (bypassCache) request.bypassCache = true; + if (!this.compiler) { + this.onCompileResponse(request, errorResult(''), false); + } else if (cmakeProject && request.source === '') { + this.onCompileResponse(request, errorResult(''), false); } else { - this.sendCompile(request); + if (cmakeProject) { + request.options.compilerOptions.cmakeArgs = treeState.cmakeArgs; + request.options.compilerOptions.customOutputFilename = treeState.customOutputFilename; + this.sendCMakeCompile(request); + } else { + this.sendCompile(request); + } } - } + }); }; Compiler.prototype.compileFromEditorSource = function (options, bypassCache) { diff --git a/static/panes/executor.js b/static/panes/executor.js index c053bc272d5..5b4f1a57bc0 100644 --- a/static/panes/executor.js +++ b/static/panes/executor.js @@ -25,6 +25,7 @@ 'use strict'; var $ = require('jquery'); var _ = require('underscore'); +var Promise = require('es6-promise').Promise; var ga = require('../analytics').ga; var Toggles = require('../widgets/toggles').Toggles; var FontScale = require('../widgets/fontscale').FontScale; @@ -251,33 +252,49 @@ Executor.prototype.compileFromTree = function (options, bypassCache) { return; } - var mainsource = tree.multifileService.getMainSource(); - var request = { - source: mainsource, + source: tree.multifileService.getMainSource(), compiler: this.compiler ? this.compiler.id : '', options: options, lang: this.currentLangId, files: tree.multifileService.getFiles(), }; - var treeState = tree.currentState(); - var cmakeProject = tree.multifileService.isACMakeProject(); + const fetches = []; - if (bypassCache) request.bypassCache = true; - if (!this.compiler) { - this.onCompileResponse(request, errorResult(''), false); - } else if (cmakeProject && request.source === '') { - this.onCompileResponse(request, errorResult(''), false); - } else { - if (cmakeProject) { - request.options.compilerOptions.cmakeArgs = treeState.cmakeArgs; - request.options.compilerOptions.customOutputFilename = treeState.customOutputFilename; - this.sendCMakeCompile(request); + fetches.push( + this.compilerService.expand(request.source).then(contents => { + request.source = contents; + }) + ); + + for (let file of request.files) { + fetches.push( + this.compilerService.expand(file.contents).then(contents => { + file.contents = contents; + }) + ); + } + + Promise.all(fetches).then(() => { + var treeState = tree.currentState(); + var cmakeProject = tree.multifileService.isACMakeProject(); + + if (bypassCache) request.bypassCache = true; + if (!this.compiler) { + this.onCompileResponse(request, errorResult(''), false); + } else if (cmakeProject && request.source === '') { + this.onCompileResponse(request, errorResult(''), false); } else { - this.sendCompile(request); + if (cmakeProject) { + request.options.compilerOptions.cmakeArgs = treeState.cmakeArgs; + request.options.compilerOptions.customOutputFilename = treeState.customOutputFilename; + this.sendCMakeCompile(request); + } else { + this.sendCompile(request); + } } - } + }); }; Executor.prototype.sendCMakeCompile = function (request) {