Skip to content

Commit bf371b9

Browse files
committed
fix: read sketch.json in BufReadPost (stevearc#50)
1 parent 698bfcc commit bf371b9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

autoload/arduino.vim

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ else
2121
endif
2222
let s:hardware_dirs = {}
2323
let s:SKETCHFILE = v:null
24-
python3 import json
2524

2625
" Initialization {{{1
2726
" Set up all user configuration variables
@@ -83,7 +82,11 @@ function! arduino#InitializeConfig() abort
8382
echoerr 'arduino-cli: command not found'
8483
endif
8584
call arduino#ReloadBoards()
86-
call s:ReadSketchJson()
85+
call s:ReadSketchJson(expand('%:p:h'))
86+
aug ArduinoReadSketch
87+
au!
88+
au BufReadPost *.ino call s:ReadSketchJson(expand('<amatch>:p:h'))
89+
aug END
8790
endfunction
8891

8992
function! arduino#RunCmd(cmd) abort
@@ -433,8 +436,9 @@ function! arduino#Attach(...) abort
433436
let port = v:null
434437
if a:0
435438
let port = a:1
436-
function PostAttach() abort
437-
call s:ReadSketchJson()
439+
let dir = expand('%:p:h')
440+
function PostAttach() closure
441+
call s:ReadSketchJson(dir)
438442
call s:notify('Arduino attached to board ' . g:arduino_board)
439443
endfunction
440444
call arduino#job#run(['arduino-cli', 'board', 'attach', '-p', port], funcref('PostAttach'))
@@ -664,8 +668,8 @@ endfunction
664668

665669
" Utility functions {{{1
666670

667-
function! s:ReadSketchJson() abort
668-
let dir = getcwd()
671+
function! s:ReadSketchJson(dir) abort
672+
let dir = a:dir
669673
while v:true
670674
let sketch = dir . '/sketch.json'
671675
if filereadable(sketch)

0 commit comments

Comments
 (0)