3

I came across this repo arduino-language-server. My question is how to make it connect it to my emacs? (Maybe more generally, how to connect to any other LSP-server?)

Currently I've installed prerequisites, and can run it (as instructed on it's readme)

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

This will gives me following:

01:12:49.446042 LS: : Initial board configuration: esp32:esp32:esp32
01:12:49.446069 LS: : arduino-language-server Version: 0.0.0-git Commit:  Date:
01:12:49.446080 LS: : Language server build path: /tmp/arduino-language-server951409904
01:12:49.446086 LS: : Language server build sketch root: /tmp/arduino-language-server951409904/sketch
01:12:49.446092 LS: : Language server FULL build path: /tmp/arduino-language-server52033989

arduino-language-server is a language server that provides IDE-like features to editors.

It should be used via an editor plugin rather than invoked directly. For more information, see:
https://github.com/arduino/arduino-language-server/
https://microsoft.github.io/language-server-protocol/
Garid
  • 545
  • 1
  • 13

1 Answers1

1

You need to install either the lsp-mode or eglot-mode Emacs package. (If you have a new enough Emacs then eglot will be built–in). Each of these does basically the same job (teaching Emacs how to talk to an LSP server), but there are differences between them. In principle you should try them both; in practice it is probably best to choose one and get used to it.

Then you need need to check to see if there is an additional package that installs customizations specific to your language. For example, if you program in Java and use lsp-mode, then you would want to install lsp-java. If you use eglot-mode instead, then you would install eglot-java.

These additional packages usually just tell the main package how to run the correct LSP server. For example, here is how lsp-java tells lsp-mode how to run the Java LSP server:

(lsp-register-client
 (make-lsp--client
  :new-connection (lsp-stdio-connection #'lsp-java--ls-command
                                        #'lsp-java--locate-server-jar)
  :major-modes '(java-mode jdee-mode)
  :server-id 'jdtls
  …

The :new-connection attribute tells it how to run the server, and the :major-modes attribute tells it when to do so.

eglot-mode has similar configuration options, but I am less familiar with it.

I don’t see any such packages for the Arduino yet, so you might need to start writing one of your own. You’ll want to carefully read the documentation for either lsp-mode or eglot-mode to work out how best to do that; it’s a bit much to include here.

db48x
  • 15,741
  • 1
  • 19
  • 23
  • Thanks for your comment, I use lsp-mode (but I want to use eglot in the future, because it's native to emacs 29). I usually follow the instructions from [emacs-lsp.github.io](https://emacs-lsp.github.io/lsp-mode/page/languages/). However, there is no entry about this Arduino-language server (there is no lsp-arduino). That's why I'm asking about how to connect to other Language servers that's not included in `M-x lsp-install-server`. I will try `lsp-register-client` there is some instruction on [here](https://emacs-lsp.github.io/lsp-mode/page/adding-new-language/) that's using same function – Garid Nov 14 '22 at 06:39
  • I tried following: `(lsp-register-client (make-lsp--client :new-connection (lsp-stdio-connection '("/home/garid/otherGit/arduino-language-server/arduino-language-server" "-clangd" "/usr/local/bin/clangd" "-cli /usr/local/bin/arduino-cli" "-cli-config" "/home/garid/.arduino15/arduino-cli.yaml" "-fqbn esp32:esp32:esp32")) :major-modes '(arduino-mode) :server-id 'arduino ) )` however it's giving me some error. 1. `lsp-stdio-connection` = shell script which starts the server, 2. `major-mode` which is arduino-mode. 3. `server-id` I don't know where to get this – Garid Nov 14 '22 at 07:07
  • You’re on the right track, but comments are not adequate for answering that type of question. You should create a question instead. Make sure you include any error messages that it gives you. – db48x Nov 14 '22 at 09:03