Skip to content

Added Windows support #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions autoload/arduino.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ endif
let g:loaded_arduino_autoload = 1
let s:has_cli = executable('arduino-cli') == 1
if has('win64') || has('win32') || has('win16')
echoerr 'vim-arduino does not support windows :('
finish
let s:OS = 'Windows'
else
let s:OS = substitute(system('uname'), '\n', '', '')
endif
let s:HERE = resolve(expand('<sfile>:p:h:h'))
let s:OS = substitute(system('uname'), '\n', '', '')
" In neovim, run the shell commands using :terminal to preserve interactivity
if has('nvim')
let s:TERM = 'botright split | terminal! '
Expand Down Expand Up @@ -47,6 +47,11 @@ function! arduino#InitializeConfig() abort
endif
if !exists('g:arduino_serial_cmd')
let g:arduino_serial_cmd = 'screen {port} {baud}'
if s:OS ==? 'Windows'
let g:arduino_serial_cmd = 'arduino-cli monitor -p {port} --config baudrate={baud}'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the arduino-cli supports reading the serial output now, we should just use this as the new default (provided s:has_cli)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is supported. In fact, I didn't know it wasn't supported before. I think it is a good idea to use it as default.

else
let g:arduino_serial_cmd = 'screen {port} {baud}'
endif
endif
if !exists('g:arduino_build_path')
let g:arduino_build_path = '{project_dir}/build'
Expand Down Expand Up @@ -195,8 +200,8 @@ function! arduino#GetBuildPath() abort
return ''
endif
let l:path = g:arduino_build_path
let l:path = substitute(l:path, '{file}', expand('%:p'), 'g')
let l:path = substitute(l:path, '{project_dir}', expand('%:p:h'), 'g')
let l:path = substitute(l:path, '{file}', substitute(expand('%:p'), '\', '/', 'g'), 'g')
let l:path = substitute(l:path, '{project_dir}', substitute(expand('%:p:h'), '\', '/', 'g'), 'g')
Comment on lines +198 to +199
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what you mean when you say the nested substitutes are not working? What specifically isn't working about them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for the confusion. Nested substitutions work fine. I will write another message about what is working as I not expecting.

I used this hack to make it work on Windows. I don't know why any path on Windows is composed using backslashes. Without changing slashes topmost substitute interpreted '\U' sequence as a trigger to make the next characters UPPERCASE. But on Windows path quite often starts with the C:/User/<username> prefix. That broke compiling and uploading.

return l:path
endfunction

Expand Down Expand Up @@ -648,6 +653,12 @@ function! arduino#GetPorts() abort
call add(ports, port)
endfor
endfor
if s:OS ==? 'Windows'
let found = split(system('pwsh -nop -c "arduino-cli board list | Select-String -Pattern \"^(COM\d) \" | ForEach-Object { $_.Matches.Value }"'), '\n')
for port in found
call add(ports, port)
endfor
endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer if you could call arduino-cli directly so it doesn't rely on powershell. Do the ports appear in the json data if you run it like we do here?

let boards_data = json_decode(system('arduino-cli board listall --format json'))

If not, you could still just call arduino-cli board list and the extract the information you want using matchlist().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. I'm gonna change it.

return ports
endfunction

Expand Down Expand Up @@ -741,6 +752,8 @@ function! arduino#GetArduinoHomeDir() abort
endif
if s:OS ==? 'Darwin'
return $HOME . '/Library/Arduino15'
elseif s:OS ==? 'Windows'
return $HOME . '/AppData/Local/Arduino15'
endif

return $HOME . '/.arduino15'
Expand Down