From bed83966f185a6b1284851e93b27e79bb2c96f47 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Mon, 19 Nov 2018 18:19:26 +1100 Subject: [PATCH] Improved tide-project-root to understand git and package.json --- lisp/my-file-modes.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lisp/my-file-modes.el b/lisp/my-file-modes.el index 11456e2..a010ac7 100644 --- a/lisp/my-file-modes.el +++ b/lisp/my-file-modes.el @@ -42,6 +42,20 @@ (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) -- 2.39.2