Skip to content

Commit

Permalink
feat: Add earthlyls lsp client
Browse files Browse the repository at this point in the history
* feat: Add earthlyls lsp client (using lsp-asm.el as reference)

* feat: Provide a way to download the server automatically
  • Loading branch information
Konubinix committed Jun 4, 2024
1 parent acad044 commit fb15cba
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
94 changes: 94 additions & 0 deletions clients/lsp-earthly.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
;;; lsp-earthly.el --- earthlyls client -*- lexical-binding: t; -*-

;; Copyright (C) 2024 Samuel Loury

;; Author: Samuel Loury <[email protected]>
;; Keywords: earthly lsp

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; LSP client for Earthfile

;;; Code:

(require 'lsp-mode)

(defgroup lsp-earthly nil
"LSP support for Earthfile."
:group 'lsp-mode
:link '(url-link "https://github.com/glehmann/earthlyls")
:package-version `(lsp-mode . "9.0.0"))

(defcustom lsp-earthly-active-modes
'(earthfile-mode)
"List of major mode that work with earthlyls."
:type '(list symbol)
:group 'lsp-earthly)

(defcustom lsp-earthly-home-url
"https://github.com/glehmann/earthlyls"
"Url we use to install earthlyls."
:type 'string
:group 'lsp-earthly
:package-version '(lsp-mode . "9.0.0"))

(defcustom lsp-earthly-store-path (f-join lsp-server-install-dir "earthly")
"The path to the file in which `earthlyls' will be stored."
:type 'file
:group 'lsp-earthly
:package-version '(lsp-mode . "9.0.0"))

(defun lsp-earthly--download-server (_client callback error-callback update?)
"Install/update earthly-ls language server using `cargo install'.
Will invoke CALLBACK or ERROR-CALLBACK based on result.
Will update if UPDATE? is t."
(when update?
(ignore-errors (delete-directory lsp-earthly-store-path t)))
(lsp-async-start-process
callback
error-callback
"cargo" "install" "--git" lsp-earthly-home-url "--root"
lsp-earthly-store-path "earthlyls"))

(defun lsp-earthly--executable ()
"Return earthlyls executable."
(let ((local (f-join lsp-earthly-store-path "bin"
(if (eq system-type 'windows-nt)
"earthlyls.exe"
"earthlyls"))))
(or (and (f-exists? local) local)
(executable-find "earthlyls")
(user-error "`earthlyls' is not installed; for installation see %s for more information" lsp-earthly-home-url))))

(defun lsp-earthly--server-command ()
"Startup command for the earthlyls server."
(list (lsp-earthly--executable)))

(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection
#'lsp-earthly--server-command
(lambda () (f-exists? lsp-earthly-store-path)))
:major-modes lsp-earthly-active-modes
:priority -1
:server-id 'earthlyls
:download-server-fn #'lsp-earthly--download-server))

(lsp-consistency-check lsp-earthly)

(provide 'lsp-earthly)
;;; lsp-earthly.el ends here
9 changes: 9 additions & 0 deletions docs/lsp-clients.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@
"lsp-install-server": "dot-ls",
"debugger": "Not available"
},
{
"name": "earthly",
"full-name": "Earthfile language server",
"server-name": "earthlyls",
"server-url": "https://github.com/glehmann/earthlyls",
"installation": "cargo install earthlyls",
"lsp-install-server": "earthlyls",
"debugger": "Not available"
},
{
"name": "elixir",
"full-name": "Elixir",
Expand Down
3 changes: 2 additions & 1 deletion lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ As defined by the Language Server Protocol 3.16."
lsp-autotools lsp-awk lsp-bash lsp-beancount lsp-bufls lsp-clangd
lsp-clojure lsp-cmake lsp-cobol lsp-credo lsp-crystal lsp-csharp lsp-css
lsp-cucumber lsp-cypher lsp-d lsp-dart lsp-dhall lsp-docker lsp-dockerfile
lsp-elixir lsp-elm lsp-emmet lsp-erlang lsp-eslint lsp-fortran lsp-fsharp
lsp-earthly lsp-elixir lsp-elm lsp-emmet lsp-erlang lsp-eslint lsp-fortran lsp-fsharp
lsp-gdscript lsp-gleam lsp-glsl lsp-go lsp-golangci-lint lsp-grammarly
lsp-graphql lsp-groovy lsp-hack lsp-haskell lsp-haxe lsp-idris lsp-java
lsp-javascript lsp-jq lsp-json lsp-kotlin lsp-latex lsp-lisp lsp-ltex
Expand Down Expand Up @@ -769,6 +769,7 @@ Changes take effect only when a new session is started."
("\\.cs\\'" . "csharp")
("\\.css$" . "css")
("\\.cypher$" . "cypher")
("Earthfile" . "earthfile")
("\\.ebuild$" . "shellscript")
("\\.go\\'" . "go")
("\\.html$" . "html")
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ nav:
- Dart: https://emacs-lsp.github.io/lsp-dart
- Dhall: page/lsp-dhall.md
- Dockerfile: page/lsp-dockerfile.md
- Earthfile: page/lsp-earthly.md
- Elixir: page/lsp-elixir.md
- Elm: page/lsp-elm.md
- Emmet: page/lsp-emmet.md
Expand Down

0 comments on commit fb15cba

Please sign in to comment.