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

Vim (neovim): clangd and ccls gives errors with esp32s3box #1063

Closed
Tloe opened this issue Mar 5, 2023 · 12 comments
Closed

Vim (neovim): clangd and ccls gives errors with esp32s3box #1063

Tloe opened this issue Mar 5, 2023 · 12 comments
Labels

Comments

@Tloe
Copy link

Tloe commented Mar 5, 2023

Linux (manjaro)
PlatformIO Core, version 6.1.7a3

Platform IO builds and uploads the project just fine, but in vim (neovim) I get some errors. I've tried both with clangd and ccls.

This is with clangd, I can use goto defenitions and go to function defenitions:
image

With ccls I get a lot of these errors when I use compile_commands.json and no errors with just the .ccls file from pio project init. No errors are actually shown in the code and I cannot use goto defenitions shortcuts so it dosn't seem to work properly:

LSP[ccls]: Error NO_RESULT_CALLBACK_FOUND: {                                                                                                                                                                                                                                                                                    
  error = {                                                                                                                                                                                                                                                                                                                     
    code = -32603,                                                                                                                                                                                                                                                                                                              
    message = "failed to index /home/t/.platformio/packages/framework-arduinoespressif32/cores/esp32/FunctionalInterrupt.cpp"                                                                                                                                                                                                   
  },                                                                                                                                                                                                                                                                                                                            
  id = 1,                                                                                                                                                                                                                                                                                                                       
  jsonrpc = "2.0"  

With this platformio.ini:

[env]
build_flags =
    -D DEBUG=1
lib_deps =
	me-no-dev/AsyncTCP@^1.1.1
	me-no-dev/ESP Async WebServer@^1.2.3
extra_scripts = pre:files/www/process.py
framework = arduino
platform = espressif32
monitor_speed = 115200

[env:esp32s3box]
board = esp32s3box
board_build.partitions = default_16MB.csv
board_build.variant = esp32s3

I run (I have also tried to generated compile_commands.json with bear but getting the same there):
pio project init --ide vim --board esp32s3box
pio run --target compiledb

This is my clangd setup (The --query-driver doesnt seem to do much):

require 'lspconfig'.clangd.setup {
  capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
  cmd = {
    "clangd",
    "--background-index",
    "--query-driver=/home/t/.platformio/packages/toolchain-xtensa-esp32s3/bin/xtensa-esp32s3-elf-gcc"
  },
  on_attach = on_attach,
  filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
}

This is my ccls setup:

require 'lspconfig'.ccls.setup {
  init_options = {
    index = {
      threads = 0;
    };
    clang = {
      excludeArgs = { "-frounding-math"} ;
    };
  }
}

I have also tried to follow these steps (this post is rather old though), but with the changes below using the platformio xtensa toolchain.:
espressif/esp-idf#6721 (comment)

CompileFlags:
  Add: [-mlong-calls, -ferror-limit=0, -isysroot=/home/t/.platformio/packages/toolchain-xtensa-esp32s3]
  Remove: [-fno-tree-switch-conversion, -mtext-section-literals, -mlongcalls, -fstrict-volatile-bitfields]

image

@Tloe
Copy link
Author

Tloe commented Mar 5, 2023

I tried to setup a plain teensy project and it works fine there so seem to be a issue with espressif?

@Tloe
Copy link
Author

Tloe commented Mar 6, 2023

I got it working with clangd :)

Changing the query driver to this:
"--query-driver=/home/t/.platformio/packages/toolchain-xtensa-esp32s3/bin/xtensa-esp32s3-elf-gcc*"

And I need the espressif clang version and .clangd file from the issue I linked above

@ivankravets ivankravets transferred this issue from platformio/platformio-core Mar 29, 2023
@stale
Copy link

stale bot commented May 1, 2023

This issue has been automatically marked as stale because it has not had recent activity. Please provide more details or it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 1, 2023
@stale stale bot closed this as completed May 8, 2023
@Tloe
Copy link
Author

Tloe commented May 29, 2023

This is still an issue so should not be closed.

@Axel-ex
Copy link

Axel-ex commented Mar 15, 2024

Having the same problem here, could you actually fix your problem? Thanks!

@TristanWebber
Copy link

I'm also having this issue, specifically for the esp32s3 and the arduino framework.

I have clangd working well for esp32 and esp32c3, and I'm achieving that by setting the --query-driver to point to the relevant toolchain in clangd.setup, and adjusting some other flags in a .clangd file in the project. Everything also works well for the esp32s3 in an espidf project. This same approach is not working for the esp32s3 in an Arduino project.

It looks like either the compile_commands.json commands are not correct, or clangd is not able to parse those commands.

Has anyone found the root of the problem, and a solution for this?

@Tloe
Copy link
Author

Tloe commented Jun 27, 2024

This python script fixes it for me. :) As you wrote, the compile_commands need the full path

import shutil
import os

with open('compile_commands.json', 'r') as file :
  filedata = file.read()

filedata = filedata.replace('xtensa-esp32s3-elf-g++', os.path.expanduser('~') + '/.platformio/packages/toolchain-xtensa-esp32s3/bin/xtensa-esp32s3-elf-g++')
filedata = filedata.replace('xtensa-esp32s3-elf-gcc', os.path.expanduser('~') + '/.platformio/packages/toolchain-xtensa-esp32s3/bin/xtensa-esp32s3-elf-gcc')

with open('compile_commands.json', 'w') as file:
  file.write(filedata)

@TristanWebber
Copy link

Thanks for the tip @Tloe but that one hasn't solved it in my case for the s3 :(. To be fair, the LSP is mostly working really well, but it's the errors I'm getting for Arduino functions that I can't seem to get rid of.

Do you mind sharing what you have in your .clangd and clangd.setup to make this one work?

image
image

@Tloe
Copy link
Author

Tloe commented Jun 27, 2024

I don't have a clangd.setup

clangd:

CompileFlags:
  Add: [-mlong-calls, -ferror-limit=0, -isysroot=/home/t/.platformio/packages/toolchain-xtensa-esp32s3]
  Remove: [-fno-tree-switch-conversion, -mtext-section-literals, -mlongcalls, -fstrict-volatile-bitfields]

@Tloe
Copy link
Author

Tloe commented Jun 27, 2024

oh sorry.. been a while since I set this up.. thought clangd.setup was a file :p


require 'lspconfig'.clangd.setup {
  capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
  on_attach = on_attach,
  cmd = {
--    "/usr/local/bin/clangd",
    "/home/t/dev/llvm-project-xtensa/build/bin/clangd",
    "--background-index",
    "--query-driver=/home/t/.platformio/packages/toolchain-xtensa-esp32s3/bin/xtensa-esp32s3-elf-g*",
  },
  filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
}

@Tloe
Copy link
Author

Tloe commented Jun 27, 2024

/home/t/dev/llvm-project-xtensa/ is a build of the patched version that I linked to in the first post..

@TristanWebber
Copy link

Perfect, thanks for that - that will be the missing piece of the puzzle. Otherwise, everything else is equivalent. I appreciate the help!

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

No branches or pull requests

3 participants