config

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

lsp-solargraph.el (5440B)


      1 ;;; lsp-solargraph.el --- Solargraph server configuration  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2019  Ivan Yonchovski
      4 
      5 ;; Author: Ivan Yonchovski <yyoncho@gmail.com>
      6 ;; Keywords:
      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 ;;
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-solargraph nil
     30   "LSP support for Ruby, using the Solargraph language server."
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/castwide/solargraph")
     33   :package-version '(lsp-mode . "6.1"))
     34 
     35 ;; (defcustom lsp-solargraph-check-gem-version t
     36 ;;   "Automatically check if a new version of the Solargraph gem is available."
     37 ;;   :type 'boolean)
     38 
     39 (defcustom lsp-solargraph-completion t
     40   "Enable completion"
     41   :type 'boolean
     42   :group 'lsp-solargraph
     43   :package-version '(lsp-mode . "6.1"))
     44 
     45 (defcustom lsp-solargraph-hover t
     46   "Enable hover"
     47   :type 'boolean
     48   :group 'lsp-solargraph
     49   :package-version '(lsp-mode . "6.1"))
     50 
     51 (defcustom lsp-solargraph-diagnostics t
     52   "Enable diagnostics"
     53   :type 'boolean
     54   :group 'lsp-solargraph
     55   :package-version '(lsp-mode . "6.1"))
     56 
     57 (defcustom lsp-solargraph-autoformat nil
     58   "Enable automatic formatting while typing (WARNING: experimental)"
     59   :type 'boolean
     60   :group 'lsp-solargraph
     61   :package-version '(lsp-mode . "6.1"))
     62 
     63 (defcustom lsp-solargraph-formatting t
     64   "Enable document formatting"
     65   :type 'boolean
     66   :group 'lsp-solargraph
     67   :package-version '(lsp-mode . "6.1"))
     68 
     69 (defcustom lsp-solargraph-symbols t
     70   "Enable symbols"
     71   :type 'boolean
     72   :group 'lsp-solargraph
     73   :package-version '(lsp-mode . "6.1"))
     74 
     75 (defcustom lsp-solargraph-definitions t
     76   "Enable definitions (go to, etc.)"
     77   :type 'boolean
     78   :group 'lsp-solargraph
     79   :package-version '(lsp-mode . "6.1"))
     80 
     81 (defcustom lsp-solargraph-rename t
     82   "Enable symbol renaming"
     83   :type 'boolean
     84   :group 'lsp-solargraph
     85   :package-version '(lsp-mode . "6.1"))
     86 
     87 (defcustom lsp-solargraph-references t
     88   "Enable finding references"
     89   :type 'boolean
     90   :group 'lsp-solargraph
     91   :package-version '(lsp-mode . "6.1"))
     92 
     93 (defcustom lsp-solargraph-folding t
     94   "Enable folding ranges"
     95   :type 'boolean
     96   :group 'lsp-solargraph
     97   :package-version '(lsp-mode . "6.1"))
     98 
     99 (defcustom lsp-solargraph-log-level "warn"
    100   "Level of debug info to log. `warn` is least and `debug` is most."
    101   :type '(choice (const :tag "warn" "info" "debug"))
    102   :group 'lsp-solargraph
    103   :package-version '(lsp-mode . "6.1"))
    104 
    105 ;; https://github.com/castwide/solargraph#solargraph-and-bundler
    106 (defcustom lsp-solargraph-use-bundler nil
    107   "Run solargraph under bundler"
    108   :type 'boolean
    109   :safe #'booleanp
    110   :group 'lsp-solargraph
    111   :package-version '(lsp-mode . "6.1"))
    112 
    113 (defcustom lsp-solargraph-multi-root t
    114   "If non nil, `solargraph' will be started in multi-root mode."
    115   :type 'boolean
    116   :safe #'booleanp
    117   :group 'lsp-solargraph
    118   :package-version '(lsp-mode . "6.3"))
    119 
    120 (defcustom lsp-solargraph-library-directories
    121   '("~/.rbenv/" "/usr/lib/ruby/" "~/.rvm/" "~/.gem/")
    122   "List of directories which will be considered to be libraries."
    123   :type '(repeat string)
    124   :group 'lsp-solargraph
    125   :package-version '(lsp-mode . "7.0.1"))
    126 
    127 (defcustom lsp-solargraph-server-command '("solargraph" "stdio")
    128   "Command to start Solargraph Ruby language server."
    129   :type '(repeat string)
    130   :group 'lsp-solargraph
    131   :package-version '(lsp-mode . "9.0.0"))
    132 
    133 (defun lsp-solargraph--build-command ()
    134   "Build solargraph command"
    135   (if lsp-solargraph-use-bundler
    136       (append '("bundle" "exec") lsp-solargraph-server-command)
    137     lsp-solargraph-server-command))
    138 
    139 (lsp-register-custom-settings
    140  '(("solargraph.logLevel" lsp-solargraph-log-level)
    141    ("solargraph.folding" lsp-solargraph-folding t)
    142    ("solargraph.references" lsp-solargraph-references t)
    143    ("solargraph.rename" lsp-solargraph-rename t)
    144    ("solargraph.definitions" lsp-solargraph-definitions t)
    145    ("solargraph.symbols" lsp-solargraph-symbols t)
    146    ("solargraph.formatting" lsp-solargraph-formatting t)
    147    ("solargraph.autoformat" lsp-solargraph-autoformat t)
    148    ("solargraph.diagnostics" lsp-solargraph-diagnostics t)
    149    ("solargraph.hover" lsp-solargraph-hover t)
    150    ("solargraph.completion" lsp-solargraph-completion t)
    151    ("solargraph.useBundler" lsp-solargraph-use-bundler t)))
    152 
    153 ;; Ruby
    154 (lsp-register-client
    155  (make-lsp-client
    156   :new-connection (lsp-stdio-connection
    157                    #'lsp-solargraph--build-command)
    158   :activation-fn (lsp-activate-on "ruby")
    159   :priority -1
    160   :multi-root lsp-solargraph-multi-root
    161   :library-folders-fn (lambda (_workspace) lsp-solargraph-library-directories)
    162   :server-id 'ruby-ls
    163   :initialized-fn (lambda (workspace)
    164                     (with-lsp-workspace workspace
    165                       (lsp--set-configuration
    166                        (lsp-configuration-section "solargraph"))))))
    167 
    168 (lsp-consistency-check lsp-solargraph)
    169 
    170 (provide 'lsp-solargraph)
    171 ;;; lsp-solargraph.el ends here