Skip to content
Permalink
Browse files
Add launch options for the hex, infoset and infoset-diff view opening.
Closes #13
  • Loading branch information
Shanedell authored and jw3 committed Nov 4, 2021
1 parent 065c3be commit 319b99ef7d0f4a9bdd5403b1a08c346651d09fa3
Show file tree
Hide file tree
Showing 6 changed files with 4,359 additions and 7 deletions.
@@ -26,6 +26,9 @@ node_modules
target
.bsp

# npm install file
package-lock.json

# build
src/version.ts

@@ -229,6 +229,21 @@
"type": "boolean",
"description": "Enable connection to running DAP Server",
"default": false
},
"openHexView": {
"type": "boolean",
"description": "Open hexview on debug start",
"default": false
},
"openInfosetView": {
"type": "boolean",
"description": "Open hexview on debug start",
"default": false
},
"openInfosetDiffView": {
"type": "boolean",
"description": "Open hexview on debug start",
"default": false
}
}
}
@@ -245,7 +260,10 @@
"type": "file",
"path": "${workspaceFolder}/infoset.xml"
},
"debugServer": 4711
"debugServer": 4711,
"openHexView": false,
"openInfosetView": false,
"openInfosetDiffView": false
}
],
"configurationSnippets": [
@@ -263,7 +281,10 @@
"type": "file",
"path": "${workspaceFolder}/infoset.xml"
},
"debugServer": 4711
"debugServer": 4711,
"openHexView": false,
"openInfosetView": false,
"openInfosetDiffView": false
}
}
],
@@ -22,6 +22,7 @@ import * as hexy from 'hexy'
import XDGAppPaths from 'xdg-app-paths'
import { ConfigEvent, DaffodilData } from './daffodil'
const xdgAppPaths = XDGAppPaths({ name: 'daffodil-dap' })
import { onDebugStartDisplay } from './utils'

export class DebuggerHexView {
context: vscode.ExtensionContext
@@ -121,6 +122,18 @@ export class DebuggerHexView {
this.onDisplayHex(e.session, e.body)
break
}

let hexFileOpened = false

vscode.window.visibleTextEditors.forEach((editor) => {
if (editor.document.fileName === this.hexFile) {
hexFileOpened = true
}
})

if (!hexFileOpened) {
onDebugStartDisplay(['hex-view'])
}
}
}

@@ -196,7 +209,7 @@ export class DebuggerHexView {
vscode.window
.showTextDocument(doc, {
selection: range,
viewColumn: vscode.ViewColumn.Three,
viewColumn: vscode.ViewColumn.Two,
preserveFocus: true,
preview: false,
})
@@ -21,6 +21,7 @@ import * as daf from './daffodil'
import * as fs from 'fs'
import { InfosetEvent } from './daffodil'
import { Uri } from 'vscode'
import { onDebugStartDisplay } from './utils'

export async function activate(ctx: vscode.ExtensionContext) {
let sid: string | undefined
@@ -29,6 +30,7 @@ export async function activate(ctx: vscode.ExtensionContext) {
ctx.subscriptions.push(
vscode.debug.onDidStartDebugSession((s) => {
sid = s.id
onDebugStartDisplay(['infoset-view', 'infoset-diff-view'])
})
)
ctx.subscriptions.push(
@@ -52,9 +54,9 @@ export async function activate(ctx: vscode.ExtensionContext) {
let path = ensure(tmp(sid))
doc = await vscode.workspace.openTextDocument(path)
await vscode.window.showTextDocument(doc, {
viewColumn: vscode.ViewColumn.Beside,
viewColumn: vscode.ViewColumn.Two,
preserveFocus: true,
preview: true,
preview: false,
})
}
})
@@ -80,7 +82,8 @@ export async function activate(ctx: vscode.ExtensionContext) {
case 'View':
let xml = await vscode.workspace.openTextDocument(uri)
await vscode.window.showTextDocument(xml, {
viewColumn: vscode.ViewColumn.Beside,
preview: false,
viewColumn: vscode.ViewColumn.Two,
})
break
case 'Delete':
@@ -103,7 +106,8 @@ export async function activate(ctx: vscode.ExtensionContext) {
'vscode.diff',
Uri.parse(prev),
Uri.parse(path),
'Previous ↔ Current'
'Previous ↔ Current',
{ preview: false, viewColumn: vscode.ViewColumn.Two }
)
}
})
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as vscode from 'vscode'

// Function to run vscode command and catch the error to not cause other issues
export function runCommand(command: string) {
vscode.commands.executeCommand(command).then(undefined, (err) => {
vscode.window.showInformationMessage(err)
})
}

// 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]

viewsToCheck.forEach(async (viewToCheck) => {
switch (viewToCheck) {
case 'hex-view':
if (config.openHexView) {
runCommand('hexview.display')
}
break
case 'infoset-view':
if (config.openInfosetView) {
runCommand('infoset.display')
}
break
case 'infoset-diff-view':
if (config.openInfosetDiffView) {
runCommand('infoset.diff')
}
break
}
})
}

0 comments on commit 319b99e

Please sign in to comment.