@@ -81,6 +81,9 @@ function! arduino#InitializeConfig() abort
81
81
elseif g: arduino_use_cli && ! s: has_cli
82
82
echoerr ' arduino-cli: command not found'
83
83
endif
84
+ if ! exists (' g:arduino_telescope_enabled' )
85
+ let g: arduino_telescope_enabled = luaeval (" pcall(require, 'telescope')" )
86
+ endif
84
87
call arduino#ReloadBoards ()
85
88
endfunction
86
89
@@ -255,7 +258,7 @@ function! arduino#GetBoards() abort
255
258
let linesplit = split (line , ' =' )
256
259
let name = linesplit[1 ]
257
260
let board = meta.package . ' :' . meta.arch . ' :' . board
258
- if index (boards, board) == -1 && ! has_key (seen, board)
261
+ if ! has_key (seen, board)
259
262
let seen[board] = 1
260
263
call add (boards, {
261
264
\ ' label' : name,
@@ -337,17 +340,21 @@ function! arduino#GetProgrammers() abort
337
340
let programmers = []
338
341
if g: arduino_use_cli
339
342
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
349
354
endif
350
355
endif
356
+
357
+ let seen = {}
351
358
for [dir ,meta] in items (s: hardware_dirs )
352
359
if ! isdirectory (dir )
353
360
continue
@@ -361,9 +368,15 @@ function! arduino#GetProgrammers() abort
361
368
if line = ~? ' ^[^.]*\.name=.*$'
362
369
let linesplit = split (line , ' \.' )
363
370
let programmer = linesplit[0 ]
371
+ let linesplit = split (line , ' =' )
372
+ let name = linesplit[1 ]
364
373
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
+ \ })
367
380
endif
368
381
endif
369
382
endfor
@@ -396,7 +409,7 @@ function! arduino#ChoosePort(...) abort
396
409
if empty (ports)
397
410
echoerr " No likely serial ports detected!"
398
411
else
399
- call arduino#Choose (' Port' , ports, ' arduino#SelectPort' )
412
+ call arduino#Choose (' Select Port' , ports, ' arduino#SelectPort' )
400
413
endif
401
414
endfunction
402
415
@@ -415,7 +428,7 @@ function! arduino#ChooseBoard(...) abort
415
428
return
416
429
endif
417
430
let boards = arduino#GetBoards ()
418
- call arduino#Choose (' Arduino Board' , boards, ' arduino#SelectBoard' )
431
+ call arduino#Choose (' Select Board' , boards, ' arduino#SelectBoard' )
419
432
endfunction
420
433
421
434
" Callback from board selection. Sets the board and prompts for any options
@@ -428,7 +441,8 @@ function! arduino#SelectBoard(board) abort
428
441
\ ' opts' : {},
429
442
\ ' active_option' : ' ' ,
430
443
\}
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 ()})
432
446
endfunction
433
447
434
448
" Prompt user for the next unselected board option
@@ -459,7 +473,7 @@ function! arduino#ChooseProgrammer(...) abort
459
473
return
460
474
endif
461
475
let programmers = arduino#GetProgrammers ()
462
- call arduino#Choose (' Arduino Programmer' , programmers, ' arduino#SetProgrammer' )
476
+ call arduino#Choose (' Select Programmer' , programmers, ' arduino#SetProgrammer' )
463
477
endfunction
464
478
465
479
function ! arduino#SetProgrammer (programmer) abort
@@ -659,7 +673,9 @@ function! arduino#Choose(title, raw_items, callback) abort
659
673
endif
660
674
endfor
661
675
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
663
679
let ext_data = get (g: ctrlp_ext_vars , s: ctrlp_idx )
664
680
let ext_data.lname = a: title
665
681
let s: ctrlp_list = items
@@ -673,11 +689,10 @@ function! arduino#Choose(title, raw_items, callback) abort
673
689
\ ' options' : ' --prompt="' .a: title .' : "'
674
690
\ })
675
691
else
676
- let labels = s: ConvertItemsToLabels (items )
677
- call map (labels, {i , l - >
692
+ let labels = map (copy (items ), {i , v - >
678
693
\ i < 9
679
- \ ? ' ' .(i + 1 ).' ) ' .l
680
- \ : (i + 1 ).' ) ' .l
694
+ \ ? ' ' .(i + 1 ).' ) ' .v . label
695
+ \ : (i + 1 ).' ) ' .v . label
681
696
\ })
682
697
let labels = [" " . a: title ] + labels
683
698
let choice = inputlist (labels)
0 commit comments