Skip to content

Commit f3304d1

Browse files
committed
WIP
1 parent 8977cf0 commit f3304d1

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-tinygo",
33
"displayName": "TinyGo",
4-
"version": "0.2.0",
4+
"version": "0.3.0-dev1",
55
"publisher": "tinygo",
66
"description": "TinyGo support for Visual Studio Code",
77
"license": "BSD-3-Clause",
@@ -28,7 +28,17 @@
2828
"command": "vscode-tinygo.selectTarget",
2929
"title": "TinyGo target"
3030
}
31-
]
31+
],
32+
"configuration": {
33+
"title": "TinyGo Configuration",
34+
"properties": {
35+
"tinygo.openocdInterface": {
36+
"description": "which hardware programmer to use (ex: jlink, cmsis-dap, stlink-v2, ...)",
37+
"type": "string",
38+
"default": "cmsis-dap"
39+
}
40+
}
41+
}
3242
},
3343
"scripts": {
3444
"compile": "tsc -p ./",

src/extension.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,20 @@ export async function activate(context: vscode.ExtensionContext) {
8686

8787
try {
8888
const execFile = util.promisify(cp.execFile);
89-
const {stdout, stderr} = await execFile('tinygo', ['env', 'TINYGOROOT']);
89+
const { stdout, stderr } = await execFile('tinygo', ['env', 'TINYGOROOT']);
9090
tinygoroot = stdout.trimRight()
91-
} catch(err) {
91+
} catch (err) {
9292
vscode.window.showErrorMessage(`Could not run 'tinygo env TINYGOROOT':\n` + err);
9393
return;
9494
}
9595

9696
try {
97+
openocdInterface = vscode.workspace.getConfiguration('tinygo')['openocdInterface'];
98+
9799
const execFile = util.promisify(cp.execFile);
98-
const {stdout, stderr} = await execFile('tinygo', ['build', '-json', '-target', target, '-o', 'out.elf', '-programmer', 'cmsis-dap']);
100+
const { stdout, stderr } = await execFile('tinygo', ['build', '-json', '-target', target, '-o', 'out.elf', '-programmer', openocdInterface]);
99101
let buildInfo = JSON.parse(stdout);
100102

101-
if (buildInfo.Options.Programmer) {
102-
openocdInterface = buildInfo.Options.Programmer;
103-
}
104103
if (buildInfo.Target['openocd-target']) {
105104
openocdTarget = buildInfo.Target['openocd-target'];
106105
}
@@ -121,7 +120,7 @@ export async function activate(context: vscode.ExtensionContext) {
121120
}
122121
}
123122
})
124-
} catch(err) {
123+
} catch (err) {
125124
vscode.window.showErrorMessage(`Could not run 'tinygo build -json -target ${target}':\n` + err);
126125
}
127126
}
@@ -186,30 +185,35 @@ export async function activate(context: vscode.ExtensionContext) {
186185
{
187186
// tasks.json configuration
188187
const tasksConfig = vscode.workspace.getConfiguration('tasks');
189-
if (!tasksConfig['tasks']) {
190-
}
191-
const configurations = tasksConfig['tasks'];
192-
let found = false
193-
for (var i in configurations) {
194-
let cfg = configurations[i];
195-
if (cfg.label == 'tinygo build task') {
196-
found = true;
188+
const task = {
189+
"label": "tinygo build task",
190+
"type": "shell",
191+
"command": "tinygo build -o ${env:TMP}/out.elf -target ${config:go.toolsEnvVars.TARGET} -size short -opt 1 ${config:go.toolsEnvVars.TargetPkg}",
192+
"problemMatcher": [],
193+
"group": {
194+
"kind": "build",
195+
"isDefault": true
197196
}
198-
}
199-
if (!found) {
200-
configurations.push({
201-
"label": "tinygo build task",
202-
"type": "shell",
203-
"command": "tinygo build -o ${env:TMP}/out.elf -target ${config:go.toolsEnvVars.TARGET} -size short -opt 1 ${config:go.toolsEnvVars.TargetPkg}",
204-
"problemMatcher": [],
205-
"group": {
206-
"kind": "build",
207-
"isDefault": true
208-
}
209-
});
210-
tasksConfig.update('tasks', configurations, false).then(() =>
197+
};
198+
if (!tasksConfig['tasks']) {
199+
tasksConfig.update('tasks', [task]).then(() =>
211200
vscode.window.showInformationMessage('Added tinygo configuration to tasks.json!')
212201
);
202+
} else {
203+
let configurations = tasksConfig['tasks'];
204+
let found = false
205+
for (var i in configurations) {
206+
let cfg = configurations[i];
207+
if (cfg.label == 'tinygo build task') {
208+
found = true;
209+
}
210+
}
211+
if (!found) {
212+
configurations.push(task);
213+
tasksConfig.update('tasks', configurations, false).then(() =>
214+
vscode.window.showInformationMessage('Added tinygo configuration to tasks.json!')
215+
);
216+
}
213217
}
214218
}
215219

0 commit comments

Comments
 (0)