@@ -2,7 +2,7 @@ import * as fs from "node:fs/promises";
22import * as path from "node:path" ;
33import * as vscode from "vscode" ;
44
5- import { deepMerge , getFileWorkspace } from "./utils/vscode" ;
5+ import { deepMerge , getFileRunSettings , getFileWorkspace } from "./utils/vscode" ;
66
77const 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+
387400export 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