Skip to content

Commit

Permalink
Ensure infoset file extension match output format.
Browse files Browse the repository at this point in the history
- Done by checking if the filepath does not end with the proper file extension. If it doesn't then:
  - 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 apache#845
  • Loading branch information
shanedell committed Jan 3, 2024
1 parent 4e45b16 commit fd1c1e4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as os from 'os'
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

Expand Down Expand Up @@ -79,6 +80,30 @@ export async function onDebugStartDisplay(viewsToCheck: string[]) {
})
}

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}`)) {
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)
Expand Down Expand Up @@ -131,6 +156,11 @@ export function getConfig(jsonArgs: object): vscode.DebugConfiguration {
: defaultValue)
)

checkInfosetFileExtension(
launchConfigArgs.infosetOutput!,
launchConfigArgs.infosetFormat!
)

return JSON.parse(JSON.stringify(launchConfigArgs))
}

Expand Down

0 comments on commit fd1c1e4

Please sign in to comment.