Skip to content

Commit 70b3e6c

Browse files
authored
Add lsp-typos (#4868)
* fix lsp-headerline to deal with nil value * add lsp-typos
1 parent c74a723 commit 70b3e6c

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

clients/lsp-typos.el

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

docs/lsp-clients.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,14 @@
12701270
"installation": "It is included in Ruby >= 3.1",
12711271
"debugger": "Not available"
12721272
},
1273+
{
1274+
"name": "typos",
1275+
"full-name": "Typos source code spell checker",
1276+
"server-name": "typos-lsp",
1277+
"server-url": "https://github.com/tekumara/typos-lsp",
1278+
"installation": "cargo install --git https://github.com/tekumara/typos-lsp typos-lsp",
1279+
"debugger": "Not available"
1280+
},
12731281
{
12741282
"name": "ttcn3",
12751283
"full-name": "TTCN3",

lsp-headerline.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ PATH is the current folder to be checked."
306306
"Get the severity level for RANGE."
307307
(let ((range-severity 10))
308308
(mapc (-lambda ((&Diagnostic :range (&Range :start) :severity?))
309-
(when (lsp-point-in-range? start range)
309+
(when (and severity?
310+
(lsp-point-in-range? start range))
310311
(setq range-severity (min range-severity severity?))))
311312
(lsp--get-buffer-diagnostics))
312313
range-severity))

lsp-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ As defined by the Language Server Protocol 3.16."
192192
lsp-solargraph lsp-solidity lsp-sonarlint lsp-sorbet lsp-sourcekit
193193
lsp-sql lsp-sqls lsp-steep lsp-svelte lsp-tailwindcss lsp-terraform
194194
lsp-tex lsp-tilt lsp-toml lsp-toml-tombi lsp-trunk lsp-ts-query lsp-ttcn3 lsp-typeprof
195-
lsp-typespec lsp-v lsp-vala lsp-verilog lsp-vetur lsp-vhdl lsp-vimscript
195+
lsp-typespec lsp-typos lsp-v lsp-vala lsp-verilog lsp-vetur lsp-vhdl lsp-vimscript
196196
lsp-volar lsp-wgsl lsp-xml lsp-yaml lsp-yang lsp-zig)
197197
"List of the clients to be automatically required."
198198
:group 'lsp-mode

0 commit comments

Comments
 (0)