Skip to content

Commit

Permalink
Add typescript config but remove prettier stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
arichiardi committed Aug 27, 2021
1 parent 805146c commit 82fa6e3
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .gitmodules
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion lib/prettier-js
Submodule prettier-js deleted from e9b73e
1 change: 1 addition & 0 deletions lib/tide
Submodule tide added at 1e376e
1 change: 1 addition & 0 deletions lib/typescript-mode
Submodule typescript-mode added at b369d7
80 changes: 80 additions & 0 deletions 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
23 changes: 23 additions & 0 deletions packs/dev/lang-pack/init.el
Expand Up @@ -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")
Expand All @@ -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

0 comments on commit 82fa6e3

Please sign in to comment.