Skip to content

Commit de3d23c

Browse files
authored
Merge branch 'informaticup' into dependabot/github_actions/github-actions-e1d721b46e
2 parents 1faefbe + 5fdd7b4 commit de3d23c

File tree

7 files changed

+48
-15
lines changed

7 files changed

+48
-15
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "answer-set-programming-language-support",
33
"displayName": "Clingo for VSCode",
4-
"version": "1.0.6",
4+
"version": "1.0.8",
55
"description": "Language Support for Clingo ASP (developed at University of Potsdam).",
66
"publisher": "ffrankreiter",
77
"jest": {
@@ -162,19 +162,19 @@
162162
"command": "answer-set-programming-language-support.runinterminalall",
163163
"key": "ctrl+shift+a",
164164
"mac": "cmd+shift+a",
165-
"when": "editorTextFocus"
165+
"when": "editorTextFocus && editorLangId == 'asp'"
166166
},
167167
{
168168
"command": "answer-set-programming-language-support.runinterminalsingle",
169-
"key": "ctrl+shift+s",
170-
"mac": "cmd+shift+s",
171-
"when": "editorTextFocus"
169+
"key": "ctrl+shift+x",
170+
"mac": "cmd+shift+x",
171+
"when": "editorTextFocus && editorLangId == 'asp'"
172172
},
173173
{
174174
"command": "answer-set-programming-language-support.runinterminalconfig",
175175
"key": "ctrl+shift+c",
176176
"mac": "cmd+shift+c",
177-
"when": "editorTextFocus"
177+
"when": "editorTextFocus && editorLangId == 'asp'"
178178
}
179179
]
180180
},

sampleConfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"preProcessor": false,
2020
"models": 0,
21+
"constants": ["const1=value1", "const2=value2"],
2122
"customArgs": ""
2223
}
2324
}

schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": { "type": "string" },
77
"author": { "type": "string" },
88
"version": { "type": "string" },
9-
"additionalFile": { "type": "array" },
9+
"additionalFiles": { "type": "array" },
1010
"args": {
1111
"type": "object",
1212
"properties": {
@@ -26,6 +26,7 @@
2626
"timeLimit": { "type": "integer" },
2727
"preProcessor": { "type": "boolean" },
2828
"models": { "type": "integer" },
29+
"constants": { "type": "array" },
2930
"customArgs": { "type": "string" }
3031
}
3132
}

src/configReader.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function readConfig(setConfig, turnMessagesOff, contextAbsolutePath) {
2727
args.push(...readModels());
2828
args.push(...readCustomArgs());
2929
args.push(...readFiles());
30+
args.push(...readConstants());
3031

3132
if (!turnMessagesOff) {
3233
vscode.window.showInformationMessage(
@@ -42,6 +43,14 @@ function readConfig(setConfig, turnMessagesOff, contextAbsolutePath) {
4243
return args;
4344
}
4445

46+
function readConstants() {
47+
if (jsonConfig.args.constants != undefined) {
48+
return jsonConfig.args.constants.map((constant) => `--const ${constant}`);
49+
} else {
50+
return [];
51+
}
52+
}
53+
4554
/**
4655
* @param {string} contextAbsolutePath
4756
* @param {string} pathToConfig
@@ -127,8 +136,30 @@ function readModels() {
127136

128137
function readCustomArgs() {
129138
if (jsonConfig.args.customArgs != undefined) {
130-
return jsonConfig.args.customArgs.split(" ");
139+
const str = jsonConfig.args.customArgs;
140+
// split custom args into seperate tokens
141+
const tokens = str.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
142+
const result = [];
143+
// process tokens as possible pairs
144+
for (let i = 0; i < tokens.length; i++) {
145+
let token = tokens[i];
146+
if (token.startsWith("-") && i + 1 < tokens.length) {
147+
if (tokens[i + 1].startsWith("-")) {
148+
// next token is another flag, so current token is standalone
149+
result.push(token);
150+
continue;
151+
}
152+
let next = tokens[i + 1];
153+
result.push(`${token} ${next}`);
154+
i++;
155+
} else {
156+
// no possible pair remaining
157+
result.push(token);
158+
}
159+
}
160+
return result;
131161
} else {
162+
// no custom args
132163
return [];
133164
}
134165
}

src/extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function activate(context) {
8484
solve: result?.Time.Solve,
8585
model: result?.Time.Model,
8686
},
87-
answers: result?.Call.flatMap((call) => call.Witnesses.map((witness) => witness.Value.join(", "))),
87+
answers: result?.Call.flatMap((call) => call.Witnesses?.map((witness) => witness.Value.join(", "))),
8888
result: result?.Result,
8989
};
9090
}

src/runClingoWasmForFileWithProgress.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ async function runClingoWasmForFileWithProgress(vscode, progress, filePath, mode
2525

2626
fileContent = await fs.promises.readFile(filePath, "utf8");
2727

28-
const additionalFiles = options?.filter((arg) => arg && !arg.startsWith("--")).map((filePath) => filePath.replace(/"/g, ""));
28+
const additionalFiles = options?.filter((arg) => arg && !arg.startsWith("-")).map((filePath) => filePath.replace(/"/g, ""));
2929

3030
if (additionalFiles?.length) {
3131
for (const additionalFilePath of additionalFiles) {
3232
if (!fs.existsSync(additionalFilePath)) {
33-
vscode.window.showErrorMessage(`File not found: ${filePath}`);
33+
vscode.window.showErrorMessage(`File not found: ${additionalFilePath}`);
3434
return null;
3535
}
3636
const additionalContent = await fs.promises.readFile(additionalFilePath, "utf8");
@@ -41,7 +41,7 @@ async function runClingoWasmForFileWithProgress(vscode, progress, filePath, mode
4141
}
4242

4343
// Filter options for Clingo
44-
const clingoOptions = options?.filter((arg) => arg.startsWith("--"));
44+
const clingoOptions = options?.filter((arg) => arg.startsWith("-"));
4545

4646
progress.report({
4747
increment: 50,
@@ -57,7 +57,7 @@ async function runClingoWasmForFileWithProgress(vscode, progress, filePath, mode
5757
});
5858

5959
// Validate the result
60-
if (["ERROR", "UNSATISFIABLE", "UNKNOWN"].includes(wasmResult.Result)) {
60+
if (["ERROR", "UNKNOWN"].includes(wasmResult.Result)) {
6161
if ("Error" in wasmResult) {
6262
vscode.window.showErrorMessage(`Clingo WASM Error: ${wasmResult.Error}`);
6363
} else {

0 commit comments

Comments
 (0)