lsp-astro.el (2197B)
1 ;;; lsp-astro.el --- lsp-mode astro integration -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2022 Paweł Kobojek, Luca Fanselau 4 5 ;; Author: Paweł Kobojek 6 ;; Keywords: languages,astro 7 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 12 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 ;;; Commentary: 22 23 ;; LSP client for astro-ls 24 25 ;;; Code: 26 27 (require 'lsp-mode) 28 29 (defun lsp-astro--get-initialization-options () 30 "Try to get the typescript server path, to supply to the astro language server." 31 (let ((library (f-join (lsp-workspace-root) "node_modules/typescript/lib"))) 32 (if (file-exists-p library) 33 `(:typescript (:tsdk ,library)) 34 (lsp-warn "Unable to find typescript server path for astro-ls. Guessed: %s" library)))) 35 36 (defgroup lsp-astro nil 37 "LSP support for Astro.build, using astro-ls." 38 :group 'lsp-mode 39 :link '(url-link "https://github.com/withastro/language-tools")) 40 41 (lsp-dependency 'astro-language-server 42 '(:system "astroserver") 43 '(:npm :package "@astrojs/language-server" 44 :path "astroserver")) 45 46 47 (lsp-register-client 48 (make-lsp-client :new-connection (lsp-stdio-connection '("astro-ls" "--stdio")) 49 :activation-fn (lsp-activate-on "astro") 50 :initialization-options #'lsp-astro--get-initialization-options 51 :server-id 'astro-ls 52 :download-server-fn (lambda (_client callback error-callback _update?) 53 (lsp-package-ensure 'astro-language-server callback error-callback)))) 54 55 (lsp-consistency-check lsp-astro) 56 57 (provide 'lsp-astro) 58 ;;; lsp-astro.el ends here