aboutsummaryrefslogtreecommitdiffstats
path: root/elpa/lsp-mode-20220505.630/lsp-solargraph.el
blob: 968b32ade3917882deaccd0d5e92e478146b6616 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
;;; lsp-solargraph.el --- Solargraph server configuration  -*- lexical-binding: t; -*-

;; Copyright (C) 2019  Ivan Yonchovski

;; Author: Ivan Yonchovski <yyoncho@gmail.com>
;; Keywords:

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'lsp-mode)

(defgroup lsp-solargraph nil
  "LSP support for Ruby, using the Solargraph language server."
  :group 'lsp-mode
  :link '(url-link "https://github.com/castwide/solargraph")
  :package-version '(lsp-mode . "6.1"))

;; (defcustom lsp-solargraph-check-gem-version t
;;   "Automatically check if a new version of the Solargraph gem is available."
;;   :type 'boolean)

(defcustom lsp-solargraph-completion t
  "Enable completion"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-hover t
  "Enable hover"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-diagnostics t
  "Enable diagnostics"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-autoformat nil
  "Enable automatic formatting while typing (WARNING: experimental)"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-formatting t
  "Enable document formatting"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-symbols t
  "Enable symbols"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-definitions t
  "Enable definitions (go to, etc.)"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-rename t
  "Enable symbol renaming"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-references t
  "Enable finding references"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-folding t
  "Enable folding ranges"
  :type 'boolean
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-log-level "warn"
  "Level of debug info to log. `warn` is least and `debug` is most."
  :type '(choice (const :tag "warn" "info" "debug"))
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

;; https://github.com/castwide/solargraph#solargraph-and-bundler
(defcustom lsp-solargraph-use-bundler nil
  "Run solargraph under bundler"
  :type 'boolean
  :safe #'booleanp
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.1"))

(defcustom lsp-solargraph-multi-root t
  "If non nil, `solargraph' will be started in multi-root mode."
  :type 'boolean
  :safe #'booleanp
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "6.3"))

(defcustom lsp-solargraph-library-directories
  '("~/.rbenv/" "/usr/lib/ruby/" "~/.rvm/" "~/.gem/")
  "List of directories which will be considered to be libraries."
  :type '(repeat string)
  :group 'lsp-solargraph
  :package-version '(lsp-mode . "7.0.1"))

(defun lsp-solargraph--build-command ()
  "Build solargraph command"
  (let ((lsp-command '("solargraph" "stdio")))
    (if lsp-solargraph-use-bundler
              (append '("bundle" "exec") lsp-command)
            lsp-command)))

(lsp-register-custom-settings
 '(("solargraph.logLevel" lsp-solargraph-log-level)
   ("solargraph.folding" lsp-solargraph-folding t)
   ("solargraph.references" lsp-solargraph-references t)
   ("solargraph.rename" lsp-solargraph-rename t)
   ("solargraph.definitions" lsp-solargraph-definitions t)
   ("solargraph.symbols" lsp-solargraph-symbols t)
   ("solargraph.formatting" lsp-solargraph-formatting t)
   ("solargraph.autoformat" lsp-solargraph-autoformat t)
   ("solargraph.diagnostics" lsp-solargraph-diagnostics t)
   ("solargraph.hover" lsp-solargraph-hover t)
   ("solargraph.completion" lsp-solargraph-completion t)
   ("solargraph.useBundler" lsp-solargraph-use-bundler t)))

;; Ruby
(lsp-register-client
 (make-lsp-client
  :new-connection (lsp-stdio-connection
                   #'lsp-solargraph--build-command)
  :major-modes '(ruby-mode enh-ruby-mode)
  :priority -1
  :multi-root lsp-solargraph-multi-root
  :library-folders-fn (lambda (_workspace) lsp-solargraph-library-directories)
  :server-id 'ruby-ls
  :initialized-fn (lambda (workspace)
                    (with-lsp-workspace workspace
                      (lsp--set-configuration
                       (lsp-configuration-section "solargraph"))))))

(lsp-consistency-check lsp-solargraph)

(provide 'lsp-solargraph)
;;; lsp-solargraph.el ends here