@@ -34,13 +34,25 @@ import {
3434import { Logger } from "../../logger/logger" ;
3535import { OutputChannel } from "../../logger/outputChannel" ;
3636import { selectOpenOcdConfigFiles } from "../openOcd/boardConfiguration" ;
37- import { getTargetsFromEspIdf } from "./getTargets" ;
37+ import { getTargetsFromEspIdf , IdfTarget } from "./getTargets" ;
3838import { setTargetInIDF } from "./setTargetInIdf" ;
3939import { updateCurrentProfileIdfTarget } from "../../project-conf" ;
4040import { DevkitsCommand } from "./DevkitsCommand" ;
4141
4242export let isSettingIDFTarget = false ;
4343
44+ export interface ISetTargetQuickPickItems {
45+ label : string ;
46+ idfTarget ?: IdfTarget ;
47+ boardInfo ?: {
48+ location : string ;
49+ config_files : string [ ] ;
50+ } ;
51+ description ?: string ;
52+ isConnected ?: boolean ;
53+ kind ?: QuickPickItemKind ;
54+ }
55+
4456export async function setIdfTarget (
4557 placeHolderMsg : string ,
4658 workspaceFolder : WorkspaceFolder
@@ -73,30 +85,35 @@ export async function setIdfTarget(
7385 async ( progress : Progress < { message : string ; increment : number } > ) => {
7486 try {
7587 const targetsFromIdf = await getTargetsFromEspIdf ( workspaceFolder . uri ) ;
76- let connectedBoards : any [ ] = [ ] ;
88+ let connectedBoards : ISetTargetQuickPickItems [ ] = [ ] ;
7789
7890 const isDebugging = debug . activeDebugSession !== undefined ;
7991
8092 if ( ! isDebugging ) {
8193 try {
8294 const devkitsCmd = new DevkitsCommand ( workspaceFolder . uri ) ;
8395 const scriptPath = await devkitsCmd . getScriptPath ( ) ;
84-
96+
8597 if ( scriptPath ) {
8698 const devkitsOutput = await devkitsCmd . runDevkitsScript ( ) ;
8799 if ( devkitsOutput ) {
88100 const parsed = JSON . parse ( devkitsOutput ) ;
89101 if ( parsed && Array . isArray ( parsed . boards ) ) {
90- connectedBoards = parsed . boards . map ( ( b : any ) => ( {
91- label : b . name ,
92- target : b . target ,
93- description : b . description ,
94- detail : `Status: CONNECTED${
95- b . location ? ` Location: ${ b . location } ` : ""
96- } `,
97- isConnected : true ,
98- boardInfo : b ,
99- } ) ) ;
102+ connectedBoards = parsed . boards . map (
103+ ( b : any ) =>
104+ ( {
105+ label : b . name ,
106+ idfTarget : targetsFromIdf . find (
107+ ( t ) => t . target === b . target
108+ ) ,
109+ description : b . description ,
110+ detail : `Status: CONNECTED${
111+ b . location ? ` Location: ${ b . location } ` : ""
112+ } `,
113+ isConnected : true ,
114+ boardInfo : b ,
115+ } as ISetTargetQuickPickItems )
116+ ) ;
100117 }
101118 }
102119 } else {
@@ -115,26 +132,24 @@ export async function setIdfTarget(
115132 "Connected ESP-IDF devkit detection is skipped while debugging. You can still select a target manually."
116133 ) ;
117134 }
118- let quickPickItems : any [ ] = [ ] ;
119- if ( connectedBoards . length > 0 ) {
120- quickPickItems = [
121- ...connectedBoards ,
122- { kind : QuickPickItemKind . Separator , label : "Default Boards" } ,
123- ...targetsFromIdf . map ( ( t ) => ( {
124- label : t . label ,
125- target : t . target ,
126- description : t . isPreview ? "Preview target" : undefined ,
127- isConnected : false ,
128- } ) ) ,
129- ] ;
130- } else {
131- quickPickItems = targetsFromIdf . map ( ( t ) => ( {
135+ let quickPickItems : ISetTargetQuickPickItems [ ] = [ ] ;
136+ const defaultBoards : ISetTargetQuickPickItems [ ] = targetsFromIdf . map (
137+ ( t ) => ( {
132138 label : t . label ,
133- target : t . target ,
139+ idfTarget : t ,
134140 description : t . isPreview ? "Preview target" : undefined ,
135141 isConnected : false ,
136- } ) ) ;
137- }
142+ } )
143+ ) ;
144+
145+ quickPickItems =
146+ connectedBoards . length > 0
147+ ? [
148+ ...connectedBoards ,
149+ { kind : QuickPickItemKind . Separator , label : "Default Boards" } ,
150+ ...defaultBoards ,
151+ ]
152+ : defaultBoards ;
138153 const selectedTarget = await window . showQuickPick ( quickPickItems , {
139154 placeHolder : placeHolderMsg ,
140155 } ) ;
@@ -171,24 +186,24 @@ export async function setIdfTarget(
171186 } else {
172187 await selectOpenOcdConfigFiles (
173188 workspaceFolder . uri ,
174- selectedTarget . target
189+ selectedTarget . idfTarget . target
175190 ) ;
176191 }
177192
178- await setTargetInIDF ( workspaceFolder , selectedTarget ) ;
193+ await setTargetInIDF ( workspaceFolder , selectedTarget . idfTarget ) ;
179194 const customExtraVars = readParameter (
180195 "idf.customExtraVars" ,
181196 workspaceFolder
182197 ) as { [ key : string ] : string } ;
183- customExtraVars [ "IDF_TARGET" ] = selectedTarget . target ;
198+ customExtraVars [ "IDF_TARGET" ] = selectedTarget . idfTarget . target ;
184199 await writeParameter (
185200 "idf.customExtraVars" ,
186201 customExtraVars ,
187202 configurationTarget ,
188203 workspaceFolder . uri
189204 ) ;
190205 await updateCurrentProfileIdfTarget (
191- selectedTarget . target ,
206+ selectedTarget . idfTarget . target ,
192207 workspaceFolder . uri
193208 ) ;
194209 } catch ( err ) {
0 commit comments