config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

lsp-ruff.el (3277B)


      1 ;;; lsp-ruff.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 nil
     30   "LSP support for Python, using ruff's Python Language Server."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/astral-sh/ruff"))
     33 
     34 (defcustom lsp-ruff-server-command '("ruff" "server")
     35   "Command to start ruff lsp.
     36 Previous ruff-lsp should change this to (\"ruff-lsp\")"
     37   :risky t
     38   :type '(repeat string)
     39   :group 'lsp-ruff)
     40 
     41 (defcustom lsp-ruff-ruff-args '()
     42   "Arguments, passed to ruff."
     43   :risky t
     44   :type '(repeat string)
     45   :group 'lsp-ruff)
     46 
     47 (defcustom lsp-ruff-log-level "error"
     48   "Tracing level."
     49   :type '(choice (const "debug")
     50                  (const "error")
     51                  (const "info")
     52                  (const "off")
     53                  (const "warn"))
     54   :group 'lsp-ruff)
     55 
     56 (defcustom lsp-ruff-python-path "python3"
     57   "Path to the Python interpreter."
     58   :risky t
     59   :type 'string
     60   :group 'lsp-ruff)
     61 
     62 (defcustom lsp-ruff-show-notifications "off"
     63   "When notifications are shown."
     64   :type '(choice (const "off")
     65                  (const "onError")
     66                  (const "onWarning")
     67                  (const "always"))
     68   :group 'lsp-ruff)
     69 
     70 (defcustom lsp-ruff-advertize-organize-imports t
     71   "Whether to report ability to handle source.organizeImports actions."
     72   :type 'boolean
     73   :group 'lsp-ruff)
     74 
     75 (defcustom lsp-ruff-advertize-fix-all t
     76   "Whether to report ability to handle source.fixAll actions."
     77   :type 'boolean
     78   :group 'lsp-ruff)
     79 
     80 (defcustom lsp-ruff-import-strategy "fromEnvironment"
     81   "Where ruff is imported from if lsp-ruff-ruff-path is not set."
     82   :type '(choice (const "fromEnvironment")
     83                  (const "useBundled"))
     84   :group 'lsp-ruff)
     85 
     86 
     87 (lsp-register-client
     88  (make-lsp-client
     89   :new-connection (lsp-stdio-connection
     90                    (lambda () (append lsp-ruff-server-command lsp-ruff-ruff-args)))
     91   :activation-fn (lsp-activate-on "python")
     92   :server-id 'ruff
     93   :priority -2
     94   :add-on? t
     95   :initialization-options
     96   (lambda ()
     97     (list :settings
     98           (list :logLevel lsp-ruff-log-level
     99                 :showNotifications lsp-ruff-show-notifications
    100                 :organizeImports (lsp-json-bool lsp-ruff-advertize-organize-imports)
    101                 :fixAll (lsp-json-bool lsp-ruff-advertize-fix-all)
    102                 :importStrategy lsp-ruff-import-strategy)))))
    103 
    104 (lsp-consistency-check lsp-ruff)
    105 
    106 (provide 'lsp-ruff)
    107 ;;; lsp-ruff.el ends here