Skip to content

Commit

Permalink
🐛 allow running gams from within .lst files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispahm committed Oct 6, 2023
1 parent 296ff29 commit c1a8fac
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/gams-ide.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gams-ide.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/runGams.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const vscode = require("vscode");
const createGamsCommand = require("./utils/createGamsCommand.js");
const os = require("os");
const path = require("path");

async function openListing(listingPath) {
const doc = await vscode.workspace.openTextDocument(listingPath);
Expand All @@ -9,9 +10,12 @@ async function openListing(listingPath) {

module.exports = async function runGams(terminal, compileOnly = false, ignoreMultiFileEntryPoint = false) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId === "gams") {
const document = editor.document;
const gamsCommand = await createGamsCommand(document, ["lo=3", compileOnly ? "a=c" : ""], ignoreMultiFileEntryPoint);
if (editor && (editor.document.languageId === "gams" || editor.document.fileName.toLowerCase().endsWith('.lst'))) {
let fileToRun = editor.document.fileName;
if (editor.document.fileName.toLowerCase().endsWith('.lst')) {
fileToRun = path.format({ ...path.parse(fileToRun), base: '', ext: '.gms' })
}
const gamsCommand = await createGamsCommand(fileToRun, ["lo=3", compileOnly ? "a=c" : ""], ignoreMultiFileEntryPoint);
// if the terminal has been closed, create a new one
if (terminal.exitStatus !== undefined) {
terminal = vscode.window.createTerminal("GAMS");
Expand Down
8 changes: 4 additions & 4 deletions src/utils/createGamsCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const { resolve, basename, dirname, parse, sep, format, isAbsolute } = require('path');
const getGamsPath = require('./getGamsPath.js')

module.exports = async function createGamsCommand(document, extraArgs = [], ignoreMultiFileEntryPoint = false) {
module.exports = async function createGamsCommand(docFileName, extraArgs = [], ignoreMultiFileEntryPoint = false) {
// get the default settings, and define the variables
const defaultSettings = vscode.workspace.getConfiguration("gamsIde");
let gamsExecutable = await getGamsPath();
Expand All @@ -13,8 +13,8 @@ module.exports = async function createGamsCommand(document, extraArgs = [], igno
let commandLineArguments = defaultSettings.get(
"commandLineArguments_execution"
) || [];
let fileName = basename(document.fileName);
let filePath = dirname(document.fileName);
let fileName = basename(docFileName);
let filePath = dirname(docFileName);

// if the scratch directory is not specified, we use
// this extension's scratch directory
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = async function createGamsCommand(document, extraArgs = [], igno
}
}

let gamsFileToExecute = document.fileName;
let gamsFileToExecute = docFileName;
if (multiFileEntryPointFile && !ignoreMultiFileEntryPoint) {
gamsFileToExecute = multiFileEntryPointFile;
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/createGamsCompileCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { resolve, basename, dirname, parse, sep, isAbsolute } = require('path');
const fs = require("fs");
const getGamsPath = require('./getGamsPath.js')

module.exports = async function createGamsCommand(document, extraArgs = []) {
module.exports = async function createGamsCommand(docFileName, extraArgs = []) {
// get the default settings, and define the variables
const defaultSettings = vscode.workspace.getConfiguration("gamsIde");
let gamsExecutable = await getGamsPath();
Expand All @@ -13,8 +13,8 @@ module.exports = async function createGamsCommand(document, extraArgs = []) {
let commandLineArguments = defaultSettings.get(
"commandLineArguments_compilation"
) || [];
let fileName = basename(document.fileName);
let filePath = dirname(document.fileName);
let fileName = basename(docFileName);
let filePath = dirname(docFileName);

// if the scratch directory is not specified, we use
// this extension's scratch directory
Expand Down Expand Up @@ -102,7 +102,7 @@ module.exports = async function createGamsCommand(document, extraArgs = []) {
}
}

let gamsFileToExecute = document.fileName;
let gamsFileToExecute = docFileName;

if (multiFileEntryPointFile) {
gamsFileToExecute = multiFileEntryPointFile;
Expand Down

0 comments on commit c1a8fac

Please sign in to comment.