Skip to content
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

Feature request: use sketch.json for per sketch fqbn and port #50

Closed
xenos1984 opened this issue Feb 22, 2022 · 4 comments
Closed

Feature request: use sketch.json for per sketch fqbn and port #50

xenos1984 opened this issue Feb 22, 2022 · 4 comments

Comments

@xenos1984
Copy link

Based on the sketch specification, one may add a file named sketch.json to a sketch folder, so set the board metadata (like fqbn and port) on a per sketch basis. This file can be created using the arduino-cli board attach command.

Would it be possible to use the settings from this file, if it is present, and the global g:arduino_* variables / ArduinoChoose* commands only in case that no such file exists? In particular:

  • When compiling / uploading, give command line arguments --fqbn and --port (using vim-arduino global settings) only if not given in the sketch.json.
  • Show board / port from sketch.json in the tag bar if present.

As another feature, would it be possible to call board attach to save such metadata, after selecting it with ArduinoChoose*, per sketch instead of globally (maybe as a new vim-arduino command or .vimrc option)?

I think this would be a helpful improvement if one is working on several sketches which are compiled for different board types / uploaded on different ports, so that there is no need to change these settings when switching to another sketch. Also it would use a settings format which is compatible with using plain arduino-cli on the command line.

@xenos1984 xenos1984 changed the title Feature request: use sketch.json for per sketch fqbn and part Feature request: use sketch.json for per sketch fqbn and port Feb 22, 2022
@stevearc
Copy link
Owner

Good idea! We now read from the sketch file and use that to set the board & port values. When a sketch file is present those values are not passed to the arduino-cli command. There's also a new ArduinoAttach command that will run arduino-cli board attach in the background. Lastly, ArduinoChooseBoard and ArduinoChoosePort will update the value in the sketch.json file, if it exists.

@xenos1984
Copy link
Author

I have tried the new feature, and as far as I can see, s:ReadSketchJson() is called at plugin initialization and when calling :ArduinoAttach, and it looks for sketch.json in the current working directory. However, this method apparently does not detect an already existing file, unless one runs arduino#InitializeConfig() with the working directory set to the sketch folder. Would it be possible to:

  • call s:ReadSketchJson() when entering a buffer with a .ino file,
  • search for the sketch.json in the folder of this .ino file?

@stevearc
Copy link
Owner

stevearc commented Mar 2, 2022

I've updated it to read the sketch file (if one exists) on BufReadPost for .ino files. Does that suit your purpose?

@xenos1984
Copy link
Author

Works perfectly now, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants