[gambit-list] LSP implementation for Gambit

Marc Feeley feeley at iro.umontreal.ca
Thu Sep 15 08:14:36 EDT 2022


Hello Ricardo.  First of all thank you so much for your work towards LSP support for Gambit.  I am eager to try it out!

When I tried to run the LSP server I hit this error:

  > (import (codeberg.org/rgherdt/scheme-lsp-server lsp-server))
  *** ERROR IN "../../../.gambit_userlib/codeberg.org/rgherdt/scheme-lsp-server/@/gambit/util.scm"@25.9 -- Duplicate import of identifier with-exception-handler

I think the cause may be the recent change in Gambit to support the R7RS `guard` form.  Gambit has its own semantics for `guard`, `raise`, and `with-exception-handler` that is slightly different from R7RS. So both the `(scheme base)` and `(gambit)` libraries export these identifiers.  The library `(scheme base)` maps `with-exception-handler` to `r7rs-with-exception-handler` which has the R7RS semantics.  If you want to import `(gambit)` and also `(scheme base)` then you have to choose which of the exception handling forms you want.  Probably this:

  (import (scheme base)
          (except (gambit) with-exception-handler raise guard))

Regarding `guard` I looked at the file `gambit.scm` quickly and I found:

    (let ((proc (if (symbol? identifier)
                    (guard
                     (condition (#t (write-log 'info
                                     (format "procedure not found: ~a"
                                             identifier))
                                    #f))
                     (eval identifier)) ; safe 'cause only a symbol
                    #f)))
      (if (and proc (procedure? proc))

Is there any reason for using `#t` instead of an `else` in the `guard` to catch all exceptions?

Also, there’s a more direct way in Gambit to get the value of a global variable and check if it is undefined:

  (let ((val (##global-var-ref (##make-global-var identifier)))))
    (if (##unbound? val) …

It is much faster than using `eval` and `guard`.  Moreover, `eval` will be sensitive to any `(namespace …)` forms that have been evaluated in the past (at the REPL or with `eval`).

Marc



> On Sep 15, 2022, at 2:09 AM, Ricardo G. Herdt <r.herdt at posteo.de> wrote:
> 
> Hi,
> 
> I released new versions of my scheme LSP server and some LSP clients. The biggest change is that they now have Gambit support :) Thanks Marc for the help.
> 
> The software is still in an early stage of development. You can find the LSP server here: https://codeberg.org/rgherdt/scheme-lsp-server
> Some important notes regarding Gambit:
> 
> - only Gambit 4.9.4+ is supported. I recommend installing Gambit from its master branch, since it has important bug fixes for GSC regarding some R7RS forms this library relies on (particularly `guard`). If you want to stick to Gambit 4.9.4, don't compile the library after installing it, otherwise it won't work.
> - I only tested this on Linux, but would expect that it also works on Mac.
> - some of the LSP clients listed below will prompt for automatically installing the LSP server if needed.
> 
> Currently following LSP clients are available:
> 
> * Emacs
> - lsp-scheme
>  Available in MELPA. The extension will prompt for installing the LSP server if it's not found.
>  Here the source code: https://codeberg.org/rgherdt/emacs-lsp-scheme
> - eglot
>  Follow these instructions to activate the LSP server for eglot: https://codeberg.org/rgherdt/scheme-lsp-server#emacs-eglot-https-github-com-joaotavora-eglot
> 
> * VSCode/VSCodium
> - vscode-scheme-lsp
>  Available both in VSCode's and VSCodium's marketplaces under the name Scheme LSP.
>  The extension will prompt for auto-installing the LSP server if it's not found.
>  Source code: https://codeberg.org/rgherdt/vscode-scheme-lsp
> 
> After installing any of these extensions, don't forget to configure it for Gambit before start using it. Refer to the corresponding docs to see how to do this.
> 
> Let me know if you have any trouble using them.
> 
> Regards,
> 
> Ricardo
> 
> 
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list
> 




More information about the Gambit-list mailing list