@@ -81,6 +81,9 @@ function! arduino#InitializeConfig() abort
8181 elseif g: arduino_use_cli && ! s: has_cli
8282 echoerr ' arduino-cli: command not found'
8383 endif
84+ if ! exists (' g:arduino_telescope_enabled' )
85+ let g: arduino_telescope_enabled = luaeval (" pcall(require, 'telescope')" )
86+ endif
8487 call arduino#ReloadBoards ()
8588endfunction
8689
@@ -255,7 +258,7 @@ function! arduino#GetBoards() abort
255258 let linesplit = split (line , ' =' )
256259 let name = linesplit[1 ]
257260 let board = meta.package . ' :' . meta.arch . ' :' . board
258- if index (boards, board) == -1 && ! has_key (seen, board)
261+ if ! has_key (seen, board)
259262 let seen[board] = 1
260263 call add (boards, {
261264 \ ' label' : name,
@@ -337,17 +340,21 @@ function! arduino#GetProgrammers() abort
337340 let programmers = []
338341 if g: arduino_use_cli
339342 let data = s: get_json_output (' arduino-cli board details ' . g: arduino_board . ' --list-programmers --format json' )
340- for entry in data[' programmers' ]
341- call add (programmers, {
342- \ ' label' : entry[' name' ],
343- \ ' value' : entry[' id' ],
344- \ })
345- endfor
346- " I'm running into some issues with 3rd party boards (e.g. adafruit:avr:gemma) where the programmer list is empty. If so, fall back to the hardware directory method
347- if ! empty (programmers)
348- return sort (programmers, ' s:ChooserItemOrder' )
343+ if has_key (data, ' programmers' )
344+ for entry in data[' programmers' ]
345+ call add (programmers, {
346+ \ ' label' : entry[' name' ],
347+ \ ' value' : entry[' id' ],
348+ \ })
349+ endfor
350+ " I'm running into some issues with 3rd party boards (e.g. adafruit:avr:gemma) where the programmer list is empty. If so, fall back to the hardware directory method
351+ if ! empty (programmers)
352+ return sort (programmers, ' s:ChooserItemOrder' )
353+ endif
349354 endif
350355 endif
356+
357+ let seen = {}
351358 for [dir ,meta] in items (s: hardware_dirs )
352359 if ! isdirectory (dir )
353360 continue
@@ -361,9 +368,15 @@ function! arduino#GetProgrammers() abort
361368 if line = ~? ' ^[^.]*\.name=.*$'
362369 let linesplit = split (line , ' \.' )
363370 let programmer = linesplit[0 ]
371+ let linesplit = split (line , ' =' )
372+ let name = linesplit[1 ]
364373 let prog = meta.package . ' :' . programmer
365- if index (programmers, prog) == -1
366- call add (programmers, prog)
374+ if ! has_key (seen, prog)
375+ let seen[prog] = 1
376+ call add (programmers, {
377+ \ ' label' : name,
378+ \ ' value' : prog
379+ \ })
367380 endif
368381 endif
369382 endfor
@@ -396,7 +409,7 @@ function! arduino#ChoosePort(...) abort
396409 if empty (ports)
397410 echoerr " No likely serial ports detected!"
398411 else
399- call arduino#Choose (' Port' , ports, ' arduino#SelectPort' )
412+ call arduino#Choose (' Select Port' , ports, ' arduino#SelectPort' )
400413 endif
401414endfunction
402415
@@ -415,7 +428,7 @@ function! arduino#ChooseBoard(...) abort
415428 return
416429 endif
417430 let boards = arduino#GetBoards ()
418- call arduino#Choose (' Arduino Board' , boards, ' arduino#SelectBoard' )
431+ call arduino#Choose (' Select Board' , boards, ' arduino#SelectBoard' )
419432endfunction
420433
421434" Callback from board selection. Sets the board and prompts for any options
@@ -428,7 +441,8 @@ function! arduino#SelectBoard(board) abort
428441 \ ' opts' : {},
429442 \ ' active_option' : ' ' ,
430443 \}
431- call arduino#ChooseBoardOption ()
444+ " Have to delay this to give the previous chooser UI time to clear
445+ call timer_start (10 , {tid - > arduino#ChooseBoardOption ()})
432446endfunction
433447
434448" Prompt user for the next unselected board option
@@ -459,7 +473,7 @@ function! arduino#ChooseProgrammer(...) abort
459473 return
460474 endif
461475 let programmers = arduino#GetProgrammers ()
462- call arduino#Choose (' Arduino Programmer' , programmers, ' arduino#SetProgrammer' )
476+ call arduino#Choose (' Select Programmer' , programmers, ' arduino#SetProgrammer' )
463477endfunction
464478
465479function ! arduino#SetProgrammer (programmer) abort
@@ -659,7 +673,9 @@ function! arduino#Choose(title, raw_items, callback) abort
659673 endif
660674 endfor
661675
662- if g: arduino_ctrlp_enabled
676+ if g: arduino_telescope_enabled
677+ call luaeval (" require('arduino.telescope').choose('" .a: title ." ', _A, '" .a: callback ." ')" , items )
678+ elseif g: arduino_ctrlp_enabled
663679 let ext_data = get (g: ctrlp_ext_vars , s: ctrlp_idx )
664680 let ext_data.lname = a: title
665681 let s: ctrlp_list = items
@@ -673,11 +689,10 @@ function! arduino#Choose(title, raw_items, callback) abort
673689 \ ' options' : ' --prompt="' .a: title .' : "'
674690 \ })
675691 else
676- let labels = s: ConvertItemsToLabels (items )
677- call map (labels, {i , l - >
692+ let labels = map (copy (items ), {i , v - >
678693 \ i < 9
679- \ ? ' ' .(i + 1 ).' ) ' .l
680- \ : (i + 1 ).' ) ' .l
694+ \ ? ' ' .(i + 1 ).' ) ' .v . label
695+ \ : (i + 1 ).' ) ' .v . label
681696 \ })
682697 let labels = [" " . a: title ] + labels
683698 let choice = inputlist (labels)
0 commit comments