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

How to set a project specific board-name #80

Open
listout opened this issue Sep 11, 2021 · 6 comments
Open

How to set a project specific board-name #80

listout opened this issue Sep 11, 2021 · 6 comments
Assignees

Comments

@listout
Copy link

listout commented Sep 11, 2021

Looking at the --help command of the LS, it tells that we can change the -board-name variable using or the -fqbn variable using JSON-RPC. I'm not sure how to do this.

It would be extremely helpful if any maintainer/contributor could provide an example.

@listout
Copy link
Author

listout commented Sep 11, 2021

Also if I change the board-name or -fqbn manually, completion seems to stop working. I have tested this with the ESP32 boards, as soon as I change the -board-name or the -fqbn variable, completion stops working.

I'm on vim, using the coc.nvim pluging. My configuration for the server was;

		"arduino": {
			"command": "~/.local/bin/arduino-language-server",
			"rootPatterns": [
				"*.ino"
			],
			"filetypes": [
				"arduino"
			],
			"args": [
				"-cli",
				"arduino-cli",
				"-cli-config",
				"~/.arduino15/arduino-cli.yaml",
				"-clangd",
				"clangd",
				"-board-name",
				"ESP32 Dev Module",
				"-fqbn",
				"esp32:esp32:esp32"
			]
		}

@Woocash9
Copy link

I'm in the same situation, though I'm not using coc but nvim native lsp implementation.
When I set manually -fqbn in the setup, completion works without any problem (first completion is quite slow as lsp-server is compiling sketch with arduino-cli to produce compilation-database, after that all works fine).
Obviously it wood be far better to be able to change the board interactively. I have spent last 2 hours analyzing the code and it looks like there is no such possibility at the moment (despite what is stated in the --help message).
I will try to implement this functionality tomorrow. Will let you know if it works.

@RadekRojik
Copy link

The same problem

@S4deghN
Copy link

S4deghN commented Feb 12, 2022

Running arduino-cli board attach [fqbn] in the root directory of your project auto generated sketch.json which works and simply contains:

{
  "cpu": {
    "fqbn": "[fqbn]",
    "port": ""
  }
}

I'm using nvim-lsp and I've installed the lsp via LspInstaller, don't know if that makes a difference.

@bradcush
Copy link

bradcush commented Jun 11, 2022

I'm using nvim-lsp and I've installed the lsp via LspInstaller, don't know if that makes a difference.

I'm using Neovim LSP and have installed arduino-language-server using go install as well as built it directly from source and can confirm that the presense of the sketch.json allows you to ignore this flag when starting the language server. There is nothing special regarding setup using LspInstaller that is required to make this work. I'm not specifying the -board-name flag anywhere either and all language server features are working.

Taken from the project README.md, omitting the -fqbn flag:

./arduino-language-server \
 -clangd /usr/local/bin/clangd \
 -cli /usr/local/bin/arduino-cli \
 -cli-config $HOME/.arduino15/arduino-cli.yaml

@alessio-perugini
Copy link
Contributor

alessio-perugini commented Aug 5, 2023

👋 We dropped support for sketch.json in favor of sketch.yaml.
If in your path you have the sketch.yaml, and you have defined default_fqbn: your_fqbn it will be automatically picked up, without needing to specify the -fqbn flag in the arduino-language-server.

For the one using neovim that wants to do some magic 🪄 , you can script a bit like:

require'lspconfig'.arduino_language_server.setup{
    on_new_config = function(config, root_dir)
        local file = io.open(root_dir .. '/sketch.yaml', "r")
        if file == nil then
            return
        end

        local fqbn = "arduino:avr:uno"
        local lines = file:lines()
        for line in lines do
            if string.find(line, "fqbn") then
                fqbn = string.gsub(line, "%s+fqbn:%s", "")
            end
        end

        file:close()

        config.cmd = {
            "arduino-language-server",
            "-fqbn", fqbn,
        }
    end,
    cmd = {
        "arduino-language-server",
        "-fqbn", "arduino:avr:uno",
    }
}
sketch.yaml

profiles:
  portenta_c33:
    fqbn: arduino:renesas_portenta:portenta_c33
    platforms:
      - platform: arduino:renesas_portenta (1.0.2)

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

7 participants