skx / yal

Yet another lisp interpreter
GNU General Public License v2.0
16 stars 0 forks source link

Language Server Support #108

Closed skx closed 1 year ago

skx commented 1 year ago

LSP is a big thing that makes editors and languages work well together, in a portable way.

What better way to make LISP cool than to add LSP?

For the next release the focus will be upon implementing a yal-LSP server:

Ideally we'll allow yal -lsp to launch the server, but there are probably additional options required - for network-socket vs. unix-socket, etc.

We must ship sample configuration for emacs, and at least one more editor.

skx commented 1 year ago

This is a little bigger than I'd like, but it does three things:

After all that we then do the LSP-magic:

And we configure "C-c TAB" to do dynamic completions, though pausing after typing "prin" or "pad:" is sufficient to make it work. Yay.

Sample code:

;;; yal.el -- Sample configuration for using Emacs LSP-mode with YAL

;; Create a keyboard-map for use within YAL files
(defvar yal-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-c TAB") 'completion-at-point)
    map))

;; Define a hook which will run when entering YAL mode.
(add-hook 'yal-mode-hook 'lsp-deferred)

;; Now create a trivial "yal-mode"
(define-derived-mode yal-mode
  lisp-mode "YAL"
  "Major mode for working with yet another lisp, YAL.")

;; yal-mode will be invoked for *.yal files
(add-to-list 'auto-mode-alist '("\\.yal\\'" . yal-mode))

;; Register an LSP helper
(require 'lsp-mode)
(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection '("yal" "-lsp"))
                  :major-modes '(yal-mode)
                  :priority -1
                  :server-id 'yal-ls))
(add-to-list 'lsp-language-id-configuration '(yal-mode . "yal"))

Screensot:

2

skx commented 1 year ago

https://github.com/tliron/glsp is awesome and made the completion support almost trivial.

Looks like showing documentation on hover requires parsing the file and doing location-testing. I'll see if I can make that good enough to be useful, but definitely completion is worth having and very simple :)

skx commented 1 year ago

I need to provide a configuration for at least one other editor. neovim looks simple: