You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sh...@apache.org on 2022/07/18 23:30:27 UTC

[daffodil-vscode] branch main updated: Add debug option that uses configuration from last debug

This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git


The following commit(s) were added to refs/heads/main by this push:
     new 5c38f0c  Add debug option that uses configuration from last debug
5c38f0c is described below

commit 5c38f0c7dad4429271aea896e1accaf4bb9266fa
Author: Michael Hoke <mi...@nteligen.com>
AuthorDate: Tue May 10 18:42:58 2022 -0400

    Add debug option that uses configuration from last debug
    
    Add debug option that uses configuration from last debug
    
    - Rename function to remove typo
    
    - Remove line added in merge
---
 package.json                         | 18 +++++++++++++-
 src/adapter/activateDaffodilDebug.ts | 48 +++++++++++++++++++++++++-----------
 src/infoset.ts                       |  4 +--
 src/utils.ts                         |  6 ++---
 4 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/package.json b/package.json
index baeff5e..dc2171c 100644
--- a/package.json
+++ b/package.json
@@ -84,7 +84,8 @@
     "onCommand:launch.config",
     "onCommand:data.edit",
     "onCommand:omega_edit.version",
-    "onCommand:toggle.experimental"
+    "onCommand:toggle.experimental",
+    "onCommand:extension.dfdl-debug.debugLastEditorContents"
   ],
   "workspaceTrust": {
     "request": "never"
@@ -139,6 +140,10 @@
         {
           "command": "extension.dfdl-debug.debugEditorContents",
           "when": "resourceLangId == dfdl"
+        },
+        {
+          "command": "extension.dfdl-debug.debugLastEditorContents",
+          "when": "resourceLangId == dfdl"
         }
       ],
       "commandPalette": [
@@ -160,6 +165,10 @@
         },
         {
           "command": "toggle.experimental"
+        },
+        {
+          "command": "extension.dfdl-debug.debugLastEditorContents",
+          "when": "resourceLangId == dfdl"
         }
       ],
       "debug/variables/context": [
@@ -184,6 +193,13 @@
         "enablement": "!inDebugMode",
         "icon": "$(play)"
       },
+      {
+        "command": "extension.dfdl-debug.debugLastEditorContents",
+        "title": "Debug Last File",
+        "category": "Daffodil Debug",
+        "enablement": "!inDebugMode",
+        "icon": "$(debug-alt)"
+      },
       {
         "command": "extension.dfdl-debug.toggleFormatting",
         "title": "Toggle between decimal and hex formatting",
diff --git a/src/adapter/activateDaffodilDebug.ts b/src/adapter/activateDaffodilDebug.ts
index e2f714a..15331a3 100644
--- a/src/adapter/activateDaffodilDebug.ts
+++ b/src/adapter/activateDaffodilDebug.ts
@@ -19,13 +19,17 @@ import { getDebugger, getDataFileFromFolder } from '../daffodilDebugger'
 import { FileAccessor } from './daffodilRuntime'
 import * as fs from 'fs'
 import * as infoset from '../infoset'
-import { getConfig, setCurrentConfig } from '../utils'
+import { getConfig, getCurrentConfig, setCurrentConfig } from '../utils'
 import * as launchWizard from '../launchWizard/launchWizard'
 import * as omegaEditClient from '../omega_edit/client'
 import * as dfdlLang from '../language/dfdl'
 
 // Function for setting up the commands for Run and Debug file
-function createDebugRunFileConfigs(resource: vscode.Uri, runOrDebug: String) {
+function createDebugRunFileConfigs(
+  resource: vscode.Uri,
+  runOrDebug: String,
+  runLast = false
+) {
   let targetResource = resource
   let noDebug = runOrDebug === 'run' ? true : false
 
@@ -38,19 +42,27 @@ function createDebugRunFileConfigs(resource: vscode.Uri, runOrDebug: String) {
     }-infoset.xml`
     vscode.window.showInformationMessage(infosetFile)
 
-    vscode.debug.startDebugging(
-      undefined,
-      getConfig(
-        'Run File',
-        'launch',
-        'dfdl',
-        targetResource.fsPath,
-        false,
-        false,
-        { type: 'file', path: '${workspaceFolder}/' + infosetFile }
-      ),
-      { noDebug: noDebug }
-    )
+    let currentConfig = getCurrentConfig()
+
+    if (runLast && currentConfig) {
+      vscode.debug.startDebugging(undefined, currentConfig, {
+        noDebug: noDebug,
+      })
+    } else {
+      vscode.debug.startDebugging(
+        undefined,
+        getConfig(
+          'Run File',
+          'launch',
+          'dfdl',
+          targetResource.fsPath,
+          false,
+          false,
+          { type: 'file', path: '${workspaceFolder}/' + infosetFile }
+        ),
+        { noDebug: noDebug }
+      )
+    }
 
     vscode.debug.onDidTerminateDebugSession(async () => {
       if (!vscode.workspace.workspaceFolders) {
@@ -85,6 +97,12 @@ export function activateDaffodilDebug(
         createDebugRunFileConfigs(resource, 'debug')
       }
     ),
+    vscode.commands.registerCommand(
+      'extension.dfdl-debug.debugLastEditorContents',
+      (resource: vscode.Uri) => {
+        createDebugRunFileConfigs(resource, 'debug', true)
+      }
+    ),
     vscode.commands.registerCommand(
       'extension.dfdl-debug.toggleFormatting',
       (_) => {
diff --git a/src/infoset.ts b/src/infoset.ts
index 9505e2b..2cdb240 100644
--- a/src/infoset.ts
+++ b/src/infoset.ts
@@ -21,12 +21,12 @@ import * as daf from './daffodil'
 import * as fs from 'fs'
 import { InfosetEvent } from './daffodil'
 import { Uri } from 'vscode'
-import { onDebugStartDisplay, getCurrentConfg } from './utils'
+import { onDebugStartDisplay, getCurrentConfig } from './utils'
 
 // Function to display an infomation message that the infoset file has been created
 // If the user wishes to open the file then they may click the 'Open' button
 async function openInfosetFilePrompt() {
-  let config = JSON.parse(JSON.stringify(getCurrentConfg()))
+  let config = JSON.parse(JSON.stringify(getCurrentConfig()))
 
   if (config.infosetOutput.type === 'file') {
     let rootPath = vscode.workspace.workspaceFolders
diff --git a/src/utils.ts b/src/utils.ts
index 4fbb45f..4b34a68 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -19,7 +19,7 @@ import * as vscode from 'vscode'
 
 const defaultConf = vscode.workspace.getConfiguration()
 // const
-let currentConfig: vscode.ProviderResult<vscode.DebugConfiguration>
+let currentConfig: vscode.DebugConfiguration
 
 export const regexp = {
   comma: new RegExp(',', 'g'),
@@ -29,7 +29,7 @@ export const regexp = {
 }
 
 // Function to retrieve to the current debug config
-export function getCurrentConfg() {
+export function getCurrentConfig() {
   return currentConfig
 }
 
@@ -49,7 +49,7 @@ export function runCommand(command: string) {
 // Function for checking if config specifies if either the
 // infoset, infoset diff or hex view needs to be opened
 export async function onDebugStartDisplay(viewsToCheck: string[]) {
-  let config = JSON.parse(JSON.stringify(getCurrentConfg()))
+  let config = JSON.parse(JSON.stringify(getCurrentConfig()))
 
   viewsToCheck.forEach(async (viewToCheck) => {
     switch (viewToCheck) {