Set up LSP and js-comint for javascript editing

This commit is contained in:
Jeremy Dormitzer 2021-04-05 10:44:49 -04:00
parent 4f7594b71f
commit a6f2b96937

View File

@ -4,6 +4,41 @@
(use-package nvm (use-package nvm
:commands (nvm-use :commands (nvm-use
nvm-use-for nvm-use-for
nvm-use-for-buffer)) nvm-use-for-buffer
nvm--installed-versions)
:init
(defun nvm (version)
(interactive (list
(completing-read "Node version: "
(mapcar #'car
(nvm--installed-versions)))))
(nvm-use version)))
(use-package js
:straight (:type built-in)
:defer t
:config
(add-hook 'js-mode-hook #'lsp-deferred))
;; Make sure we load LSP in React files
(with-eval-after-load 'lsp-clients
(defun lsp-typescript-javascript-tsx-jsx-activate-p (filename major-mode)
"Checks if the javascript-typescript language server should be enabled
based on FILE-NAME and MAJOR-MODE"
(or (member major-mode '(typescript-mode typescript-tsx-mode js-mode js2-mode rjsx-mode))
(and (eq major-mode 'web-mode)
(or (string-suffix-p ".tsx" filename t)
(string-suffix-p ".jsx" filename t)
(string-suffix-p ".js" filename t))))))
(use-package js-comint
:commands (run-js)
:config
(js-do-use-nvm)
:general
(js-mode-map "C-c M-j" #'run-js
"C-x C-e" #'js-send-last-sexp
"C-c C-k" #'js-send-buffer
"C-c M-z" #'js-send-buffer-and-go))
(provide 'init-js) (provide 'init-js)