Skip to content

Commit

Permalink
warn if no ag or grep is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktasia committed Mar 6, 2016
1 parent 64cd0ad commit 2e356fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
1 change: 0 additions & 1 deletion TODO.txt
@@ -1,6 +1,5 @@

1)
;; TODO: if no grep or ag warn user (windows test)
;; TODO: ignore #files# ?

;; TODO: When there's multiple options use the compilations view for selecting the file
Expand Down
20 changes: 16 additions & 4 deletions dumb-jump.el
Expand Up @@ -245,6 +245,10 @@ immediately to the right of a symbol then it's probably a function call"
"Return t if ag is installed"
(s-contains? "ag version" (shell-command-to-string (concat dumb-jump-ag-cmd " --version"))))

(defun dumb-jump-grep-installed? ()
"Return t if ag is installed"
(s-match "[0-9]+\\.[0-9]+" (shell-command-to-string (concat dumb-jump-grep-cmd " --version"))))

(defun dumb-jump-find-start-pos (line-in look-for cur-pos)
"Find start column position of LOOK-FOR in LINE-IN using CUR-POS as a hint"
(let ((is-found nil)
Expand Down Expand Up @@ -354,10 +358,15 @@ denoter file/dir is found or uses dumb-jump-default-profile"
(plist-get (car result) :language)
(format ".%s file" (or (f-ext file) "?")))))


(defun dumb-jump-get-results ()
(if (buffer-modified-p (current-buffer))
`(:results nil :lang nil :symbol nil :ctx-type nil :file nil :root nil)
(dumb-jump-fetch-results)))
(cond
((not (or (dumb-jump-grep-installed?) (dumb-jump-ag-installed?)))
`(:results nil :lang nil :symbol nil :ctx-type nil :file nil :root nil :issue ,(intern "nogrep")))
((buffer-modified-p (current-buffer))
`(:results nil :lang nil :symbol nil :ctx-type nil :file nil :root nil :issue ,(intern "unsaved")))
(t
(dumb-jump-fetch-results))))

(defun dumb-jump-fetch-results ()
"Build up a list of results by examining the current context and calling grep"
Expand Down Expand Up @@ -424,14 +433,17 @@ denoter file/dir is found or uses dumb-jump-default-profile"
(results (plist-get info :results))
(look-for (plist-get info :symbol))
(proj-root (plist-get info :root))
(issue (plist-get info :issue))
(lang (plist-get info :lang))
(result-count (length results)))
(cond
((> fetch-time dumb-jump-max-find-time)
(dumb-jump-message "Took over %ss to find '%s'. Please install ag or add a .dumbjump file to '%s' with path exclusions"
(number-to-string dumb-jump-max-find-time) look-for proj-root))
((and (null results) (null look-for))
((eq issue 'unsaved)
(dumb-jump-message "Please save your file before jumping."))
((eq issue 'nogrep)
(dumb-jump-message "Please install ag or grep!"))
((s-ends-with? " file" lang)
(dumb-jump-message "Could not find rules for '%s'." lang))
((= result-count 1)
Expand Down
20 changes: 16 additions & 4 deletions test/dumb-jump-test.el
Expand Up @@ -386,12 +386,24 @@
(:path "src/file.js" :line 69 :context "isNow = false" :diff 0 :target "isNow"))))
(dumb-jump-handle-results results "src/file.js" "/code/redux" "" "isNow" nil))))

(ert-deftest dumb-jump-message-get-results-test ()
(ert-deftest dumb-jump-message-get-results-unsaved-test ()
(noflet ((buffer-modified-p (b)
t))
t)
(dumb-jump-message (input)
(should (string= "Please save your file before jumping." input))))

(let ((results (dumb-jump-get-results)))
(should (eq (plist-get results :issue) 'unsaved)))))

(ert-deftest dumb-jump-message-get-results-nogrep-test ()
(noflet ((dumb-jump-ag-installed? ()
nil)
(dumb-jump-grep-installed? ()
nil)
(dumb-jump-message (input)
(should (string= "Please install ag or grep!" input))))
(let ((results (dumb-jump-get-results)))
(should-not (plist-get results :results))
(should-not (plist-get results :file)))))
(should (eq (plist-get results :issue) 'nogrep)))))

(ert-deftest dumb-jump-message-result-follow-test ()
(noflet ((dumb-jump-goto-file-line (path line pos)
Expand Down

0 comments on commit 2e356fc

Please sign in to comment.