Issues with CLI and CCLS

I’m trying to get platformIO set up to work on an open-source project (meshtastic), and running into a few issues.

First of all, using the CLI to enumerate the available boards simply crashes with a python traceback:

$ pio boards
AssertionError: Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/platformio/__main__.py", line 103, in main
    cli()  # pylint: disable=no-value-for-parameter
    ~~~^^
  File "/usr/lib/python3.13/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.13/site-packages/platformio/cli.py", line 85, in invoke
    return super().invoke(ctx)
           ~~~~~~~~~~~~~~^^^^^
  File "/usr/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.13/site-packages/platformio/commands/boards.py", line 34, in cli
    for board in _get_boards(installed):
                 ~~~~~~~~~~~^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/platformio/commands/boards.py", line 75, in _get_boards
    return pm.get_installed_boards() if installed else pm.get_all_boards()
                                                       ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/platformio/package/manager/platform.py", line 124, in get_all_boards
    boards = self.get_installed_boards()
  File "/usr/lib/python3.13/site-packages/platformio/util.py", line 57, in wrapper
    self.cache[key] = (time.time(), func(*args, **kwargs))
                                    ~~~~^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/platformio/package/manager/platform.py", line 112, in get_installed_boards
    for config in p.get_boards().values():
                  ~~~~~~~~~~~~^^
  File "/home/sparrows/.platformio/platforms/raspberrypi/platform.py", line 161, in get_boards
    result[key] = self._add_default_debug_tools(result[key])
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/sparrows/.platformio/platforms/raspberrypi/platform.py", line 211, in _add_default_debug_tools
    assert openocd_target, ("Missing target configuration for %s" %
           ^^^^^^^^^^^^^^
AssertionError: Missing target configuration for me25ls01-4y10td

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `python -m pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq/index.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

I am on the latest pio version, with a fresh meshtastic clone, and seem to be the only person having this issue with meshtastic. This also breaks the board selection dialogue for IDEs.

My second issue is that using emacs with CCLS and the platformio-mode plugin, as recomended by pio docs, header files seemingly are misinterpreted as being C headers, rather then C++.


Note in the above screenshot, the error message must use 'enum' tag to refer to type 'class', indicating this is the case. I have done everything i can think of to resolve this issue, rebuilt the compile-commands.json and .ccls files, but nothing resolves it.

I have searched around but found no existing info related to either of my problems. Is there a known way to fix them?

That ME25LS01 module is nRF52 based. It does not need the raspberry pi platform.

Can you

rm -rf ~/.platformio/platforms/raspberrypi

to get rid of the offending platform?

Another fix would be to be find the offending me25ls01-4y10td.json file (find ~/.platformio -name me25ls01-4y10td.json) and add in the openocd target definition, i.e., change

into

  "debug": {
    "jlink_device": "nRF52840_xxAA",
    "svd_path": "nrf52840.svd",
    "openocd_target": "nrf52.cfg"
  },
1 Like

Your first suggestion did fix my first issue, thank you!

Would you happen to have any clue on the LSP issue as well?

I think I just tracked this issue down. In the .ccls file that is created by pio project init --ide emacs, the first line is clang and that is wrong. That is using the clang for the platform you are developing on. In my case, I changed this line to /Users/<user name>/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc.

My set up was working 99% but I had wierd complaints. So far, this has fixed all of them.

This means that

is wrong? Same for

That would be quite amazing if that has been wrong for literal years. But not saying that can’t be it.

Then you’ve correctly file an issue in

already.

To repeat, I’m very new to all of the embedded tools so please double check everything.

That being said, I’m confused now with pio run -t compiledb which produces compile_commands.json. To find #include <string.h> on my system, there needs to be an -I for .platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include. The .ccls has this but the compile_commands.json does not.

Oh but for that you have to turn on COMPILATIONDB_INCLUDE_TOOLCHAIN=True with an extra script. That is not on by default.

See documentation

https://docs.platformio.org/en/latest/integration/compile_commands.html

Why can’t this language server enumerate the include paths of the compiler once it knows the path to the compiler?

1 Like

Changing the first line of the .ccls file to gcc does not resolve the issue for me. I still get the same errors from CCLS, and when I list the buffers in the CCLS session it lists header file buffers as C (this is despite the corresponding emacs buffers being in c++ major mode, as they should).

also despite fixing the issues with the CLI, the platformio-mode tool still errors while trying to enumerate available boards with the platformio-boards command. From my investigation this appears to be a bug in the plugin itself, and I plan to file a bug report with that repo. However this is still quite problematic when that plugin is listed as the officially supported solution in the platformio docs.

I have generated the compile-commands.json file previously, as documented in the link provided by @maxgerhardt, but that did not result in any change to the LSP’s behavior.

I also just noticed that the aforementioned emacs plugin has not had any commits on its github in over 4 years, despite several open issues and pull requests. it’s quite alarming to me that this clearly abandoned project is still the official recommended solution for emacs integration

How did you build your .ccls file? I used pio project init --ide emacs

Also, for the compile_commands.json (isn’t it an underscore and not a dash / hyphan?) you need COMPILATIONDB_INCLUDE_TOOLCHAIN to be True.

Last… I have seen the exact error that you mention where class is not recognized but I haven’t seen it recently and I don’t recall precisely where / how I saw it.

Building the board list platformio-boards doesn’t work for me either. I use it just to build and load.

Good luck. I wish I could help more.

I built the .ccls the same way you did. I tried changing the first line of that generated file to gcc like you suggested, but had no luck. and yes, that’s the compile_commands file i meant.

specifically the error about class is not recognized indicates that CCLS is assuming that header files are C headers, rather then C++ headers. I assume this is related to the weirdness you’ve noted in .ccls file generation but having never used CCLS before trying to use it with pio, i wouldn’t even know where to begin troubleshooting it

This is my first real use of lsp-mode and ccls as well so its all new to me too. You keep saying “gcc” but is that what you put? I put the full path to the compiler that my project uses: .platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc

using the full path to the platformio-specific GCC binary does not work either. but gcc is also installed normally in my system and in my path. there’s no reason the language server should need a special GCC binary, even if one is needed for cross-compilation

Well if the Intellisense wants to be accurate it should 100% use the right GCC binary.

sizeof(int) is 4 on x86 GCC and 2 on AVR-GCC.

Some __builtin functions will exist for ARM but not XTensa.

Some things will always be compiler and architecture specific

I don’t know… I had an error when I was using clang that the “section” for attribute for mach-o needed two arguments. That’s because clang on my host (a Mac) produces mach-o files but the project is producing elf.

fair point. but regardless, this issue seems to persist regardless of which compiler binary is specified in the .ccls

at a loss for solutions, I tried using clangd instead of ccls. it correctly recognizes headers as C++. while it still seems confused about some of the includes, this is a vast improvement over the situation with ccls, so that’s what i’m gonna use for now.

in all, I would not recomend this workflow for emacs. however, given I am working on other people’s code and don’t have the option to use a different build system, it will have to do. I strongly recomend this project either work out the issues with emacs support, or stop listing emacs as a supported editor on your site.