@@ -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