Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql): Prevent the graphql server from accidentally starting with a TypeSpec file #4639

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/lsp-graphql.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

(defun lsp-graphql-activate-p (filename &optional _)
"Check if the GraphQL language server should be enabled based on FILENAME."
(let ((target-extensions (mapconcat 'identity lsp-graphql-target-file-extensions "\\|")))
(or (string-match-p (format "\\.%s\\'" target-extensions) filename)
(let ((target-extensions (mapconcat (lambda (e) (format "\\.%s\\'" e)) lsp-graphql-target-file-extensions "\\|")))
(or (string-match-p target-extensions filename)
(and (derived-mode-p 'js-mode 'js2-mode 'typescript-mode 'typescript-ts-mode)
(not (derived-mode-p 'json-mode))))))

Expand Down
44 changes: 44 additions & 0 deletions test/lsp-graphql-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;;; lsp-graphql-test.el --- unit tests for lsp-graphql.el -*- lexical-binding: t -*-

;; Copyright (C) 2024 ncaq <ncaq@ncaq.net>

;; Author: ncaq <ncaq@ncaq.net>
;; 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 'ert)
(require 'lsp-graphql)

(ert-deftest lsp-graphql-activate-p-based-on-file-extension ()
(should (lsp-graphql-activate-p "abc.ts"))
(should (lsp-graphql-activate-p "abc.js"))
(should (lsp-graphql-activate-p "abc.jsx"))
(should (lsp-graphql-activate-p "abc.tsx"))
(should (lsp-graphql-activate-p "abc.vue"))
(should (lsp-graphql-activate-p "abc.graphql"))
(should (lsp-graphql-activate-p "abc.graphqls"))
(should (lsp-graphql-activate-p "abc.gql"))
(should-not (lsp-graphql-activate-p "abc.tsxx"))
(should-not (lsp-graphql-activate-p "abc.jss"))
(should-not (lsp-graphql-activate-p "abc.tsp"))
(should-not (lsp-graphql-activate-p "js.hs")))

;;; lsp-graphql-test.el ends here
Loading