Skip to content

Commit 50f5770

Browse files
committed
Add command to show evaluated run settings for the current file
Fixes #139
1 parent 7ffa63d commit 50f5770

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Support for opened files without active workspaces
66
- Icon to copy the text of the text boxes
77
- Icon to drag testcase to new positions to be able to re-order them
8+
- Command to show the evaluated run settings for the current file
89

910
### Changed
1011

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@
296296
"title": "Open runSettings.json",
297297
"category": "Fast Olympic Coding"
298298
},
299+
{
300+
"command": "fastolympiccoding.showEvaluatedRunSettings",
301+
"title": "Show Evaluated Run Settings",
302+
"category": "Fast Olympic Coding"
303+
},
299304
{
300305
"command": "fastolympiccoding.compile",
301306
"title": "Compile",

src/extension/runSettingsCommands.ts

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "node:fs/promises";
22
import * as path from "node:path";
33
import * as vscode from "vscode";
44

5-
import { deepMerge, getFileWorkspace } from "./utils/vscode";
5+
import { deepMerge, getFileRunSettings, getFileWorkspace } from "./utils/vscode";
66

77
const gdbAttachDebugConfig = {
88
debugCommand: [
@@ -384,6 +384,19 @@ function getActiveFileExtension(): string | null {
384384
return path.extname(activeEditor.document.fileName);
385385
}
386386

387+
function getTargetFilePath(uri?: vscode.Uri): string | undefined {
388+
if (uri?.scheme === "file") {
389+
return uri.fsPath;
390+
}
391+
392+
const activeEditor = vscode.window.activeTextEditor;
393+
if (activeEditor?.document.uri.scheme === "file") {
394+
return activeEditor.document.fileName;
395+
}
396+
397+
return undefined;
398+
}
399+
387400
export function registerRunSettingsCommands(context: vscode.ExtensionContext): void {
388401
context.subscriptions.push(
389402
vscode.commands.registerCommand(
@@ -578,4 +591,59 @@ export function registerRunSettingsCommands(context: vscode.ExtensionContext): v
578591
})();
579592
})
580593
);
594+
595+
context.subscriptions.push(
596+
vscode.commands.registerCommand(
597+
"fastolympiccoding.showEvaluatedRunSettings",
598+
async (uri?: vscode.Uri) => {
599+
let file = getTargetFilePath(uri);
600+
if (!file) {
601+
const selectedFile = await vscode.window.showOpenDialog({
602+
canSelectMany: false,
603+
canSelectFolders: false,
604+
canSelectFiles: true,
605+
openLabel: "Select file",
606+
});
607+
file = selectedFile?.at(0)?.fsPath;
608+
}
609+
610+
if (!file) {
611+
return;
612+
}
613+
614+
const runSettings = getFileRunSettings(file);
615+
if (!runSettings) {
616+
return;
617+
}
618+
619+
const extension = path.extname(file);
620+
const runSettingsRecord = runSettings as Record<string, unknown>;
621+
const extensionRunSettings = runSettingsRecord[extension];
622+
if (!extensionRunSettings) {
623+
await vscode.window.showErrorMessage(
624+
`No evaluated run settings found for extension \"${extension}\"`
625+
);
626+
return;
627+
}
628+
629+
const filteredRunSettings = Object.fromEntries(
630+
Object.entries(runSettingsRecord).filter(([key]) => {
631+
if (key === "languageSettings") {
632+
return false;
633+
}
634+
if (key === extension) {
635+
return true;
636+
}
637+
return !key.startsWith(".");
638+
})
639+
);
640+
641+
const document = await vscode.workspace.openTextDocument({
642+
language: "json",
643+
content: JSON.stringify(filteredRunSettings, undefined, 2),
644+
});
645+
await vscode.window.showTextDocument(document);
646+
}
647+
)
648+
);
581649
}

0 commit comments

Comments
 (0)