Subject: [bug#60286] [PATCH 2/2] gnu: Add guile-scheme-lsp-server.

From: Giacomo Leidi <[email-masked]>
Date: Fri, 23 Dec 2022 21:46:30 +0100

* gnu/packages/scheme-xyz.scm (guile-scheme-lsp-server): New variable.
---
 gnu/packages/scheme-xyz.scm | 85 +++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/gnu/packages/scheme-xyz.scm b/gnu/packages/scheme-xyz.scm
index 819c5cdf9e..513953b0f4 100644
--- a/gnu/packages/scheme-xyz.scm
+++ b/gnu/packages/scheme-xyz.scm
@@ -18,6 +18,7 @@
 
 (define-module (gnu packages scheme-xyz)
   #:use-module (gnu packages autotools)
+  #:use-module (gnu packages bash)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages texinfo)
@@ -65,3 +66,87 @@ (define-public guile-scheme-json-rpc
 This package delivers Guile's bytecode for @code{scheme-json-rpc}.")
     (home-page "https://codeberg.org/rgherdt/scheme-json-rpc")
     (license license:expat)))
+
+(define (scheme-lsp-server-origin name version hash)
+  (origin
+    (method git-fetch)
+    (uri (git-reference
+           (url "https://codeberg.org/rgherdt/scheme-lsp-server.git")
+           (commit version)))
+    (file-name (git-file-name name version))
+    (sha256
+     (base32
+      hash))))
+
+(define-public guile-scheme-lsp-server
+  (package
+    (name "guile-scheme-lsp-server")
+    (version "0.2.2")
+    (source
+     (scheme-lsp-server-origin
+      name
+      version
+      "0lb359gw00w149h5yq2brfrcpybdwdj6ndbl7k1ms88l653r5l2g"))
+    (build-system gnu-build-system)
+    (arguments
+     (list #:modules `((ice-9 match)
+                       (ice-9 ftw)
+                       ,@%gnu-build-system-modules)
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'move-to-guile-directory
+                 (lambda _
+                   (chdir "./guile")))
+               (add-after 'install 'wrap-entrypoint
+                 (lambda _
+                   (let* ((bin (string-append #$output "/bin"))
+                          (site (string-append #$output
+                                               "/share/guile/site"))
+                          (deps (list #$guile-scheme-json-rpc)))
+                     (match (scandir site)
+                       (("." ".." version)
+                        (let ((modules (string-append site "/"
+                                                      version))
+                              (compiled-modules (string-append #$output
+                                                 "/lib/guile/"
+                                                 version
+                                                 "/site-ccache")))
+                          (wrap-program (string-append bin
+                                         "/guile-lsp-server")
+                                        `("GUILE_LOAD_PATH" ":"
+                                          prefix
+                                          (,modules
+                                           ,@(map (lambda (dep)
+                                                    (string-append
+                                                     dep
+                                                     "/share/guile/site/"
+                                                     version))
+                                                  deps)))
+                                        `("GUILE_LOAD_COMPILED_PATH"
+                                          ":" prefix
+                                          (,compiled-modules
+                                           ,@(map (lambda (dep)
+                                                    (string-append
+                                                     dep
+                                                     "/lib/guile/"
+                                                     version
+                                                     "/site-ccache"))
+                                              deps))))
+                          #t)))))))))
+    (native-inputs (list autoconf automake pkg-config))
+    (inputs
+     ;; Depend on the latest Guile to avoid bytecode compatibility issues when
+     ;; using modules built against the latest version.
+     (list bash-minimal
+           guile-3.0-latest))
+    (propagated-inputs (list guile-scheme-json-rpc))
+    (synopsis "LSP (Language Server Protocol) server for Scheme")
+    (description
+     "@code{guile-lsp-server} is an implementation for Guile of the LSP
+specification.  This software aims to support several Scheme implementations.
+To achieve this, the code is designed to contain as much logic as possible in
+R7RS Scheme, separating implementation-specific code in different modules.
+
+This package delivers Guile's implementation for @code{scheme-lsp-server}.")
+    (home-page "https://codeberg.org/rgherdt/scheme-lsp-server")
+    (license license:expat)))
-- 
2.38.1