blob: 3b1bfba7b65f588e459fd6dd281ef5a27379ec93 (
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
|
;;; lsp-graphql.el --- lsp client for graphql -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Binbin Ye
;; Author: Binbin Ye
;; Keywords: lsp, graphql
;; 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:
;; Support for running graphql lsp. Support multiple server running at the same time when editing tsx/jsx.
;;; Code:
(require 'lsp-mode)
(lsp-dependency 'graphql-language-service-cli
'(:npm :package "graphql-language-service-cli"
:path "graphql-lsp"))
(defgroup lsp-graphql nil
"LSP support for the GraphQL, using the graphql-language-service-cli as language server."
:link '(url-link "https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme")
:group 'lsp-mode)
(defcustom lsp-clients-graphql-server-args '("server" "--method=stream")
"CLI arguments for graphql language server."
:type '(repeat string)
:risky t
:group 'lsp-graphql)
(defun lsp-graphql-activate-p (filename &optional _)
"Check if the GraphQL language server should be enabled based on FILENAME."
(or (string-match-p (rx (one-or-more anything) "."
(or "ts" "js" "jsx" "tsx" "vue" "graphql" "gql")eos)
filename)
(and (derived-mode-p 'js-mode 'js2-mode 'typescript-mode)
(not (derived-mode-p 'json-mode)))))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection (lambda()
(cons (lsp-package-path 'graphql-language-service-cli)
lsp-clients-graphql-server-args)))
:major-modes '(graphql-mode)
:language-id "graphql"
:server-id 'graphql-lsp
:priority -3
:add-on? t
:multi-root t
:activation-fn 'lsp-graphql-activate-p
:download-server-fn (lambda (_client callback error-callback _update?)
(lsp-package-ensure
'graphql-language-service-cli
callback
error-callback))))
(lsp-consistency-check lsp-graphql)
(provide 'lsp-graphql)
;;; lsp-graphql.el ends here
|