~mgmarlow/deno-ts-mode

7429ad5bba931809627b4bc0fc69425839d2fc89 — Graham Marlow 1 year, 20 days ago b971799
fix: Separate ts and tsx auto-mode fallbacks

Fixes the problem where the fallback is always typescript-ts-mode even
when the user is in a tsx file.
1 files changed, 8 insertions(+), 2 deletions(-)

M deno-ts-mode.el
M deno-ts-mode.el => deno-ts-mode.el +8 -2
@@ 58,18 58,24 @@
  "Major mode for Deno."
  :group 'deno-ts-mode)

(defun deno-ts--auto-mode ()
(defun deno-ts--ts-auto-mode ()
  "Return `deno-ts-mode' if project is a Deno project, else `typescript-ts-mode'."
  (cond ((deno-ts-project-p) (deno-ts-mode))
        (t (typescript-ts-mode))))

(defun deno-ts--tsx-auto-mode ()
  "Return `deno-ts-mode' if project is a Deno project, else `tsx-ts-mode'."
  (cond ((deno-ts-project-p) (deno-ts-mode))
        (t (tsx-ts-mode))))

(defun deno-ts-setup-auto-mode-alist ()
  "Add Deno to `auto-mode-alist' for .ts and .tsx files.

If the visited .ts file does not detect a Deno project (as
determined by `deno-project-p') this function will fallback to
`typescript-ts-mode'."
  (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . deno-ts--auto-mode)))
  (add-to-list 'auto-mode-alist '("\\.ts\\'" . deno-ts--ts-auto-mode))
  (add-to-list 'auto-mode-alist '("\\.tsx\\'" . deno-ts--tsx-auto-mode)))

(provide 'deno-ts-mode)
;;; deno-ts-mode.el ends here