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 2021/12/21 13:59:41 UTC

[daffodil-vscode] branch main updated: Create popup notification when infoset is written. Closes #12

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 3553a65  Create popup notification when infoset is written. Closes #12
3553a65 is described below

commit 3553a65e74d24de11e779e5acd9680ae1e0a3a6e
Author: Shane Dell <sh...@gmail.com>
AuthorDate: Mon Dec 6 13:56:24 2021 -0500

    Create popup notification when infoset is written. Closes #12
---
 src/adapter/activateDaffodilDebug.ts |  4 +++-
 src/infoset.ts                       | 38 ++++++++++++++++++++++++++++++++++--
 src/utils.ts                         | 25 ++++++++++++------------
 3 files changed, 52 insertions(+), 15 deletions(-)

diff --git a/src/adapter/activateDaffodilDebug.ts b/src/adapter/activateDaffodilDebug.ts
index 700a8e9..ca243c1 100644
--- a/src/adapter/activateDaffodilDebug.ts
+++ b/src/adapter/activateDaffodilDebug.ts
@@ -19,7 +19,7 @@ import { getDebugger, getDataFileFromFolder } from '../daffodilDebugger'
 import { FileAccessor } from './daffodilRuntime'
 import * as fs from 'fs'
 import * as infoset from '../infoset'
-import { getConfig } from '../utils'
+import { getConfig, setCurrentConfig } from '../utils'
 import * as launchWizard from '../launchWizard/launchWizard'
 
 // Function for setting up the commands for Run and Debug file
@@ -318,6 +318,7 @@ class DaffodilConfigurationProvider
     ) {
       return getDataFileFromFolder(dataFolder).then((dataFile) => {
         config.data = dataFile
+        setCurrentConfig(config)
         return getDebugger(this.context, config).then((result) => {
           return config
         })
@@ -325,6 +326,7 @@ class DaffodilConfigurationProvider
     }
 
     return getDebugger(this.context, config).then((result) => {
+      setCurrentConfig(config)
       return config
     })
   }
diff --git a/src/infoset.ts b/src/infoset.ts
index 894cd69..b8c739b 100644
--- a/src/infoset.ts
+++ b/src/infoset.ts
@@ -21,7 +21,40 @@ import * as daf from './daffodil'
 import * as fs from 'fs'
 import { InfosetEvent } from './daffodil'
 import { Uri } from 'vscode'
-import { onDebugStartDisplay } from './utils'
+import { onDebugStartDisplay, getCurrentConfg } 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()))
+
+  if (config.infosetOutput.type === 'file') {
+    let rootPath = vscode.workspace.workspaceFolders
+      ? vscode.workspace.workspaceFolders[0].uri.fsPath
+      : vscode.Uri.parse('').fsPath
+    let path = config.infosetOutput.path.includes('${workspaceFolder}')
+      ? config.infosetOutput.path.replace('${workspaceFolder}', rootPath)
+      : config.infosetOutput.path
+
+    const action = await vscode.window.showInformationMessage(
+      `Wrote infoset file to ${path}`,
+      'Open',
+      'Dismiss'
+    )
+
+    let uri = vscode.Uri.parse(path)
+
+    switch (action) {
+      case 'Open':
+        let xml = await vscode.workspace.openTextDocument(uri)
+        await vscode.window.showTextDocument(xml, {
+          preview: false,
+          viewColumn: vscode.ViewColumn.One,
+        })
+        break
+    }
+  }
+}
 
 export async function activate(ctx: vscode.ExtensionContext) {
   let sid: string | undefined
@@ -34,8 +67,9 @@ export async function activate(ctx: vscode.ExtensionContext) {
     })
   )
   ctx.subscriptions.push(
-    vscode.debug.onDidTerminateDebugSession((s) => {
+    vscode.debug.onDidTerminateDebugSession(async (s) => {
       sid = undefined
+      await openInfosetFilePrompt()
     })
   )
   ctx.subscriptions.push(
diff --git a/src/utils.ts b/src/utils.ts
index dfcb90d..dc235c0 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -18,6 +18,18 @@
 import * as vscode from 'vscode'
 
 const defaultConf = vscode.workspace.getConfiguration()
+let currentConfig: vscode.ProviderResult<vscode.DebugConfiguration>
+
+// Function to retrieve to the current debug config
+export function getCurrentConfg() {
+  return currentConfig
+}
+
+// Function to set the current debug config
+export function setCurrentConfig(config) {
+  currentConfig = config
+  return currentConfig
+}
 
 // Function to run vscode command and catch the error to not cause other issues
 export function runCommand(command: string) {
@@ -29,18 +41,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(
-      vscode.workspace
-        .getConfiguration(
-          'launch',
-          vscode.workspace.workspaceFolders
-            ? vscode.workspace.workspaceFolders[0].uri
-            : vscode.Uri.parse('')
-        )
-        .get('configurations')
-    )
-  )[0]
+  let config = JSON.parse(JSON.stringify(getCurrentConfg()))
 
   viewsToCheck.forEach(async (viewToCheck) => {
     switch (viewToCheck) {