|
| 1 | +;;; lsp-typos.el --- LSP client for typos-lsp -*- lexical-binding: t; -*- |
| 2 | +;; |
| 3 | +;; Copyright (C) 2025 Thanh Vuong |
| 4 | +;; |
| 5 | +;; Author: Thanh Vuong <[email protected]> |
| 6 | +;; Keywords: lsp, typos |
| 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 typos-lsp |
| 24 | +;; |
| 25 | +;; This client is disabled by default to avoid confusion as it will run |
| 26 | +;; everywhere lsp mode is on if enabled. Users could use |
| 27 | +;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html |
| 28 | +;; to have it run per project. |
| 29 | +;; |
| 30 | +;; Consult https://github.com/tekumara/typos-lsp and |
| 31 | +;; https://github.com/crate-ci/typos for more information. |
| 32 | +;; |
| 33 | +;;; Code: |
| 34 | + |
| 35 | +(require 'lsp-mode) |
| 36 | + |
| 37 | +(defgroup lsp-typos nil |
| 38 | + "LSP support for typos source code spell checker." |
| 39 | + :group 'lsp-mode |
| 40 | + :link '(url-link "https://github.com/tekumara/typos-lsp")) |
| 41 | + |
| 42 | +(defcustom lsp-typos-path "typos-lsp" |
| 43 | + "Path to typos-lsp executable." |
| 44 | + :group 'lsp-typos |
| 45 | + :type 'string) |
| 46 | + |
| 47 | +(defcustom lsp-typos-enable nil |
| 48 | + "Enable or disable LSP Typos." |
| 49 | + :group 'lsp-typos |
| 50 | + :type 'boolean |
| 51 | + :safe #'booleanp) |
| 52 | + |
| 53 | +(defcustom lsp-typos-config nil |
| 54 | + "Path to toml config file." |
| 55 | + :group 'lsp-typos |
| 56 | + :type '(choice (const :tag "None" nil) |
| 57 | + (string :tag "Toml File Path") ) |
| 58 | + :safe (lambda (it) (or (stringp it) (null it)))) |
| 59 | + |
| 60 | +(defcustom lsp-typos-diagnostic-severity "Warning" |
| 61 | + "Severity level for typos diagnostics. |
| 62 | +Can be one of \"Error\",\"Warning\", \"Information\", or \"Hint\"." |
| 63 | + :group 'lsp-typos |
| 64 | + :type '(choice |
| 65 | + (const :tag "Error" "Error") |
| 66 | + (const :tag "Warning" "Warning") |
| 67 | + (const :tag "Information" "Information") |
| 68 | + (const :tag "Hint" "Hint")) |
| 69 | + :safe #'stringp) |
| 70 | + |
| 71 | +(lsp-register-client |
| 72 | + (make-lsp-client |
| 73 | + :new-connection (lsp-stdio-connection lsp-typos-path) |
| 74 | + :activation-fn (lambda (_file-name _mode) lsp-typos-enable) |
| 75 | + :initialization-options (lambda () |
| 76 | + (append (when lsp-typos-config |
| 77 | + `(:config ,lsp-typos-config)) |
| 78 | + `(:diagnosticSeverity ,lsp-typos-diagnostic-severity))) |
| 79 | + :priority -1 |
| 80 | + :add-on? t |
| 81 | + :multi-root t |
| 82 | + :server-id 'typos-lsp)) |
| 83 | + |
| 84 | +(provide 'lsp-typos) |
| 85 | +;;; lsp-typos.el ends here |
0 commit comments