config

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

lsp-ruff-lsp.el (3613B)


      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