diff --git a/.gitmodules b/.gitmodules index 3e378f55e..b83bf4ade 100644 --- a/.gitmodules +++ b/.gitmodules @@ -378,6 +378,9 @@ [submodule "tablist"] path = lib/tablist url = git@github.com:politza/tablist.git +[submodule "tide"] + path = lib/tide + url = git@github.com:ananthakumaran/tide.git [submodule "transient"] path = lib/transient url = git@github.com:magit/transient.git @@ -387,6 +390,9 @@ [submodule "tuareg"] path = lib/tuareg url = git@github.com:ocaml/tuareg.git +[submodule "typescript-mode"] + path = lib/typescript-mode + url = git@github.com:emacs-typescript/typescript.el.git [submodule "use-package"] path = lib/use-package url = git@github.com:jwiegley/use-package.git @@ -428,3 +434,9 @@ [submodule "zprint-mode"] path = lib/zprint-mode url = git@github.com:pesterhazy/zprint-mode.el.git +[submodule "lib/typescript-mode"] + path = lib/typescript-mode + url = git@github.com:emacs-typescript/typescript.el.git +[submodule "lib/tide"] + path = lib/tide + url = git@github.com:ananthakumaran/tide.git diff --git a/lib/prettier-js b/lib/prettier-js deleted file mode 160000 index e9b73e81d..000000000 --- a/lib/prettier-js +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e9b73e81d3e1642aec682195f127a42dfb0b5774 diff --git a/lib/tide b/lib/tide new file mode 160000 index 000000000..1e376e3e9 --- /dev/null +++ b/lib/tide @@ -0,0 +1 @@ +Subproject commit 1e376e3e9798206ea3e42a5c037a7c00aa64ee00 diff --git a/lib/typescript-mode b/lib/typescript-mode new file mode 160000 index 000000000..b369d7d25 --- /dev/null +++ b/lib/typescript-mode @@ -0,0 +1 @@ +Subproject commit b369d7d2518fa11760ac3908a383405350cd51d2 diff --git a/packs/dev/lang-pack/config/typescript-conf.el b/packs/dev/lang-pack/config/typescript-conf.el new file mode 100644 index 000000000..80144f309 --- /dev/null +++ b/packs/dev/lang-pack/config/typescript-conf.el @@ -0,0 +1,80 @@ +;;; typescript-conf.el --- Java Config + +;;; Commentary: + +;;; Code: + +(live-add-pack-lib "smartparens") +(live-add-pack-lib "tide") +(live-add-pack-lib "typescript.el") + +;; Largely inspired by https://pastebin.com/hmezXa2e + +(defun ar-emacs--setup-tsx-company-backends () + "Set up the company-backends for tsx files." + (make-local-variable 'company-backends) + (setq company-backends + '((company-tide company-files :with company-yasnippet :with company-dabbrev-code) + (company-dabbrev-code company-dabbrev)))) + +(defun ar-emacs--tsserver-from-node-modules () + "Use your node_modules's TSServer to avoid possible version mismatches. + +Put this in .dir-locals.el: + + ((typescript-mode . ((eval . (setq tide-tsserver-executable (ar-emacs--tsserver-from-node-modules)))))) +" + (let* ((node-module-path "node_modules/.bin/tsserver") + (root (projectile-project-root))) + (expand-file-name node-module-path root))) + +(defun ar-emacs--tslint-from-node-modules () + "Use your node_modules's TSServer to avoid possible version mismatches. + +Put this in .dir-locals.el: + + ((typescript-mode . ((eval . (setq flycheck-typescript-tslint-executable (ar-emacs--tslint-from-node-modules)))))) +" + (let* ((node-module-path "node_modules/.bin/tslint") + (root (projectile-project-root))) + (expand-file-name node-module-path root))) + +(use-package typescript-mode + :mode ("\\.ts\\'") + :init + (require 'smartparens-javascript) + :hook + ((typescript-mode . company-mode) + (typescript-mode . smartparens-strict-mode) + (typescript-mode . subword-mode) + (typescript-mode . eldoc-mode) + (typescript-mode . which-key-mode) + (typescript-mode . tide-setup) + (typescript-mode . tide-hl-identifier-mode)) + :custom + (typescript-indent-level 2) + (flycheck-check-syntax-automatically '(save mode-enabled)) + :config + (flycheck-add-mode 'typescript-tslint 'typescript-mode) + (flycheck-add-next-checker 'typescript-tide '(t . typescript-tslint) 'append)) + +(use-package tide + :init + (setq tide-tsserver-logs-folder (expand-file-name "tsserver" live-tmp-dir)) + (setq tide-tsserver-process-environment (format "TSS_LOG=-level verbose -file %s" tide-tsserver-logs-folder))) + +;; aligns annotation to the right hand side +;; (setq company-tooltip-align-annotations t) + +;; From Spacemacs +(defun ts-open-region-in-playground (start end) + "Open selected START to END characters (region) in the TypeScript Playground. + +If nothing is selected - open the whole current buffer." + (interactive (if (use-region-p) + (list (region-beginning) (region-end)) + (list (point-min) (point-max)))) + (browse-url (concat "http://www.typescriptlang.org/Playground#src=" + (url-hexify-string (buffer-substring-no-properties start end))))) + +;;; typescript-conf.el ends here diff --git a/packs/dev/lang-pack/init.el b/packs/dev/lang-pack/init.el index 37a30d000..3e97be0aa 100644 --- a/packs/dev/lang-pack/init.el +++ b/packs/dev/lang-pack/init.el @@ -18,6 +18,28 @@ ((json-reformat:indent-width 2 "Set width to 2") (js-indent-level 2 "Set indent level to 2"))) +(use-package web-mode + :mode ("\\.jsx\\'" "\\.tsx\\'") + :hook + ((web-mode . company-mode) + (web-mode . smartparens-strict-mode) + (web-mode . subword-mode) + (web-mode . eldoc-mode) + (web-mode . which-key-mode) + (web-mode . tide-setup) + (web-mode . tide-hl-identifier-mode) + (web-mode . ar-emacs--setup-tsx-company-backends)) + :custom + (web-mode-content-types-alist '(("jsx" . "\\.[jt]sx?\\'"))) + (web-mode-enable-auto-pairing t) + (web-mode-enable-auto-closing t) + (web-mode-enable-current-element-highlight t) + (company-transformers '(company-sort-by-backend-importance)) + (flycheck-check-syntax-automatically '(save mode-enabled)) + :config + (flycheck-add-mode 'typescript-tslint 'web-mode) + (flycheck-add-next-checker 'typescript-tide '(t . typescript-tslint) 'append)) + (live-load-config-file "flycheck-conf.el") (live-load-config-file "yaml-conf.el") (live-load-config-file "plantuml-conf.el") @@ -29,5 +51,6 @@ (live-load-config-file "java-conf.el") (live-load-config-file "javascript-conf.el") (live-load-config-file "go-conf.el") +(live-load-config-file "typescript-conf.el") ;;; init.el ends here