|
| 1 | +;;; lsp-odin.el --- Description -*- lexical-binding: t; -*- |
| 2 | +;; |
| 3 | +;; Copyright (C) 2025 Sam Precious |
| 4 | +;; |
| 5 | +;; Author: Sam Precious <samwdp@gmail.com> |
| 6 | +;; Keywords: lsp, odin |
| 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 Odin using the ols language server |
| 24 | +;; |
| 25 | +;;; Code: |
| 26 | + |
| 27 | +(require 'lsp-mode) |
| 28 | +(require 'f) |
| 29 | + |
| 30 | +(defgroup lsp-odin-ols nil |
| 31 | + "LSP support for Odin, using ols." |
| 32 | + :group 'lsp-mode |
| 33 | + :link '(url-link "https://github.com/DanielGavin/ols") |
| 34 | + :package-version '(lsp-mode . "9.0.0")) |
| 35 | + |
| 36 | +(defcustom lsp-odin-ols-download-url |
| 37 | + (let ((suffix |
| 38 | + (pcase system-type |
| 39 | + ('windows-nt |
| 40 | + (when (and (string-match "^x86_64-.*" system-configuration) |
| 41 | + (version<= "26.4" emacs-version)) |
| 42 | + "ols-x86_64-pc-windows-msvc.zip")) |
| 43 | + ('darwin |
| 44 | + (if (string-match "aarch64-.*" system-configuration) |
| 45 | + "ols-arm64-darwin.zip" |
| 46 | + "ols-x86_64-darwin.zip")) |
| 47 | + (_ |
| 48 | + "ols-x86_64-unknown-linux-gnu")))) |
| 49 | + (when suffix |
| 50 | + (f-join "https://github.com/DanielGavin/ols/releases/download/nightly/" |
| 51 | + suffix))) |
| 52 | + "Automatic download url for ols language server." |
| 53 | + :group 'lsp-odin-ols |
| 54 | + :type 'string) |
| 55 | + |
| 56 | +(defcustom lsp-odin-ols-server-install-dir |
| 57 | + (f-join lsp-server-install-dir "ols/") |
| 58 | + "Installation directory for ols server." |
| 59 | + :group 'lsp-odin-ols |
| 60 | + :type 'directory) |
| 61 | + |
| 62 | +(defcustom lsp-odin-ols-store-path |
| 63 | + (f-join lsp-odin-ols-server-install-dir "latest" "ols.zip") |
| 64 | + "The path where ols .zip archive will be stored." |
| 65 | + :group 'lsp-odin-ols |
| 66 | + :type 'file) |
| 67 | + |
| 68 | +(defcustom lsp-odin-ols-server-dir |
| 69 | + (f-join lsp-odin-ols-server-install-dir "latest" "ols") |
| 70 | + "The path where ols .zip archive will be extracted." |
| 71 | + :group 'lsp-odin-ols |
| 72 | + :type 'file) |
| 73 | + |
| 74 | +(defcustom lsp-odin-ols-binary-path |
| 75 | + (f-join lsp-odin-ols-server-install-dir "latest" |
| 76 | + (pcase system-type |
| 77 | + ('windows-nt |
| 78 | + "ols-x86_64-pc-windows-msvc.exe") |
| 79 | + ('darwin |
| 80 | + (if (string-match "aarch64-.*" system-configuration) |
| 81 | + "ols-arm64-darwin" |
| 82 | + "ols-x86_64-darwin")) |
| 83 | + (_ |
| 84 | + "ols-x86_64-unknown-linux-gnu"))) |
| 85 | + "The path where ols binary after will be stored." |
| 86 | + :group 'lsp-odin-ols |
| 87 | + :type 'file) |
| 88 | + |
| 89 | + |
| 90 | +(lsp-dependency |
| 91 | + 'ols |
| 92 | + `(:download :url lsp-odin-ols-download-url |
| 93 | + :decompress :zip |
| 94 | + :store-path lsp-odin-ols-store-path |
| 95 | + :binary-path lsp-odin-ols-binary-path |
| 96 | + :set-executable? t) |
| 97 | + '(:system "ols")) |
| 98 | + |
| 99 | +(defun lsp-odin--ols-download-server (_client callback error-callback _update?) |
| 100 | + "Download zip package for ols and install it. |
| 101 | +Will invoke CALLBACK on success, ERROR-CALLBACK on error." |
| 102 | + (lsp-package-ensure 'ols callback error-callback)) |
| 103 | + |
| 104 | +(lsp-register-client |
| 105 | + (make-lsp-client :new-connection (lsp-stdio-connection lsp-odin-ols-binary-path) |
| 106 | + :major-modes '(odin-mode odin-ts-mode) |
| 107 | + :language-id "odin" |
| 108 | + :activation-fn (lsp-activate-on "odin") |
| 109 | + :server-id 'ols |
| 110 | + :multi-root t |
| 111 | + :download-server-fn #'lsp-odin--ols-download-server)) |
| 112 | + |
| 113 | +(provide 'lsp-odin) |
| 114 | +;;; lsp-odin.el ends here |
0 commit comments