0

I am trying to use a custom lsp server. I place the following snippet in my init file:


  (with-eval-after-load 'lsp-mode
    (add-to-list 'lsp-language-id-configuration '(solidity-mode . "soldity"))
    (add-to-list 'lsp-language-id-configuration '("\\.sol$" . "solidity"))
    (lsp-register-client
     (make-lsp-client :new-connection (lsp-stdio-connection '("solidity-ls" "--stdio"))
                      :activation-fn (lsp-activate-on "solidity")
                      :server-id 'solidity)))

But when I open a .sol file no lsp mode is activated. If I manually use M-x lsp I get a message saying that semgrep lsp is available but not installed, and the lsp-log has this message: Command "semgrep lsp" is not present on the path.

I don't want semgrep lsp. I want my custom solidity lsp client. M-x describe-variable for lsp-language-id-configuration shows that my add-to-list statements have had zero effect. M-x describe-mode shows that I'm in solidity/*l mode. The only way I can get my custom lsp client to work is by navigating to my init file, selecting the following region, and using M-x eval-region

    (add-to-list 'lsp-language-id-configuration '(solidity-mode . "soldity"))
    (add-to-list 'lsp-language-id-configuration '("\\.sol$" . "solidity"))
    (lsp-register-client
     (make-lsp-client :new-connection (lsp-stdio-connection '("solidity-ls" "--stdio"))
                      :activation-fn (lsp-activate-on "solidity")
                      :server-id 'solidity))

How can I get lsp-mode to register my lsp-client automatically when I open a .sol file?

NB: I'm using spacemacs and the following instructions for adding a custom lsp server https://emacs-lsp.github.io/lsp-mode/page/adding-new-language/

1 Answer 1

0

Moving the logic to a solidity-mode-hook and requiring lsp-mode inside the hook fixed things. I also added a notification handler to ignore an event that lsp-mode doesn't recognize and hence causes errors.

  (add-hook 'solidity-mode-hook
            (lambda ()
              (require 'lsp-mode)
              (add-to-list 'lsp-language-id-configuration '(solidity-mode . "soldity"))
              (add-to-list 'lsp-language-id-configuration '("\\.sol$" . "solidity"))
              (lsp-register-client
               (make-lsp-client :new-connection (lsp-stdio-connection '("solidity-ls" "--stdio"))
                                :activation-fn (lsp-activate-on "solidity")
                                :notification-handlers
                                (ht ("textDocument/didOpen" #'ignore))
                                :server-id 'solidity))
              (lsp)
              )
            )

EDIT: I had to enclose the code inside the hook in a lambda.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.