lsp-graphql.el (3013B)
1 ;;; lsp-graphql.el --- lsp client for graphql -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2021 Binbin Ye 4 5 ;; Author: Binbin Ye 6 ;; Keywords: lsp, graphql 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 ;; Support for running graphql lsp. Support multiple server running at the same time when editing tsx/jsx. 24 25 ;;; Code: 26 27 (require 'lsp-mode) 28 29 (lsp-dependency 'graphql-language-service-cli 30 '(:system "graphql-lsp") 31 '(:npm :package "graphql-language-service-cli" 32 :path "graphql-lsp")) 33 34 35 (defgroup lsp-graphql nil 36 "LSP support for the GraphQL, using the graphql-language-service-cli as language server." 37 :link '(url-link "https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme") 38 :group 'lsp-mode) 39 40 (defcustom lsp-clients-graphql-server-args '("server" "--method=stream") 41 "CLI arguments for graphql language server." 42 :type '(repeat string) 43 :risky t 44 :group 'lsp-graphql) 45 46 (defun lsp-graphql-activate-p (filename &optional _) 47 "Check if the GraphQL language server should be enabled based on FILENAME." 48 (or (string-match-p (rx (one-or-more anything) "." 49 (or "ts" "js" "jsx" "tsx" "vue" "graphql" "gql")eos) 50 filename) 51 (and (derived-mode-p 'js-mode 'js2-mode 'typescript-mode 'typescript-ts-mode) 52 (not (derived-mode-p 'json-mode))))) 53 54 (lsp-register-client 55 (make-lsp-client :new-connection (lsp-stdio-connection (lambda() 56 (cons (lsp-package-path 'graphql-language-service-cli) 57 lsp-clients-graphql-server-args))) 58 :major-modes '(graphql-mode) 59 :language-id "graphql" 60 :server-id 'graphql-lsp 61 :priority -3 62 :add-on? t 63 :multi-root t 64 :activation-fn 'lsp-graphql-activate-p 65 :download-server-fn (lambda (_client callback error-callback _update?) 66 (lsp-package-ensure 67 'graphql-language-service-cli 68 callback 69 error-callback)))) 70 71 (lsp-consistency-check lsp-graphql) 72 73 (provide 'lsp-graphql) 74 ;;; lsp-graphql.el ends here