diff options
-rw-r--r-- | lisp/web.el | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/lisp/web.el b/lisp/web.el index c999e45..77c6ef9 100644 --- a/lisp/web.el +++ b/lisp/web.el @@ -23,27 +23,6 @@ (add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode)) (setq-default js-indent-level 2) -;; JavaScript -(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode)) -(push '("\\.js[x]?\\'" . javascript-mode) auto-mode-alist) - -;; TypeScript -(use-package tree-sitter-langs - :config - (tree-sitter-require 'tsx) - (add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx)) - ) -(use-package typescript-mode - :mode "\.ts\'" - :config (setq typescript-indent-level 2) - :init - (define-derived-mode typescript-tsx-mode typescript-mode "TypeScript[tsx]") - (add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)) - ) - - - - (require 'flycheck) (setq-default flycheck-disabled-checkers (append flycheck-disabled-checkers @@ -55,6 +34,9 @@ (flycheck-add-mode 'typescript-tslint 'typescript-mode) (add-hook 'js-mode-hook 'flycheck-mode) (add-hook 'typescript-mode-hook 'flycheck-mode) + +; use local eslint from node_modules before global +; http://emacs.stackexchange.com/questions/21205/flycheck-with-file-relative-eslint-executable (defun my-use-eslint-from-node-modules () "Use eslint from local node_modules instead of globally." (let* ((root (locate-dominating-file @@ -66,16 +48,26 @@ (when (and eslint (file-executable-p eslint)) (setq-local flycheck-javascript-eslint-executable eslint)))) (add-hook 'flycheck-mode-hook #'my-use-eslint-from-node-modules) +;; TSX +(use-package tree-sitter-langs + :config + (tree-sitter-require 'tsx) + (add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx)) + ) -; use local eslint from node_modules before global -; http://emacs.stackexchange.com/questions/21205/flycheck-with-file-relative-eslint-executable +(define-derived-mode typescript-tsx-mode web-mode "TypeScript[tsx]") +(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)) +(flycheck-add-mode 'typescript-tslint 'typescript-tsx-mode) +(add-hook 'typescript-tsx-mode 'flycheck-mode) ;; Package management (require 'eglot) (add-hook 'js-mode-hook 'eglot-ensure) (add-hook 'typescript-mode-hook 'eglot-ensure) +(add-hook 'typescript-tsx-mode-hook 'eglot-ensure) (add-to-list 'eglot-server-programs '(js-mode . ("typescript-language-server" "--stdio"))) (add-to-list 'eglot-server-programs '(typescript-mode . ("typescript-language-server" "--stdio"))) +(add-to-list 'eglot-server-programs '(typescript-tsx-mode . ("typescript-language-server" "--stdio"))) ;; Ignore certain directories in projectile (require 'projectile) |