From 526b6c00483cd86a028805e31ebd8a4a7000c3da Mon Sep 17 00:00:00 2001 From: Graham Marlow Date: Mon, 11 Sep 2023 19:02:43 -0700 Subject: [PATCH] Add deno-tsx-ts-mode and automatically configure Eglot --- CHANGELOG.org | 11 +++++++++++ README.md | 5 ++--- deno-ts-mode.el | 27 ++++++++++++++++----------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 8d5d684..d0e7af8 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -1,5 +1,16 @@ * deno-ts-mode changelog +** 0.3.0 + +Breaking: + +- Remove =deno-ts-setup-eglot= in favor of automatically adding Eglot + server programs for both =deno-ts-mode= and =deno-tsx-ts-mode=. + +Other: + +- New major mode: =deno-tsx-ts-mode= for TSX and JSX support. + ** 0.2.0 Breaking: diff --git a/README.md b/README.md index 9854985..52a9bac 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,8 @@ M-x deno-ts-run-task (use-package eglot :ensure t - :hook ((deno-ts-mode . eglot-ensure)) - :config - (deno-ts-setup-eglot)) + :hook ((deno-ts-mode . eglot-ensure) + (deno-tsx-ts-mode . eglot-ensure))) ``` ## Contributing diff --git a/deno-ts-mode.el b/deno-ts-mode.el index 8af87dd..fb78c56 100644 --- a/deno-ts-mode.el +++ b/deno-ts-mode.el @@ -5,7 +5,7 @@ ;; Author: Graham Marlow ;; Keywords: languages ;; URL: https://git.sr.ht/~mgmarlow/deno-ts-mode -;; Version: 0.2.0 +;; Version: 0.3.0 ;; Package-Requires: ((emacs "29.1")) ;; This program is free software; you can redistribute it and/or modify @@ -43,9 +43,8 @@ ;; ;; (use-package eglot ;; :ensure t -;; :hook ((deno-ts-mode . eglot-ensure)) -;; :config -;; (deno-ts-setup-eglot)) +;; :hook ((deno-ts-mode . eglot-ensure) +;; (deno-tsx-ts-mode . eglot-ensure))) ;;; Code: @@ -83,12 +82,6 @@ Return nil if `project-current' is not a Deno project or the current project cannot be read." (and (deno-ts-project-config-path) t)) -;; https://deno.land/manual@v1.36.1/getting_started/setup_your_environment#eglot -(defun deno-ts-setup-eglot () - "Add `deno-ts-mode' to `eglot-server-programs'." - (add-to-list 'eglot-server-programs - '(deno-ts-mode . ("deno" "lsp" :initializationOptions (:enable t :lint t))))) - (cl-defstruct deno-ts-config "Deno configuration file struct." tasks lint fmt test) @@ -126,6 +119,12 @@ Return nil if no project is found." "Major mode for Deno." :group 'deno-ts-mode) +;;;###autoload +(define-derived-mode deno-tsx-ts-mode + tsx-ts-mode "Deno[TSX]" + "Major mode for TSX and JSX with Deno." + :group 'deno-ts-mode) + ;;;###autoload (defun deno-ts-mode-maybe () "Maybe activate `deno-ts-mode'. @@ -140,7 +139,7 @@ activated. Otherwise, fallback to either `typescript-ts-mode' or ((equal "ts" ext) (typescript-ts-mode)) ((and (equal "tsx" ext) (deno-ts-project-p)) - (deno-ts-mode)) + (deno-tsx-ts-mode)) ((equal "tsx" ext) (tsx-ts-mode))))) @@ -158,6 +157,12 @@ activated. Otherwise, fallback to either `typescript-ts-mode' or (equal (cdr x) 'tsx-ts-mode)))) auto-mode-alist))) +;; Register eglot server program for TS and TSX. +(dolist (mode '(deno-ts-mode deno-tsx-ts-mode)) + (add-to-list 'eglot-server-programs + (cons mode '("deno" "lsp" :initializationOptions + (:enable t :lint t :unstable t))))) + ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ts\\'" . deno-ts-mode-maybe)) -- 2.45.2