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

Allow other snippet/template expansion libraries #4474

Open
FrauH0lle opened this issue Jun 10, 2024 · 0 comments
Open

Allow other snippet/template expansion libraries #4474

FrauH0lle opened this issue Jun 10, 2024 · 0 comments

Comments

@FrauH0lle
Copy link

Hey there,

I would like to ask if you would consider supporting other snippet expansion libraries than yasnippet?

Currently I working with tempel and combine it with lsp-snippet which works fairly well after some modifications to lsp-snippet. In the end, this lead me to ask this question, because the package uses a little hack to work (which also does not work after #4413).

So I was thinking about the following changes to make the integration of 3rd party packages easier.

Introduce a variable like

(defcustom lsp-snippet-override nil
  "Allows the use of other snippet expansion packages than yasnippet.")

This could be used in the checks for snippet expansion capabilities here , here and here

...
,(and lsp-enable-snippet (or lsp-snippet-override
                             (fboundp 'yas-minor-mode)))

yasnippet itself is used here:

(defun lsp--expand-snippet (snippet &optional start end expand-env)
  "Wrapper of `yas-expand-snippet' with all of it arguments.
The snippet will be convert to LSP style and indent according to
LSP server result."
  (require 'yasnippet nil t)
  ....)

Here, another variable could be used:

(defcustom lsp-snippet-function #'lsp-snippet-expand-yasnippet
  "Function used to expand snippets. Will be called with the
 arguments SNIPPET &optional START END EXPAND-ENV")

(defun lsp-snippet-expand-yasnippet (snippet &optional start end expand-env)
  "Wrapper of `yas-expand-snippet' with all of it arguments.
The snippet will be convert to LSP style and indent according to
LSP server result."
  (require 'yasnippet nil t)
  (let* ((inhibit-field-text-motion t)
         (yas-wrap-around-region nil)
         (yas-indent-line 'none)
         (yas-also-auto-indent-first-line nil))
    (yas-expand-snippet
     (lsp--to-yasnippet-snippet snippet)
     start end expand-env)))

and change lsp--expand-snippet to

(defun lsp--expand-snippet (snippet &optional start end expand-env)
  "Wrapper of `yas-expand-snippet' with all of it arguments.
The snippet will be convert to LSP style and indent according to
LSP server result."
  (funcall lsp-snippet-function snippet start end expand-env))

Thus, other packages could provide their own expansion machinery and simply hook it to lsp-mode.

Would this be something you would consider?

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

No branches or pull requests

1 participant