arduino / arduino-language-server

An Arduino Language Server based on Clangd to Arduino code autocompletion
GNU Affero General Public License v3.0
117 stars 11 forks source link

[nvim + arduino-language-server]: Clang-related error #152

Closed oliverswitzer closed 1 year ago

oliverswitzer commented 1 year ago

Describe the problem

Hi,

I am seeing some odd logs that I can't quite make sense of that seem related to communication happening between arduino-language-server and my local clang install:

I am using nvim + nvim-config + lsp-installer to try and get arduino-language-server working for my local nvim setup.

When opening a file titled fibonacci.ino (a blank arduino file), I see the following output in the logs (I have turned on LSP tracing). There is additional output, but didn't want to post a wall of text, but let me know if you'd like to see more:

lsp.log:

...
[DEBUG][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:365    "rpc.send"      {  id = 1,  jsonrpc = "2.0",  method = "initialize",  params = {    capabilities = {      callHierarchy = {        dynamicRegistration = false      },      textDocument = {        codeAction = {          codeActionLiteralSupport = {            codeActionKind = {              valueSet = { "", "Empty", "QuickFix", "Refactor", "RefactorExtract", "RefactorInline", "RefactorRewrite", "Source", "SourceOrganizeImports", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" }            }          },          dataSupport = true,          dynamicRegistration = false,          isPreferredSupport = true,          resolveSupport = {            properties = { "edit" }          }        },        completion = {          completionItem = {            commitCharactersSupport = false,            deprecatedSupport = false,            documentationFormat = { "markdown", "plaintext" },            preselectSupport = false,            snippetSupport = false          },          completionItemKind = {            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }          },          contextSupport = false,          dynamicRegistration = false        },        declaration = {          linkSupport = true        },        definition = {          linkSupport = true        },        documentHighlight = {          dynamicRegistration = false        },        documentSymbol = {          dynamicRegistration = false,          hierarchicalDocumentSymbolSupport = true,          symbolKind = {            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }          }        },        hover = {          contentFormat = { "markdown", "plaintext" },          dynamicRegistration = false        },        implementation = {          linkSupport = true        },        publishDiagnostics = {          relatedInformation = true,          tagSupport = {            valueSet = { 1, 2 }          }        },        references = {          dynamicRegistration = false        },        rename = {          dynamicRegistration = false,          prepareSupport = true        },        signatureHelp = {          dynamicRegistration = false,          signatureInformation = {            activeParameterSupport = true,            documentationFormat = { "markdown", "plaintext" },            parameterInformation = {              labelOffsetSupport = true            }          }        },        synchronization = {          didSave = true,          dynamicRegistration = false,          willSave = false,          willSaveWaitUntil = false        },        typeDefinition = {          linkSupport = true        }      },      window = {        showDocument = {          support = false        },        showMessage = {          messageActionItem = {            additionalPropertiesSupport = false          }        },        workDoneProgress = true      },      workspace = {        applyEdit = true,        configuration = true,        symbol = {          dynamicRegistration = false,          hierarchicalWorkspaceSymbolSupport = true,          symbolKind = {            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }          }        },        workspaceEdit = {          resourceOperations = { "rename", "create", "delete" }        },        workspaceFolders = true      }    },    clientInfo = {      name = "Neovim",      version = "0.8.0"    },    initializationOptions = vim.empty_dict(),    processId = 74770,    rootPath = "/Users/oliverswitzer/workspace/arduino-playground",    rootUri = "file:///Users/oliverswitzer/workspace/arduino-playground",    trace = "off",    workspaceFolders = { {        name = "/Users/oliverswitzer/workspace/arduino-playground",        uri = "file:///Users/oliverswitzer/workspace/arduino-playground"      } }  }}
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.490985 clangd found at /usr/bin/clangd\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.491683 \27[97mLS: : Initial board configuration: arduino:avr:nano\27[0m\n20:59:50.491687 \27[97mLS: : arduino-language-server Version: 0.0.0-git Commit:  Date: \27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.491694 \27[97mLS: : Language server build path: /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server486595322\27[0m\n20:59:50.491699 \27[97mLS: : Language server build sketch root: /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server486595322/sketch\27[0m\n20:59:50.491701 \27[97mLS: : Language server FULL build path: /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server207618810\27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.492205 IN Elapsed: 15.708µs\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.492540 \27[92mIDE --> LS REQU initialize 1\27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.493056 \27[92m                initialize 1: \27[93mwrite-locked\27[0m\27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.493147 \27[92m                initialize 1: \27[93mwrite-unlocked\27[0m\27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.493188 \27[96mINIT --- : initializing workbench: file:///Users/oliverswitzer/workspace/arduino-playground\27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.493401 \27[92m                initialize 1: initialization parameters: {\"capabilities\":{\"textDocumentSync\":{\"openClose\":true,\"change\":2,\"save\":{\"includeText\":true}},\"completionProvider\":{\"triggerCharacters\":[\".\",\"\\u003c\",\"\\u003e\",\":\",\"\\\"\",\"/\"],\"allCommitCharacters\":[\" \",\"\\t\",\"(\",\")\",\"[\",\"]\",\"{\",\"}\",\"\\u003c\",\"\\u003e\",\":\",\";\",\",\",\"+\",\"-\",\"/\",\"*\",\"%\",\"^\",\"\\u0026\",\"#\",\"?\",\".\",\"=\",\"\\\"\",\"'\",\"|\"],\"completionItem\":{}},\"hoverProvider\":{},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\",\"]},\"definitionProvider\":{},\"documentHighlightProvider\":{},\"documentSymbolProvider\":{},\"codeActionProvider\":{\"codeActionKinds\":[\"quickfix\",\"refactor\",\"info\"]},\"documentFormattingProvider\":{},\"documentRangeFormattingProvider\":{},\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"\\n\"},\"renameProvider\":{},\"executeCommandProvider\":{\"commands\":[\"clangd.applyFix\",\"clangd.applyTweak\"]},\"workspaceSymbolProvider\":{}},\"serverInfo\":{\"name\":\"arduino-language-server\",\"version\":\"0.0.0-git\"}}\27[0m\n"
[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.493409 \27[32mIDE <-- LS RESP initialize 1\27[0m\n20:59:50.493436 \27[96mINIT --- : \27[93mread-locked\27[0m\27[0m\n20:59:50.493440 \27[96mINIT --- : \27[93mread-unlocked\27[0m\27[0m\n20:59:50.493437 OUT Elapsed: 5.458µs\n"
[DEBUG][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:474    "rpc.receive"   {  id = 1,  jsonrpc = "2.0",  result = {    capabilities = {      codeActionProvider = {        codeActionKinds = { "quickfix", "refactor", "info" }      },      completionProvider = {        allCommitCharacters = { " ", "\t", "(", ")", "[", "]", "{", "}", "<", ">", ":", ";", ",", "+", "-", "/", "*", "%", "^", "&", "#", "?", ".", "=", '"', "'", "|" },        completionItem = vim.empty_dict(),        triggerCharacters = { ".", "<", ">", ":", '"', "/" }      },      definitionProvider = vim.empty_dict(),      documentFormattingProvider = vim.empty_dict(),      documentHighlightProvider = vim.empty_dict(),      documentOnTypeFormattingProvider = {        firstTriggerCharacter = "\n"      },      documentRangeFormattingProvider = vim.empty_dict(),      documentSymbolProvider = vim.empty_dict(),      executeCommandProvider = {        commands = { "clangd.applyFix", "clangd.applyTweak" }      },      hoverProvider = vim.empty_dict(),      renameProvider = vim.empty_dict(),      signatureHelpProvider = {        triggerCharacters = { "(", "," }      },      textDocumentSync = {        change = 2,        openClose = true,        save = {          includeText = true        }      },      workspaceSymbolProvider = vim.empty_dict()    },    serverInfo = {      name = "arduino-language-server",      version = "0.0.0-git"    }  }}
[DEBUG][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:365    "rpc.send"      {  jsonrpc = "2.0",  method = "initialized",  params = vim.empty_dict()}
[INFO][2023-03-06 20:59:50] .../lua/vim/lsp.lua:1324    "LSP[arduino_language_server]"  "server_capabilities"   {  server_capabilities = {    codeActionProvider = {      codeActionKinds = { "quickfix", "refactor", "info" }    },    completionProvider = {      allCommitCharacters = { " ", "\t", "(", ")", "[", "]", "{", "}", "<", ">", ":", ";", ",", "+", "-", "/", "*", "%", "^", "&", "#", "?", ".", "=", '"', "'", "|" },      completionItem = vim.empty_dict(),      triggerCharacters = { ".", "<", ">", ":", '"', "/" }    },    definitionProvider = vim.empty_dict(),    documentFormattingProvider = vim.empty_dict(),    documentHighlightProvider = vim.empty_dict(),    documentOnTypeFormattingProvider = {      firstTriggerCharacter = "\n"    },    documentRangeFormattingProvider = vim.empty_dict(),    documentSymbolProvider = vim.empty_dict(),    executeCommandProvider = {      commands = { "clangd.applyFix", "clangd.applyTweak" }    },    hoverProvider = vim.empty_dict(),    renameProvider = vim.empty_dict(),    signatureHelpProvider = {      triggerCharacters = { "(", "," }    },    textDocumentSync = {      change = 2,      openClose = true,      save = {        includeText = true      }    },    workspaceSymbolProvider = vim.empty_dict()  }}
[DEBUG][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:365    "rpc.send"      {  jsonrpc = "2.0",  method = "textDocument/didOpen",  params = {    textDocument = {      languageId = "arduino",      text = "\n",      uri = "file:///Users/oliverswitzer/workspace/arduino-playground/fibonacci.ino",      version = 0    }  }}

[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.493589 \27[96mINIT --- : running: /opt/homebrew/bin/arduino-cli --config-file /Users/oliverswitzer/Library/Arduino15/arduino-cli.yaml compile --fqbn arduino:avr:nano --only-compilation-database --source-override /var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/1727312059 --build-path /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server207618810 --format json /Users/oliverswitzer/workspace/arduino-playground\27[0m\n20:59:50.493842 IN Elapsed: 392.709µs\n20:59:50.493967 \27[92mIDE --> LS NOTIF initialized\27[0m\n20:59:50.493983 \27[92m                 initialized: Notification is not propagated to clangd\27[0m\n20:59:50.494005 IN Elapsed: 13.041µs\n20:59:50.494020 \27[92mIDE --> LS NOTIF textDocument/didOpen\27[0m\n"

[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.494281 \27[92m                 textDocument/didOpen: \27[93mwrite-locked\27[0m\27[0m\n20:59:50.494285 \27[92m                 textDocument/didOpen: (throttled: waiting for clangd)\27[0m\n20:59:50.494288 \27[92m                 textDocument/didOpen: \27[93munlocked (waiting clangd)\27[0m\27[0m\n"

[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.535567 \27[96mINIT --- : error starting clang: running /opt/homebrew/bin/arduino-cli --config-file /Users/oliverswitzer/Library/Arduino15/arduino-cli.yaml compile --fqbn arduino:avr:nano --only-compilation-database --source-override /var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/1727312059 --build-path /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server207618810 --format json /Users/oliverswitzer/workspace/arduino-playground: exit status 1\27[0m\n"

[ERROR][2023-03-06 20:59:50] .../vim/lsp/rpc.lua:440    "rpc"   "arduino-language-server"       "stderr"        "20:59:50.535589 \27[92m                 textDocument/didOpen: \27[93mlocked (waiting clangd)\27[0m\27[0m\n20:59:50.535592 \27[92m                 textDocument/didOpen: clangd startup failed: quitting Language server\27[0m\n"

Here's the log directly from arduino-language-server (less noisy):

21:15:25.943704 Language server launched with arguments:
21:15:25.943715   arg[0] = /Users/oliverswitzer/.asdf/installs/golang/1.17.1/packages/bin/arduino-language-server
21:15:25.943726   arg[1] = -cli
21:15:25.943731   arg[2] = /opt/homebrew/bin/arduino-cli
21:15:25.943735   arg[3] = -cli-config
21:15:25.943738   arg[4] = /Users/oliverswitzer/Library/Arduino15/arduino-cli.yaml
21:15:25.943742   arg[5] = -fqbn
21:15:25.943746   arg[6] = arduino:avr:nano
21:15:25.943750   arg[7] = -log
21:15:25.943754   arg[8] = /Users/oliverswitzer/.local/state/nvim/arduino-lsp.log
21:15:25.943843 clangd found at /usr/bin/clangd
21:15:25.943898 logging to /Users/oliverswitzer/workspace/arduino-playground/inols.log
21:15:25.944366 LS: : Initial board configuration: arduino:avr:nano
21:15:25.944376 LS: : arduino-language-server Version: 0.0.0-git Commit:  Date: 
21:15:25.944383 LS: : Language server build path: /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server2844659674
21:15:25.944388 LS: : Language server build sketch root: /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server2844659674/sketch
21:15:25.944393 LS: : Language server FULL build path: /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server2992724278
21:15:25.944677 IN Elapsed: 21.417µs
21:15:25.944995 IDE --> LS REQU initialize 1
21:15:25.945477                 initialize 1: write-locked
21:15:25.945533                 initialize 1: write-unlocked
21:15:25.945800                 initialize 1: initialization parameters: {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{"includeText":true}},"completionProvider":{"triggerCharacters":[".","\u003c","\u003e",":","\"","/"],"allCommitCharacters":[" ","\t","(",")","[","]","{","}","\u003c","\u003e",":",";",",","+","-","/","*","%","^","\u0026","#","?",".","=","\"","'","|"],"completionItem":{}},"hoverProvider":{},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":{},"documentHighlightProvider":{},"documentSymbolProvider":{},"codeActionProvider":{"codeActionKinds":["quickfix","refactor","info"]},"documentFormattingProvider":{},"documentRangeFormattingProvider":{},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n"},"renameProvider":{},"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"workspaceSymbolProvider":{}},"serverInfo":{"name":"arduino-language-server","version":"0.0.0-git"}}
21:15:25.945815 IDE <-- LS RESP initialize 1
21:15:25.945849 INIT --- : initializing workbench: file:///Users/oliverswitzer/workspace/arduino-playground
21:15:25.945863 INIT --- : read-locked
21:15:25.945854 OUT Elapsed: 12.791µs
21:15:25.945870 INIT --- : read-unlocked
21:15:25.946029 INIT --- : running: /opt/homebrew/bin/arduino-cli --config-file /Users/oliverswitzer/Library/Arduino15/arduino-cli.yaml compile --fqbn arduino:avr:nano --only-compilation-database --source-override /var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/2967869730 --build-path /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server2992724278 --format json /Users/oliverswitzer/workspace/arduino-playground
21:15:25.946400 IN Elapsed: 506µs
21:15:25.946472 IDE --> LS NOTIF initialized
21:15:25.946486                  initialized: Notification is not propagated to clangd
21:15:25.946497 IN Elapsed: 5µs
21:15:25.946512 IDE --> LS NOTIF textDocument/didOpen
21:15:25.946789                  textDocument/didOpen: write-locked
21:15:25.946797                  textDocument/didOpen: (throttled: waiting for clangd)
21:15:25.946802                  textDocument/didOpen: unlocked (waiting clangd)
21:15:25.954268 INIT --- : error starting clang: running /opt/homebrew/bin/arduino-cli --config-file /Users/oliverswitzer/Library/Arduino15/arduino-cli.yaml compile --fqbn arduino:avr:nano --only-compilation-database --source-override /var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/2967869730 --build-path /private/var/folders/km/y_f3tv3s0yz6f1h4z09qmr300000gn/T/arduino-language-server2992724278 --format json /Users/oliverswitzer/workspace/arduino-playground: exit status 1
21:15:25.954317                  textDocument/didOpen: locked (waiting clangd)
21:15:25.954323                  textDocument/didOpen: clangd startup failed: quitting Language server

Here is my nvim lsp setup:

  require("lspconfig").arduino_language_server.setup {
    cmd = {
        "arduino-language-server",
        "-cli", "/opt/homebrew/bin/arduino-cli",
        "-cli-config", "/Users/oliverswitzer/Library/Arduino15/arduino-cli.yaml",
        "-fqbn", "arduino:avr:nano"
    }
  }

note that I've tried explicitly passing -clangd /usr/bin/clangd as well with no luck.

Version of arduino-cli:

$ arduino-cli version
arduino-cli  Version: 0.31.0 Commit: 940c9457 Date: 2023-02-20T15:09:19Z

clang version:

$ clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I am using the latest released version of arduino-language-server from a go install (unclear to me from --help how to get the current version of arduino-language-server)

Any help or insight you could provide on why this is not working or what these log lines imply would be greatly appreciated. Thank you in advance!

To reproduce

nvim any_arduino_file.ino with the setup delineated above.

Expected behavior

client 8 quit with exit code 2 and signal 0 in the nvim editor, and the log lines listed above in my lsp.log file.

Arduino Language Server version

0.7.4

Arduino CLI version

0.31.0 Commit: 940c9457 Date: 2023-02-20T15:09:19Z

Operating system

macOS

Operating system version

13.2.1 (22D68) - Ventura

Additional context

No response

Issue checklist

saippua commented 1 year ago

also experiencing this. Any workarounds?

darius-grauslys commented 1 year ago

Also experiencing this issue.

darius-grauslys commented 1 year ago

I spent a bit of time to look into the issue, though I do not know Go myself.

by supplying a -log flag to arduino-language-server within coc-settings.json I noticed an error with output generated by ls/builder.go . In the function generateBuildEnvironment, the local variable overridesJSON receives a path to a non-existent directory. This was logged as an error in the inols-err.log. I went into ls/builder.go and removed all usage of overridesJSON, and replaced its usage in the args constructor with buildPath.String().

This cleared out the error, but later on caused the arduino LSP to panic:

Panic: unimplemented request: workspace/semanticTokens/refresh

I reverted my code changes such that overridesJSON would refer to a non-existent directory again however this no longer seemed to be an issue, and now the LSP will continue to panic in the same manner whenever an ino file is opened.

BrunoCooper17 commented 1 year ago

Try disabling lsp semantic tokens (https://www.reddit.com/r/neovim/comments/zjqquc/how_do_i_turn_off_semantic_tokens/). Apparently the server does not support them and are disabled by default (https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#arduino_language_server, see capabilities)

kons-9 commented 1 year ago

I faced the same error, and I found this error is because of the way of finding a file name in arduino-cli. The algorithm is "root directory" + "ino". For example, since your directory is arduino-playground, the language server tries to find arduino-playground.ino, not fibonacci.ino, which is the reason for the error.

per1234 commented 1 year ago

Thanks for explaining the cause of the reported error @kons-9. Arduino sketches must contain a .ino file with name matching the sketch folder:

https://arduino.github.io/arduino-cli/dev/sketch-specification/#primary-sketch-file