Skip to content

Commit 37cce4d

Browse files
d4nceryyoncho
authored andcommitted
Extend JS/TS LS to work with any web-mode derived mode (#788)
* Extend JS/TS LS to work with any web-mode derived mode * Check file suffix only * Update JS/TS check to use regex * Integrate review suggestions
1 parent 4c87e81 commit 37cce4d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lsp-clients.el

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ finding the executable with variable `exec-path'."
9797
:risky t
9898
:type '(repeat string))
9999

100-
(defun lsp-typescript-javascript-tsx-jsx-activate-p (filename mode)
101-
"Check if the javascript-typescript language server should be enabled
102-
based on FILE-NAME and MAJOR-MODE"
103-
(or (member mode '(typescript-mode typescript-tsx-mode js-mode js-jsx-mode js2-mode js2-jsx-mode rjsx-mode))
104-
(and (eq major-mode 'web-mode)
105-
(or (string-suffix-p ".tsx" filename t)
106-
(string-suffix-p ".jsx" filename t)))))
100+
(defun lsp-typescript-javascript-tsx-jsx-activate-p (filename &optional _)
101+
"Check if the javascript-typescript language server should be enabled based on FILENAME."
102+
(string-match-p (rx (one-or-more char) "." (or "ts" "js") (opt "x") string-end) filename))
107103

108104
(lsp-register-client
109105
(make-lsp-client :new-connection (lsp-stdio-connection (lambda ()

test/lsp-clients-test.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,14 @@
7575
(let ((major-mode 'js-mode))
7676
(should (not (lsp-clients-flow-activate-p (concat test-location "fixtures/SampleTypeScriptProject/src/sample.ts") nil)))))
7777

78+
(ert-deftest lsp-typescript-javascript-activates-based-on-file-extension ()
79+
(should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.js"))
80+
(should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.jsx"))
81+
(should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.ts"))
82+
(should (lsp-typescript-javascript-tsx-jsx-activate-p "abc.tsx"))
83+
(should (lsp-typescript-javascript-tsx-jsx-activate-p "a1.ts"))
84+
(should (lsp-typescript-javascript-tsx-jsx-activate-p "a1.d.ts"))
85+
(should (not (lsp-typescript-javascript-tsx-jsx-activate-p "abc.tsxx")))
86+
(should (not (lsp-typescript-javascript-tsx-jsx-activate-p "abc.jss"))))
87+
7888
;;; lsp-clients-test.el ends here

0 commit comments

Comments
 (0)