Skip to content

Commit e1bdae2

Browse files
Added more LSP support for Python by adding ruff-lsp support. (#3926)
* Added more LSP support for Python by adding ruff-lsp support. * Changed (if CUSTOM-BOOLEAN-OPTION t :json-false) uses in clients/lsp-ruff-lsp.el to (lsp-json-bool CUSTOM-BOOLEAN-OPTION). * Set add-on? to t on clients/lsp-ruff-lsp.el. * Added the missing values for the logLevel option in the ruff-lsp client (clients/lsp-ruff-lsp.el). * Added the showNotifications option to the ruff-lsp client (clients/lsp-ruff-lsp.el). * Added the importStrategy option to the ruff-lsp client (clients/lsp-ruff-lsp.el). --------- Co-authored-by: Ivan Yonchovski <yyoncho@users.noreply.github.com>
1 parent a655f36 commit e1bdae2

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
* Add ~lsp-clients-typescript-prefer-use-project-ts-server~ custom
6666
variable to try to use the project's tsserver.js instead of the
6767
one installed by lsp-mode.
68+
* Add [[https://github.com/charliermarsh/ruff-lsp][ruff-lsp]] support (additional server for Python).
6869
* Update documentation of Vue3 install server
6970
** Release 8.0.0
7071
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.

clients/lsp-ruff-lsp.el

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
;;; lsp-ruff-lsp.el --- ruff-lsp support -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2023 Freja Nordsiek
4+
;;
5+
;; Author: Freja Nordsiek <fnordsie@posteo.net
6+
;; Keywords: language tools
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+
;; ruff-lsp Client for the Python programming language
24+
25+
;;; Code:
26+
27+
(require 'lsp-mode)
28+
29+
(defgroup lsp-ruff-lsp nil
30+
"LSP support for Python, using ruff-lsp's Python Language Server."
31+
:group 'lsp-mode
32+
:link '(url-link "https://github.com/charliermarsh/ruff-lsp"))
33+
34+
(defcustom lsp-ruff-lsp-server-command '("ruff-lsp")
35+
"Command to start ruff-lsp."
36+
:risky t
37+
:type '(repeat string)
38+
:group 'lsp-ruff-lsp)
39+
40+
(defcustom lsp-ruff-lsp-ruff-path ["ruff"]
41+
"Paths to ruff to try, in order."
42+
:risky t
43+
:type 'lsp-string-vector
44+
:group 'lsp-ruff-lsp)
45+
46+
(defcustom lsp-ruff-lsp-ruff-args []
47+
"Arguments, passed to ruff."
48+
:risky t
49+
:type 'lsp-string-vector
50+
:group 'lsp-ruff-lsp)
51+
52+
(defcustom lsp-ruff-lsp-log-level "error"
53+
"Tracing level."
54+
:type '(choice (const "debug")
55+
(const "error")
56+
(const "info")
57+
(const "off")
58+
(const "warn"))
59+
:group 'lsp-ruff-lsp)
60+
61+
(defcustom lsp-ruff-lsp-python-path "python3"
62+
"Path to the Python interpreter."
63+
:risky t
64+
:type 'string
65+
:group 'lsp-ruff-lsp)
66+
67+
(defcustom lsp-ruff-lsp-show-notifications "off"
68+
"When notifications are shown."
69+
:type '(choice (const "off")
70+
(const "onError")
71+
(const "onWarning")
72+
(const "always"))
73+
:group 'lsp-ruff-lsp)
74+
75+
(defcustom lsp-ruff-lsp-advertize-organize-imports t
76+
"Whether to report ability to handle source.organizeImports actions."
77+
:type 'boolean
78+
:group 'lsp-ruff-lsp)
79+
80+
(defcustom lsp-ruff-lsp-advertize-fix-all t
81+
"Whether to report ability to handle source.fixAll actions."
82+
:type 'boolean
83+
:group 'lsp-ruff-lsp)
84+
85+
(defcustom lsp-ruff-lsp-import-strategy "fromEnvironment"
86+
"Where ruff is imported from if lsp-ruff-lsp-ruff-path is not set."
87+
:type '(choice (const "fromEnvironment")
88+
(const "useBundled"))
89+
:group 'lsp-ruff-lsp)
90+
91+
92+
(lsp-register-client
93+
(make-lsp-client
94+
:new-connection (lsp-stdio-connection
95+
(lambda () lsp-ruff-lsp-server-command))
96+
:activation-fn (lsp-activate-on "python")
97+
:server-id 'ruff-lsp
98+
:priority -2
99+
:add-on? t
100+
:initialization-options
101+
(lambda ()
102+
(list :settings
103+
(list :args lsp-ruff-lsp-ruff-args
104+
:logLevel lsp-ruff-lsp-log-level
105+
:path lsp-ruff-lsp-ruff-path
106+
:interpreter (vector lsp-ruff-lsp-python-path)
107+
:showNotifications lsp-ruff-lsp-show-notifications
108+
:organizeImports (lsp-json-bool lsp-ruff-lsp-advertize-organize-imports)
109+
:fixAll (lsp-json-bool lsp-ruff-lsp-advertize-fix-all)
110+
:importStrategy lsp-ruff-lsp-import-strategy)))))
111+
112+
(lsp-consistency-check lsp-ruff-lsp)
113+
114+
(provide 'lsp-ruff-lsp)
115+
;;; lsp-ruff-lsp.el ends here

docs/lsp-clients.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,14 @@
699699
"installation": "pip install robotframework --user",
700700
"debugger": "Yes"
701701
},
702+
{
703+
"name": "ruff-lsp",
704+
"full-name": "Python",
705+
"server-name": "ruff-lsp",
706+
"server-url": "https://github.com/charliermarsh/ruff-lsp",
707+
"installation": "pip install ruff-lsp",
708+
"debugger": "Not available"
709+
},
702710
{
703711
"name": "rust-analyzer",
704712
"common-group-name": "rust",

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ nav:
120120
- Python (Palantir deprecated): page/lsp-pyls.md
121121
- Python (Pyright): https://emacs-lsp.github.io/lsp-pyright
122122
- Python (Microsoft): https://emacs-lsp.github.io/lsp-python-ms
123+
- Python (Ruff): page/lsp-ruff-lsp.md
123124
- R: page/lsp-r.md
124125
- Racket (jeapostrophe): page/lsp-racket-langserver.md
125126
- Racket (Theia): page/lsp-racket-language-server.md

0 commit comments

Comments
 (0)