Skip to content

Commit b2fb9be

Browse files
authored
Merge pull request #3 from zapta/main
Assorted cleanups
2 parents 3ffad06 + 43c1361 commit b2fb9be

6 files changed

Lines changed: 69 additions & 67 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Apio FPGA for VS Code
1+
# Apio FPGA for VSCode
22

33
> **Note (November 2025):** This extension is not yet available on the Visual Studio Code Marketplace.
4-
> To install it, download the latest `.vsix` package from the [Releases page](https://github.com/FPGAwars/apio-vscode/releases) and use **Extensions → … → Install from VSIX…** in VS Code.
4+
> To install it, download the latest `.vsix` package from the [Releases page](https://github.com/FPGAwars/apio-vscode/releases) and use **Extensions → … → Install from VSIX…** in VSCode.
55
6-
This official extension by the Apio team brings Apio’s power directly into VS Code with **one-click buttons** and a **dedicated sidebar panel**. Common commands (`lint`, `build`, `upload`) appear on the status bar, while the full command set is organized in a collapsible tree under the **Apio** tab.
6+
This official extension by the Apio team brings Apio’s power directly into VSCode with **one-click buttons** and a **dedicated sidebar panel**. Common commands (`lint`, `build`, `upload`) appear on the status bar, while the full command set is organized in a collapsible tree under the **Apio** tab.
77

88
![VSCode screenshot](media/screenshot1.png)
99

@@ -35,7 +35,7 @@ Apio is a lightweight, open-source, command-line FPGA toolchain for Verilog and
3535
Follow the official guide:
3636
[https://fpgawars.github.io/apio/docs/quick-start/](https://fpgawars.github.io/apio/docs/quick-start/)
3737

38-
2. **Open the project in VS Code**
38+
2. **Open the project in VSCode**
3939
`File → Open Folder…` → select the folder containing `apio.ini`.
4040

4141
3. **Run commands**

defs.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ const COMMANDS_TREE = [
1111
tooltip: "Build the apio project",
1212
id: "apio.build",
1313
action: { cmds: ["apio build {env-flag}"] },
14-
btn: { icon: "$(chip)", priority: 98 },
14+
btn: { icon: "$(check)", position: 1 },
1515
},
1616
{
1717
title: "Upload",
1818
tooltip: "Build and upload to the FPGA board",
1919
id: "apio.upload",
2020
action: { cmds: ["apio upload {env-flag}"] },
21-
btn: { icon: "$(play)", priority: 96 },
21+
btn: { icon: "$(play)", position: 3 },
2222
},
2323
{
2424
title: "Clean",
2525
tooltip: "Clean the build artifacts",
2626
id: "apio.clean",
2727
action: { cmds: ["apio clean"] },
28-
btn: { icon: "$(trash)", priority: 95 },
28+
btn: { icon: "$(trash)", position: 7 },
2929
},
3030
],
3131
},
@@ -37,7 +37,7 @@ const COMMANDS_TREE = [
3737
tooltip: "Lint the source code",
3838
id: "apio.lint",
3939
action: { cmds: ["apio lint {env-flag}"] },
40-
btn: { icon: "$(check-all)", priority: 99 },
40+
btn: { icon: "$(check-all)", position: 2 },
4141
},
4242
{
4343
title: "Format",
@@ -47,22 +47,24 @@ const COMMANDS_TREE = [
4747
},
4848
{
4949
title: "Sim",
50-
tooltip: "Run simulator on the default testbench",
50+
tooltip: "Run the testbench simulator",
5151
id: "apio.sim",
5252
action: { cmds: ["apio sim {env-flag}"] },
53+
btn: { icon: "$(debug-alt)", position: 5 },
5354
},
5455
{
5556
title: "Test",
56-
tooltip: "Run the testbenchs",
57+
tooltip: "Run automatic tests",
5758
id: "apio.test",
5859
action: { cmds: ["apio test"] },
60+
btn: { icon: "$(beaker)", position: 4 },
5961
},
6062
{
6163
title: "Report",
6264
tooltip: "Report design utilization and speed",
6365
id: "apio.report",
6466
action: { cmds: ["apio report {env-flag}"] },
65-
btn: { icon: "$(report)", priority: 97 },
67+
btn: { icon: "$(report)", position: 6 },
6668
},
6769
{
6870
title: "Graph",
@@ -200,7 +202,6 @@ const COMMANDS_TREE = [
200202
},
201203
];
202204

203-
204205
const TOOLS_TREE = [
205206
{
206207
title: "Terminal",
@@ -210,7 +211,6 @@ const TOOLS_TREE = [
210211
},
211212
];
212213

213-
214214
const HELP_TREE = [
215215
{
216216
title: "System info",
@@ -225,16 +225,22 @@ const HELP_TREE = [
225225
action: { cmds: ["apio raw --verbose"] },
226226
},
227227
{
228-
title: "Documentation",
229-
tooltip: "Open Apio documentation",
228+
title: "Overview",
229+
tooltip: "Show Apio documentation",
230230
id: "apio.docs",
231231
action: { url: "https://fpgawars.github.io/apio/docs" },
232232
},
233233
{
234-
title: "Apio commands",
235-
tooltip: "Open Apio commands documentation",
236-
id: "apio.commands.docs",
234+
title: "Commands",
235+
tooltip: "Show Apio commands documentation",
236+
id: "apio.docs.commands",
237237
action: { url: "https://fpgawars.github.io/apio/docs/cmd-apio-build" },
238+
},
239+
{
240+
title: "Project file apio.ini",
241+
tooltip: "Show Apio project file documentation",
242+
id: "apio.docs.project.file",
243+
action: { url: "https://fpgawars.github.io/apio/docs/project-file" },
238244
},
239245
{
240246
title: "Ask questions",

extension.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// List of VSC icons at:
1+
// List of VSC text icons at:
22
// https://code.visualstudio.com/api/references/icons-in-labels
33

44
// Online Javascript linter at: https://eslint.org/play/
@@ -49,13 +49,14 @@ class ApioTreeGroup {
4949
}
5050
}
5151

52-
// Tree is a list of nodes.
53-
function traverseHierarchy(nodes) {
52+
// Recursively traverse the definition tree and return it using
53+
// datatypes that are expected by vscode. Nodes is a list of nodes.
54+
function traverseAndConvertTree(nodes) {
5455
const result = [];
5556
for (const node of nodes) {
5657
if ("children" in node) {
5758
// Handle a group
58-
const children = traverseHierarchy(node.children);
59+
const children = traverseAndConvertTree(node.children);
5960
const item = new ApioTreeGroup(node.title, node.tooltip, children);
6061
result.push(item);
6162
} else {
@@ -77,12 +78,12 @@ function traverseHierarchy(nodes) {
7778
}
7879

7980
// Tree is a list of nodes.
80-
function traverseCommands(context, pre_cmds, nodes) {
81+
function traverseAndRegisterCommands(context, pre_cmds, nodes) {
8182
// const result = [];
8283
for (const node of nodes) {
8384
if ("children" in node) {
8485
// Handle a group
85-
traverseCommands(context, pre_cmds, node.children);
86+
traverseAndRegisterCommands(context, pre_cmds, node.children);
8687
} else {
8788
// Handle a leaf, it must have an action. If there are commands,
8889
// we prefix the pre_cmds, e.g. to cd to the project dir.
@@ -97,29 +98,28 @@ function traverseCommands(context, pre_cmds, nodes) {
9798

9899
// Register the callback to execute the action once selected.
99100
context.subscriptions.push(
100-
vscode.commands.registerCommand(
101-
node.id,
102-
execAction(commands, url)
103-
)
101+
vscode.commands.registerCommand(node.id, execAction(commands, url))
104102
);
105103
}
106104
}
107105
}
108106

109-
function registerTreeButtons(context, nodes_list) {
107+
function traverseAndRegisterTreeButtons(context, nodes_list) {
110108
for (const node of nodes_list) {
111109
if ("children" in node) {
112110
// Handle a group
113-
registerTreeButtons(context, node.children);
111+
traverseAndRegisterTreeButtons(context, node.children);
114112
} else {
115113
// Handle a leaf (command). It may or may not have a button
116114
// definitions.
117115
if ("btn" in node) {
118-
log(`Registering button ${node.id}, priority ${node.btn.priority}`);
119-
116+
const priority = 100 - node.btn.position;
117+
log(
118+
`Registering button ${node.id}, position ${node.btn.position}, priority ${priority}`
119+
);
120120
const btn = vscode.window.createStatusBarItem(
121121
vscode.StatusBarAlignment.Left,
122-
node.btn.priority
122+
priority
123123
);
124124

125125
btn.command = node.id;
@@ -152,7 +152,7 @@ class ApioTreeProvider {
152152

153153
getChildren(element) {
154154
if (!element) {
155-
return traverseHierarchy(this.tree);
155+
return traverseAndConvertTree(this.tree);
156156
}
157157

158158
// Inside a group: return children
@@ -229,31 +229,6 @@ function execAction(commands, url) {
229229
};
230230
}
231231

232-
function registerTreeCommands(context, apio_folder, tree) {
233-
// Determine platform dependent command to change to the apio project dir.
234-
const cd_cmd = isWindows
235-
? `chdir /d "${apio_folder}"`
236-
: `cd "${apio_folder}"`;
237-
log(`cd_cmd: ${cd_cmd}`);
238-
239-
// Determine platform dependent command to clear the terminal.
240-
const clear_cmd = isWindows ? "cls" : "clear";
241-
log(`clear_cmd: ${clear_cmd}`);
242-
243-
const pre_cmds = [clear_cmd, cd_cmd];
244-
245-
// Register all commands from all trees
246-
traverseCommands(context, pre_cmds, tree);
247-
}
248-
249-
function registerTreeView(context, container_id, tree) {
250-
// Side view Apio command tree.
251-
const viewContainer = vscode.window.registerTreeDataProvider(
252-
container_id,
253-
new ApioTreeProvider(tree)
254-
);
255-
context.subscriptions.push(viewContainer);
256-
}
257232

258233
// Scans apio.ini and return list of env names.
259234
function extractApioIniEnvs(filePath) {
@@ -285,8 +260,12 @@ function extractApioIniEnvs(filePath) {
285260
}
286261
}
287262

263+
// Update the displaed of the env selector.
288264
function updateEnvSelector() {
289-
statusBarEnv.text = `$(selection) Env: ${currentEnv || ENV_DEFAULT}`;
265+
statusBarEnv.text =
266+
currentEnv && currentEnv != ENV_DEFAULT
267+
? `[env:${currentEnv}]`
268+
: ENV_DEFAULT;
290269
statusBarEnv.tooltip = "APIO: Select apio.ini env";
291270
}
292271

@@ -328,14 +307,31 @@ function activate(context) {
328307
isWindows = platform == "win32";
329308
log(`is windows: ${isWindows}`);
330309

310+
// Determines the commands that we prefix each apio command.
311+
const cd_cmd = isWindows
312+
? `chdir /d "${apio_folder}"`
313+
: `cd "${apio_folder}"`;
314+
log(`cd_cmd: ${cd_cmd}`);
315+
316+
// Determine platform dependent command to clear the terminal.
317+
const clear_cmd = isWindows ? "cls" : "clear";
318+
log(`clear_cmd: ${clear_cmd}`);
319+
320+
const pre_cmds = [clear_cmd, cd_cmd];
321+
331322
// Traverse the definition trees and register the commands.
332323
for (const tree of Object.values(defs.TREE_VIEWS)) {
333-
registerTreeCommands(context, apio_folder, tree);
324+
traverseAndRegisterCommands(context, pre_cmds, tree);
334325
}
335326

336-
// Traverse the definition trees and register the sidebar view entries.
327+
// Register the trees with their respective views.
337328
for (const [view_id, tree] of Object.entries(defs.TREE_VIEWS)) {
338-
registerTreeView(context, view_id, tree);
329+
// registerTreeView(context, view_id, tree);
330+
const viewContainer = vscode.window.registerTreeDataProvider(
331+
view_id,
332+
new ApioTreeProvider(tree)
333+
);
334+
context.subscriptions.push(viewContainer);
339335
}
340336

341337
// Construct the status bar 'Apio:' label
@@ -350,7 +346,7 @@ function activate(context) {
350346

351347
// Traverse the definition trees and register the status bar buttons.
352348
for (const tree of Object.values(defs.TREE_VIEWS)) {
353-
registerTreeButtons(context, tree);
349+
traverseAndRegisterTreeButtons(context, tree);
354350
}
355351

356352
// Load saved env or use default ""

media/screenshot1.png

17.8 KB
Loading

scripts/clear-apio-extension.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -x
22

3-
# Apio VS Code Extension: Uninstall + Full Cache Clear (macOS)
3+
# Apio VSCode Extension: Uninstall + Full Cache Clear (macOS)
44
# For local debugging only.
55

66
# Exit on first error
@@ -20,5 +20,5 @@ rm -rf ~/Library/Application\ Support/Code/CachedExtensions
2020
rm -rf ~/Library/Application\ Support/Code/CachedExtensionVSIXs
2121
rm -rf ~/Library/Application\ Support/Code/Code\ Cache
2222

23-
echo "Done. Restart VS Code, then reinstall your new .vsix:"
23+
echo "Done. Restart VSCode, then reinstall your new .vsix:"
2424
echo "code --install-extension apio-*.vsix"

scripts/verify-package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ npm install -g @vscode/vsce@latest
1010
#!/bin/bash
1111
#set -e
1212

13-
#echo "=== VS Code Marketplace Readiness Check ==="
13+
#echo "=== VSCode Marketplace Readiness Check ==="
1414

1515
# 1. Package with dry-run (validates everything the Marketplace checks)
1616
# vsce package --dry-run

0 commit comments

Comments
 (0)