Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Server Support #108

Closed
skx opened this issue Nov 22, 2022 · 3 comments · Fixed by #109
Closed

Language Server Support #108

skx opened this issue Nov 22, 2022 · 3 comments · Fixed by #109
Assignees

Comments

@skx
Copy link
Owner

skx commented Nov 22, 2022

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:

  • We should provide completion for "things".
    • All the builtin golang-implemented primitives.
    • Any/wall functions defined in the standard library.
    • (Optionally: Anything in the users' source.)
  • We should provide help-on-hover
    • Again for "everything", built-in functions, the standard library, and optionally the users's own code.

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
Copy link
Owner Author

skx commented Nov 22, 2022

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

  • Creates a pretend (derived) mode for yal files, yal-mode.
  • Ensures that when yal-mode files are loaded this mode is used.
  • Ensures that lsp-deferred is called as a hook when entering that mode.

After all that we then do the LSP-magic:

  • We launch yal -lsp as a language-server, for files in yal-mode.

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 skx self-assigned this Nov 22, 2022
@skx
Copy link
Owner Author

skx commented Nov 22, 2022

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 added a commit that referenced this issue Nov 23, 2022
This pull-request, once complete, will had LSP support and
will close #108.

Currently we show help for standard library functions, when
the user hovers over a token.  We also provide completion for
all our standard-library functions.
@skx skx mentioned this issue Nov 23, 2022
@skx
Copy link
Owner Author

skx commented Nov 23, 2022

  • Working for Emacs:
    • Hover
    • Completion

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

@skx skx closed this as completed in #109 Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant