]> code.delx.au - dotemacs/commitdiff
Improved tide-project-root to understand git and package.json
authorJames Bunton <jbunton@atlassian.com>
Mon, 19 Nov 2018 07:19:26 +0000 (18:19 +1100)
committerJames Bunton <jbunton@atlassian.com>
Mon, 19 Nov 2018 07:19:26 +0000 (18:19 +1100)
lisp/my-file-modes.el

index 11456e23beed1240cd3e7789a3a996d5869cfbaa..a010ac7e68a865d4683ff0019017d725bcd22f2c 100644 (file)
 (add-hook 'typescript-mode-hook #'tide-setup)
 (add-hook 'typescript-mode-hook #'js2-refactor-mode)
 
+(defun tide-project-root ()
+  (or
+   tide-project-root
+   (let ((root (or (locate-dominating-file default-directory "tsconfig.json")
+                   (locate-dominating-file default-directory "jsconfig.json")
+                   (locate-dominating-file default-directory ".git")
+                   (locate-dominating-file default-directory "package.json"))))
+     (unless root
+       (message (tide-join (list "Couldn't locate JavaScript project root folder. Using '" default-directory "' as project root.")))
+       (setq root default-directory))
+     (let ((full-path (expand-file-name root)))
+       (setq tide-project-root full-path)
+       full-path))))
+
 (require 'js2-refactor)
 (js2r-add-keybindings-with-prefix "C-c C-m")
 (setq js2r-always-insert-parens-around-arrow-function-params t)