116 lines
4.5 KiB
EmacsLisp
116 lines
4.5 KiB
EmacsLisp
;;; lsp-typst.el --- LSP support for Typst with lsp-mode -*- lexical-binding: t; colon-double-space: t; -*-
|
||
|
||
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
|
||
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
|
||
;; Version: 1.0.0
|
||
;; Package-Requires: ((emacs "30.1") (lsp-mode "10") (f "0.20") (typst-ts-mode "0.12"))
|
||
;; Homepage: https://labs.phundrak.com/phundrak/lsp-typst
|
||
;; Keywords: lsp typst tools
|
||
|
||
|
||
;; This file is not part of GNU Emacs
|
||
|
||
;; This program is free software: you can redistribute it and/or modify
|
||
;; it under the terms of the GNU General Public License as published by
|
||
;; the Free Software Foundation, either version 3 of the License, or
|
||
;; (at your option) any later version.
|
||
|
||
;; This program is distributed in the hope that it will be useful,
|
||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;; GNU General Public License for more details.
|
||
|
||
;; You should have received a copy of the GNU General Public License
|
||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
|
||
;;; Commentary:
|
||
|
||
;; LSP support for Typst with lsp-mode.
|
||
;;
|
||
;; I recommend `typst-ts-mode'
|
||
;; (https://codeberg.org/meow_king/typst-ts-mode/), available on
|
||
;; Nongnu Elpa, if you need a major mode for Typst, but this package
|
||
;; does not require it.
|
||
|
||
;;; Code:
|
||
|
||
(require 'lsp-mode)
|
||
(require 'f)
|
||
|
||
(defgroup lsp-typst nil
|
||
"Settings for the tinymist language server client for Typst."
|
||
:group 'lsp-mode
|
||
:link '(url "https://github.com/Myriad-Dreamin/tinymist")
|
||
:package-version '(lsp-typst . "1.0.0"))
|
||
|
||
(defcustom lsp-typst-server-command "tinymist"
|
||
"The binary or full path to binary which launches the server."
|
||
:type 'string
|
||
:group 'lsp-typst
|
||
:package-version '(lsp-typst . "1.0.0"))
|
||
|
||
(defcustom lsp-typst-server-command-args '("lsp")
|
||
"Command-line arguments for the tinymist LSP server."
|
||
:type '(repeat string)
|
||
:group 'lsp-typst
|
||
:package-version '(lsp-typst . "1.0.0"))
|
||
|
||
(defcustom lsp-typst-download-url
|
||
(format "https://github.com/Myriad-Dreamin/tinymist/releases/latest/download/tinymist-%s"
|
||
(let ((aarch64-p (string-match "^aarch64-.*" system-configuration)))
|
||
(pcase system-type
|
||
('gnu/linux (if aarch64-p "linux-arm64" "linux-x64"))
|
||
('darwin (if aarch64-p "darwin-arm64" "darwin-x64"))
|
||
('windows-nt (if aarch64-p "win32-arm64.exe" "win32-x64.exe")))))
|
||
"Automatic download URL for tinymist.
|
||
|
||
Out of the box, supports x86-64 GNU/Linux, Windows, and macOS. If you
|
||
are using Linux with musl, a non-aarch64 ARM architecture, or if you
|
||
want tinymist-preview, you’ll probably want to change this value."
|
||
:type 'string
|
||
:group 'lsp-typst
|
||
:package-version '(lsp-typst . "1.0.0"))
|
||
|
||
(defcustom lsp-typst-store-path (f-join lsp-server-install-dir
|
||
"tinymist"
|
||
(if (eq system-type 'windows-nt)
|
||
"tinymist.exe"
|
||
"tinymist"))
|
||
"The path to the file in which `tinymist' will be stored."
|
||
:type 'string
|
||
:group 'lsp-typst
|
||
:package-version '(lsp-typst . "1.0.0"))
|
||
|
||
;;;###autoload
|
||
(with-eval-after-load 'lsp-mode
|
||
(add-to-list 'lsp-language-id-configuration '(typst-ts-mode . "typst"))
|
||
|
||
(lsp-dependency 'typst
|
||
'(:system "typst")
|
||
`(:download :url lsp-typst-download-url
|
||
:store-path lsp-typst-store-path
|
||
:set-executable? t))
|
||
|
||
(lsp-register-client
|
||
(make-lsp-client :new-connection (lsp-stdio-connection
|
||
(lambda ()
|
||
(cons (or (executable-find lsp-typst-server-command)
|
||
(lsp-package-path 'typst)
|
||
"tinymist")
|
||
lsp-typst-server-command-args)))
|
||
:activation-fn (lsp-activate-on "typst")
|
||
:initialized-fn (lambda (workspace)
|
||
(with-lsp-workspace workspace
|
||
(lsp--set-configuration (lsp-configuration-section "typst"))))
|
||
:priority -1
|
||
:server-id 'typst
|
||
:download-server-fn (lambda (_client callback error-callback _update?)
|
||
(lsp-package-ensure 'typst callback error-callback)))))
|
||
|
||
(lsp-consistency-check lsp-typst)
|
||
|
||
(provide 'lsp-typst)
|
||
|
||
;;; lsp-typst.el ends here
|