Ensure infoset file extension match output format.
- Done by checking if the filepath does not end with the proper file extension. If it doesn't then:
- Display warning that the filepath does not end with the output format's file extension and that it will be automatically updated with that file extension.
- If the path ends with a different extension it is replaced with the extension of the output format.
- If the path does not end with a different extension then the extension for the output format is added to the end of the file path.
Closes #845
diff --git a/src/utils.ts b/src/utils.ts
index 3545167..290a0ad 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -21,6 +21,7 @@
import * as child_process from 'child_process'
import path from 'path'
import { VSCodeLaunchConfigArgs } from './classes/vscode-launch'
+import { InfosetOutput } from './daffodilDebugger'
let currentConfig: vscode.DebugConfiguration
@@ -84,6 +85,34 @@
})
}
+function checkInfosetFileExtension(
+ infosetOutput: InfosetOutput,
+ infosetFormat: string
+) {
+ // If the infoset file path doesn't end with the infoset output format, update to end with infoset output format.
+ if (!infosetOutput.path.endsWith(`.${infosetFormat}`)) {
+ vscode.window.showWarningMessage(
+ `The output path for the file extension doesn't end with the infoset output format type. The file extension will be updated to end with .${infosetFormat}`
+ )
+
+ let fileExtensionSearchResult = new RegExp('(\\.).*$')
+ .exec(infosetOutput!.path)
+ ?.filter((fileExt) => fileExt !== '.')[0]
+
+ /**
+ * If search result is not undefined replace the file extension with the correct extension.
+ * Else append proper file extension to the end of the output path.
+ */
+ infosetOutput.path =
+ fileExtensionSearchResult !== undefined
+ ? infosetOutput.path.replace(
+ fileExtensionSearchResult,
+ `.${infosetFormat}`
+ )
+ : (infosetOutput.path = `${infosetOutput!.path}.${infosetFormat}`)
+ }
+}
+
export function getConfig(jsonArgs: object): vscode.DebugConfiguration {
const launchConfigArgs: VSCodeLaunchConfigArgs = JSON.parse(
JSON.stringify(jsonArgs)
@@ -136,6 +165,13 @@
: defaultValue)
)
+ if (launchConfigArgs.infosetOutput?.type == 'file') {
+ checkInfosetFileExtension(
+ launchConfigArgs.infosetOutput!,
+ launchConfigArgs.infosetFormat!
+ )
+ }
+
return JSON.parse(JSON.stringify(launchConfigArgs))
}