Skip to content

Commit

Permalink
Create view container with a view of commands.
Browse files Browse the repository at this point in the history
- Create initial view container with a single view.
- Create command view that displays a tree of our custom commands that can be ran.
- Add play button to commands in view to be able to run them.
- Update list of commands based on if debug mode or not.
- Bump macos-12 to macos-14 to unbreak CI.
  - Not using macos-13 as it doesn't have sbt installed by default.
- Configure daffodil-icon to look good for view container.

Closes apache#1129
  • Loading branch information
shanedell committed Dec 3, 2024
1 parent 352ce37 commit cabcb83
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ jobs:
matrix:
java_distribution: [ temurin ]
java_version: [ 8, 11, 17 ]
os: [ macos-12, ubuntu-20.04, windows-2019 ]
# macos-13 not used as it doesn't by default have sbt installed.
os: [ macos-14, ubuntu-20.04, windows-2019 ]
node: [ '18.20.1' ]
vscode: [ '1.82.0', 'stable' ] # v1.82.0 is the first version of VSCode to use Node 18
fail-fast: false # don't immediately fail all other jobs if a single job fails
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
name: 'Build, Test, and Package (OS: ${{ matrix.os }}, Node: ${{ matrix.node }}, Java: ${{ matrix.java_version }}, VS Code: ${{ matrix.vscode }})'
strategy:
matrix:
os: [ macos-12, ubuntu-20.04, windows-2019, macos-latest, ubuntu-latest, windows-latest ]
# macos-13 not used as it doesn't by default have sbt installed.
os: [ macos-14, ubuntu-20.04, windows-2019, macos-latest, ubuntu-latest, windows-latest ]
node: [ '18.20.1' ]
vscode: [ '1.82.0', 'stable', 'insiders' ] # v1.82.0 is the first version of VSCode to use Node 18
java_distribution: [ temurin ]
Expand Down
73 changes: 73 additions & 0 deletions images/daffodil-viewbar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "apache-daffodil-vscode",
"displayName": "Apache Daffodil™ Extension for Visual Studio Code",
"description": "Apache Daffodil™ Extension for Visual Studio Code providing DFDL syntax highlighting, DFDL code completion, DFDL schema debugging, and data editor",
"version": "1.4.0",
"version": "1.4.1-SNAPSHOT",
"daffodilVersion": "3.8.0",
"publisher": "asf",
"author": "Apache Daffodil",
Expand Down Expand Up @@ -122,12 +122,30 @@
"onCommand:extension.dfdl-debug.getValidatedTDMLCopyPath",
"onCommand:launch.config",
"onCommand:extension.data.edit",
"onCommand:extension.dfdl-debug.debugLastEditorContents"
"onCommand:extension.dfdl-debug.debugLastEditorContents",
"onView:commandsView"
],
"workspaceTrust": {
"request": "never"
},
"contributes": {
"viewsContainers": {
"activitybar": [
{
"id": "daffodil-explorer",
"title": "Daffodil Explorer",
"icon": "images/daffodil-viewbar.svg"
}
]
},
"views": {
"daffodil-explorer": [
{
"id": "commandsView",
"name": "Commands View"
}
]
},
"languages": [
{
"id": "dfdl",
Expand Down Expand Up @@ -178,6 +196,20 @@
}
],
"menus": {
"view/title": [
{
"command": "commandsView.refresh",
"when": "view == commandsView",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "commandsView.runCommand",
"when": "view == commandsView",
"group": "inline"
}
],
"editor/title": [
{
"command": "launch.config",
Expand Down Expand Up @@ -298,6 +330,16 @@
]
},
"commands": [
{
"command": "commandsView.refresh",
"title": "Refresh",
"icon": "$(refresh)"
},
{
"command": "commandsView.runCommand",
"title": "Run",
"icon": "$(play)"
},
{
"command": "extension.dfdl-debug.debugEditorContents",
"title": "Debug File",
Expand Down
6 changes: 6 additions & 0 deletions src/adapter/activateDaffodilDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
copyTestCase,
} from 'tdmlEditor/utilities/tdmlXmlUtils'
import xmlFormat from 'xml-formatter'
import { CommandsProvider } from '../views/commands'

export const outputChannel: vscode.OutputChannel =
vscode.window.createOutputChannel('Daffodil')
Expand Down Expand Up @@ -204,10 +205,15 @@ function createDebugRunFileConfigs(
}
}

function setupViews(context: vscode.ExtensionContext) {
new CommandsProvider().register(context)
}
export function activateDaffodilDebug(
context: vscode.ExtensionContext,
factory?: vscode.DebugAdapterDescriptorFactory
) {
setupViews(context)

context.subscriptions.push(
vscode.commands.registerCommand(
'extension.dfdl-debug.runEditorContents',
Expand Down
1 change: 1 addition & 0 deletions src/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@
/* padding-top: -10px; */
margin-top: 0px;
/* cursor: pointer; */
fill: #000000;
}
119 changes: 119 additions & 0 deletions src/views/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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'

const viewName = 'commandsView'
const packageCommands = require('../../package.json').contributes.commands

// Custom class to hold attributes of the commands
class CommandItem extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly commandName: string,
public readonly category: string,
public readonly enablement: string,
public readonly collapsibleState: vscode.TreeItemCollapsibleState
) {
super(label, collapsibleState)
this.tooltip = `${this.category}: ${this.label}`
this.description = this.commandName
}

iconPath = new vscode.ThemeIcon('bracket')
}

// Class that will create the tree of commands in our view container
export class CommandsProvider implements vscode.TreeDataProvider<CommandItem> {
private commands: Array<CommandItem>
constructor() {
this.commands = getCommands('!inDebugMode')
}

private _onDidChangeTreeData: vscode.EventEmitter<
CommandItem | undefined | null | void
> = new vscode.EventEmitter<CommandItem | undefined | null | void>()
readonly onDidChangeTreeData: vscode.Event<
CommandItem | undefined | null | void
> = this._onDidChangeTreeData.event

getTreeItem = (element: CommandItem): vscode.TreeItem => element

getChildren = (): vscode.ProviderResult<CommandItem[]> => this.commands

refresh = (): void => this._onDidChangeTreeData.fire()

public register(context: vscode.ExtensionContext): any {
vscode.window.registerTreeDataProvider(viewName, this)

const tree = vscode.window.createTreeView(viewName, {
treeDataProvider: this,
showCollapseAll: true,
})

// Create command that allows for the execution of our other commands
// when the command items play icon is clicked
vscode.commands.registerCommand(
`${viewName}.runCommand`,
async (commandItem: CommandItem) =>
vscode.commands.executeCommand(commandItem.commandName)
)

// Create command that will refresh the list of commands
vscode.commands.registerCommand(`${viewName}.refresh`, () => {
this.refresh()
})

// Create listeners to update the commands based on if a debug session is happening
vscode.debug.onDidStartDebugSession(() => {
this.commands = getCommands('inDebugMode')
this.refresh()
})
vscode.debug.onDidTerminateDebugSession(() => {
this.commands = getCommands('!inDebugMode')
this.refresh()
})

context.subscriptions.push(tree)
}
}

// Function to parse all the commands from the package.json, that currently enabled,
// to an array of CommandItems
function getCommands(enablement: String): Array<CommandItem> {
const commands = Array<CommandItem>()

packageCommands
.filter(
(c) =>
!c.command.startsWith(viewName) &&
(enablement === c.enablement || c.enablement === undefined)
)
.forEach((command) => {
commands.push(
new CommandItem(
command.title,
command.command,
command.category,
command.enablement ?? '',
vscode.TreeItemCollapsibleState.None
)
)
})

return commands
}
Loading

0 comments on commit cabcb83

Please sign in to comment.