Skip to content

Commit

Permalink
Rename setting program to schema
Browse files Browse the repository at this point in the history
Closes apache#928
  • Loading branch information
shanedell committed Jan 5, 2024
1 parent be254b3 commit cb31e12
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ object Parse {
// Parse a launch config that has been found to not have a tdmlConfig object
def parseManual(arguments: JsonObject): EitherNel[String, LaunchArgs] =
(
parseProgram(arguments),
parseSchema(arguments),
parseData(arguments),
parseStopOnEntry(arguments),
parseInfosetFormat(arguments),
Expand Down Expand Up @@ -302,7 +302,7 @@ object Parse {
Option(tdmlConfig.getAsJsonPrimitive("action")) match {
case None =>
(
parseProgram(arguments),
parseSchema(arguments),
parseData(arguments),
parseStopOnEntry(arguments),
parseInfosetFormat(arguments),
Expand All @@ -314,7 +314,7 @@ object Parse {
action.getAsString() match {
case "generate" =>
(
parseProgram(arguments),
parseSchema(arguments),
parseData(arguments),
parseStopOnEntry(arguments),
parseInfosetFormat(arguments),
Expand All @@ -327,7 +327,7 @@ object Parse {
).parMapN(LaunchArgs.TDMLConfig.Generate.apply)
case "append" =>
(
parseProgram(arguments),
parseSchema(arguments),
parseData(arguments),
parseStopOnEntry(arguments),
parseInfosetFormat(arguments),
Expand Down Expand Up @@ -356,20 +356,20 @@ object Parse {
}
}

// Parse the program field from the launch config
// Returns an error if the program field is missing or is an invalid path
// Parse the schema field from the launch config
// Returns an error if the schema field is missing or is an invalid path
// A case where the user expects a new directory to be created is not a valid path
// eg. /path/to/<existing>/<non-existing>/file.tdml
//
// arguments: Launch config
def parseProgram(arguments: JsonObject) =
Option(arguments.getAsJsonPrimitive("program"))
.toRight("missing 'program' field from launch request")
def parseSchema(arguments: JsonObject) =
Option(arguments.getAsJsonPrimitive("schema"))
.toRight("missing 'schema' field from launch request")
.flatMap(path =>
Either
.catchNonFatal(Paths.get(path.getAsString))
.leftMap(t => s"'program' field from launch request is not a valid path: $t")
.ensureOr(path => s"program file at $path doesn't exist")(_.toFile().exists())
.leftMap(t => s"'schema' field from launch request is not a valid path: $t")
.ensureOr(path => s"schema file at $path doesn't exist")(_.toFile().exists())
)
.toEitherNel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ParseSuite extends FunSuite {
val name = "Default Config"
val request = "launch"
val launchType = "dfdl"
var program = Paths.get("./src/test/data/emptySchema.dfdl.xsd").toAbsolutePath().toString()
var schema = Paths.get("./src/test/data/emptySchema.dfdl.xsd").toAbsolutePath().toString()
var data = Paths.get("./src/test/data/emptyData.xml").toAbsolutePath().toString()
val debugServer = 4711
val infosetFormat = "xml"
Expand All @@ -46,7 +46,7 @@ class ParseSuite extends FunSuite {
var testTDMLObject = new JsonObject()

override def beforeEach(context: BeforeEach): Unit = {
program = Paths.get("./src/test/data/emptySchema.dfdl.xsd").toAbsolutePath().toString()
schema = Paths.get("./src/test/data/emptySchema.dfdl.xsd").toAbsolutePath().toString()
data = Paths.get("./src/test/data/emptyData.xml").toAbsolutePath().toString()
infosetOutputType = "none"
infosetOutputPath = "testPath/infoset.xml"
Expand All @@ -61,12 +61,12 @@ class ParseSuite extends FunSuite {
assertEquals(Parse.Debugee.LaunchArgs.parse(testJsonObject).isRight, true)
}

test("Parse failed - No Program") {
test("Parse failed - No Schema") {
buildJson()
testJsonObject.remove("program")
testJsonObject.remove("schema")
val parseResult = Parse.Debugee.LaunchArgs.parse(testJsonObject)
assertEquals(parseResult.isLeft, true)
assertEquals(parseResult.left.get.head, "missing 'program' field from launch request")
assertEquals(parseResult.left.get.head, "missing 'schema' field from launch request")
}

test("Parse failed - No data") {
Expand Down Expand Up @@ -141,12 +141,12 @@ class ParseSuite extends FunSuite {
)
}

test("Parse failed - Invalid Program Path") {
program = "badPath.dfdl.xsd"
test("Parse failed - Invalid Schema Path") {
schema = "badPath.dfdl.xsd"
buildJson()
val parseResult = Parse.Debugee.LaunchArgs.parse(testJsonObject)
assertEquals(parseResult.isLeft, true)
assertEquals(parseResult.left.get.head, s"program file at $program doesn't exist")
assertEquals(parseResult.left.get.head, s"schema file at $schema doesn't exist")
}

test("Parse failed - infosetOutputType not file") {
Expand All @@ -171,7 +171,7 @@ class ParseSuite extends FunSuite {
testJsonObject.addProperty("name", name)
testJsonObject.addProperty("request", request)
testJsonObject.addProperty("type", launchType)
testJsonObject.addProperty("program", program)
testJsonObject.addProperty("schema", schema)
testJsonObject.addProperty("data", data)
testJsonObject.addProperty("debugServer", debugServer)
testJsonObject.addProperty("infosetFormat", infosetFormat)
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"onLanguage:dfdl",
"onDebugResolve:dfdl",
"onDebugDynamicConfigurations:dfdl",
"onCommand:extension.dfdl-debug.getProgramName",
"onCommand:extension.dfdl-debug.getSchemaName",
"onCommand:extension.dfdl-debug.getDataName",
"onCommand:extension.dfdl-debug.runEditorContents",
"onCommand:extension.dfdl-debug.debugEditorContents",
Expand Down Expand Up @@ -338,14 +338,14 @@
"configurationAttributes": {
"launch": {
"required": [
"program",
"schema",
"data"
],
"properties": {
"program": {
"schema": {
"type": "string",
"description": "Absolute path to the DFDL schema file.",
"default": "${command:AskForProgramName}"
"default": "${command:AskForSchemaName}"
},
"data": {
"type": "string",
Expand Down Expand Up @@ -462,7 +462,7 @@
"type": "dfdl",
"request": "launch",
"name": "Ask for file name",
"program": "${command:AskForProgramName}",
"schema": "${command:AskForSchemaName}",
"stopOnEntry": true,
"data": "${command:AskForDataName}",
"infosetFormat": "xml",
Expand Down Expand Up @@ -506,7 +506,7 @@
"type": "dfdl",
"request": "launch",
"name": "Ask for file name",
"program": "^\"\\${command:AskForProgramName}\"",
"schema": "^\"\\${command:AskForSchemaName}\"",
"stopOnEntry": true,
"data": "^\"\\${command:AskForDataName}\"",
"infosetFormat": "xml",
Expand Down Expand Up @@ -544,7 +544,7 @@
}
],
"variables": {
"AskForProgramName": "extension.dfdl-debug.getProgramName",
"AskForSchemaName": "extension.dfdl-debug.getSchemaName",
"AskForDataName": "extension.dfdl-debug.getDataName",
"AskForTDMLName": "extension.dfdl-debug.getTDMLName",
"AskForTDMLDescription": "extension.dfdl-debug.getTDMLDescription",
Expand All @@ -561,10 +561,10 @@
"type": "string",
"default": "dfdl"
},
"program": {
"schema": {
"type": "string",
"description": "Absolute path to the DFDL schema file.",
"default": "${command:AskForProgramName}"
"default": "${command:AskForSchemaName}"
},
"data": {
"type": "string",
Expand Down
18 changes: 9 additions & 9 deletions src/adapter/activateDaffodilDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import { handleDebugEvent } from './daffodilEvent'
import { InlineDebugAdapterFactory } from './extension'
import * as dfdlExt from '../language/semantics/dfdlExt'

/** Method to file path for program and data
/** Method to file path for schema and data
* Details:
* Required so that the vscode api commands:
* - extension.dfdl-debug.getProgramName
* - extension.dfdl-debug.getSchemaName
* - extension.dfdl-debug.getDataName
* can be sent a file instead of always opening up a prompt.
* Always makes it so the vscode api commands above are able
Expand Down Expand Up @@ -113,7 +113,7 @@ function createDebugRunFileConfigs(
name: 'Run File',
request: 'launch',
type: 'dfdl',
program: targetResource.fsPath,
schema: targetResource.fsPath,
data: false,
debugServer: false,
infosetFormat: 'xml',
Expand Down Expand Up @@ -194,7 +194,7 @@ export function activateDaffodilDebug(
}
),
vscode.commands.registerCommand(
'extension.dfdl-debug.getProgramName',
'extension.dfdl-debug.getSchemaName',
async (fileRequested = null) => {
// Open native file explorer to allow user to select data file from anywhere on their machine
return await getFile(
Expand Down Expand Up @@ -297,7 +297,7 @@ export function activateDaffodilDebug(
name: 'Daffodil Launch',
request: 'launch',
type: 'dfdl',
program: '${file}',
schema: '${file}',
data: false,
debugServer: false,
infosetFormat: 'xml',
Expand All @@ -321,7 +321,7 @@ export function activateDaffodilDebug(
name: 'Daffodil Launch',
request: 'launch',
type: 'dfdl',
program: '${file}',
schema: '${file}',
data: false,
debugServer: false,
infosetFormat: 'xml',
Expand Down Expand Up @@ -438,9 +438,9 @@ class DaffodilConfigurationProvider
config.debugServer = 4711
}

if (!config.program) {
if (!config.schema) {
return vscode.window
.showInformationMessage('Cannot find a program to debug')
.showInformationMessage('Cannot find a schema to debug')
.then((_) => {
return undefined // abort launch
})
Expand All @@ -457,7 +457,7 @@ class DaffodilConfigurationProvider
}

if (
!dataFolder.includes('${command:AskForProgramName}') &&
!dataFolder.includes('${command:AskForSchemaName}') &&
!dataFolder.includes('${command:AskForDataName}') &&
!dataFolder.includes('${workspaceFolder}') &&
vscode.workspace.workspaceFolders &&
Expand Down
8 changes: 4 additions & 4 deletions src/adapter/daffodilDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function timeout(ms: number) {
* The interface should always match this schema.
*/
interface ILaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
/** An absolute path to the "program" to debug. */
program: string
/** An absolute path to the "schema" to debug. */
schema: string
/** Automatically stop target after launch. If not specified, target does not stop. */
stopOnEntry?: boolean
/** enable logging the Debug Adapter Protocol */
Expand Down Expand Up @@ -246,8 +246,8 @@ export class DaffodilDebugSession extends LoggingDebugSession {
// wait until configuration has finished (and configurationDoneRequest has been called)
await this._configurationDone.wait(1000)

// start the program in the runtime
await this._runtime.start(args.program, !!args.stopOnEntry, !!args.noDebug)
// start the schema in the runtime
await this._runtime.start(args.schema, !!args.stopOnEntry, !!args.noDebug)

this.sendResponse(response)
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/vscode-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface VSCodeLaunchConfigArgs {
name: string
request: string
type: string
program: string | boolean
schema: string | boolean
data: string | boolean
debugServer: number | boolean
infosetFormat: string | null
Expand Down
10 changes: 5 additions & 5 deletions src/daffodilDebugger/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function getTDMLConfig(
// so we don't need to prompt for them now.
if (config?.tdmlConfig?.action === 'execute') {
// Erase the value of `data` so that we aren't prompted for it later
// Might need to add `program` here if we move the `Execute TDML` command
// Might need to add `schema` here if we move the `Execute TDML` command
// away from the detected dfdl language in VSCode.
config.data = ''
}
Expand Down Expand Up @@ -155,10 +155,10 @@ export async function getDebugger(
if (vscode.workspace.workspaceFolders !== undefined) {
await stopDebugger()

// Get program file before debugger starts to avoid timeout
if (config.program.includes('${command:AskForProgramName}')) {
config.program = await vscode.commands.executeCommand(
'extension.dfdl-debug.getProgramName'
// Get schema file before debugger starts to avoid timeout
if (config.schema.includes('${command:AskForSchemaName}')) {
config.schema = await vscode.commands.executeCommand(
'extension.dfdl-debug.getSchemaName'
)
}

Expand Down
14 changes: 7 additions & 7 deletions src/launchWizard/launchWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getConfigValues() {
'openInfosetDiffView'
).checked
const openInfosetView = document.getElementById('openInfosetView').checked
const program = document.getElementById('program').value
const schema = document.getElementById('schema').value
const stopOnEntry = document.getElementById('stopOnEntry').checked
const trace = document.getElementById('trace').checked
const useExistingServer = document.getElementById('useExistingServer').checked
Expand Down Expand Up @@ -96,7 +96,7 @@ function getConfigValues() {
openHexView,
openInfosetDiffView,
openInfosetView,
program,
schema,
stopOnEntry,
trace,
useExistingServer,
Expand Down Expand Up @@ -271,7 +271,7 @@ function save() {
request: 'launch',
type: 'dfdl',
name: configValues.name,
program: configValues.program,
schema: configValues.schema,
data: configValues.data,
debugServer: configValues.debugServer,
infosetFormat: configValues.infosetFormat,
Expand Down Expand Up @@ -327,7 +327,7 @@ function copyConfig() {
request: 'launch',
type: 'dfdl',
name: `${configValues.name}`,
program: configValues.program,
schema: configValues.schema,
data: configValues.data,
debugServer: configValues.debugServer,
infosetFormat: configValues.infosetFormat,
Expand Down Expand Up @@ -409,7 +409,7 @@ async function updateConfigValues(config) {
document.getElementById('openInfosetDiffView').checked =
config.openInfosetDiffView
document.getElementById('openInfosetView').checked = config.openInfosetView
document.getElementById('program').value = config.program
document.getElementById('schema').value = config.schema
document.getElementById('stopOnEntry').checked = config.stopOnEntry
document.getElementById('trace').checked = config.trace
document.getElementById('useExistingServer').checked =
Expand Down Expand Up @@ -462,8 +462,8 @@ async function updateDaffodilDebugClasspath(message) {
case 'dataUpdate':
document.getElementById('data').value = message.value
break
case 'programUpdate':
document.getElementById('program').value = message.value
case 'schemaUpdate':
document.getElementById('schema').value = message.value
break
case 'daffodilDebugClasspathUpdate':
await updateDaffodilDebugClasspath(message)
Expand Down
6 changes: 3 additions & 3 deletions src/launchWizard/launchWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,11 @@ class LaunchWizard {
</p>
</div>
<div id="programDiv" class="setting-div">
<div id="schemaDiv" class="setting-div">
<p>Main Schema File:</p>
<p class="setting-description">Absolute path to the DFDL schema file.</p>
<input class="file-input" value="${defaultValues.program}" id="program"/>
<button id="programBrowse" class="browse-button" type="button" onclick="filePicker('program', 'Select DFDL schema to debug')">Browse</button>
<input class="file-input" value="${defaultValues.schema}" id="schema"/>
<button id="schemaBrowse" class="browse-button" type="button" onclick="filePicker('schema', 'Select DFDL schema to debug')">Browse</button>
</div>
<div id="dataDiv" class="setting-div">
Expand Down
Loading

0 comments on commit cb31e12

Please sign in to comment.