-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix #391] Add option for disabling warnings #392
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
;; Benedek Fazekas <[email protected]> | ||
;; Version: 2.4.0-SNAPSHOT | ||
;; Keywords: convenience, clojure, cider | ||
;; Package-Requires: ((emacs "24.4") (s "1.8.0") (seq "2.19") (yasnippet "0.6.1") (paredit "24") (multiple-cursors "1.2.2") (clojure-mode "5.6.1") (cider "0.15.0") (edn "1.1.2") (inflections "2.3") (hydra "0.13.2")) | ||
;; Package-Requires: ((emacs "24.4") (s "1.8.0") (seq "2.19") (yasnippet "0.6.1") (paredit "24") (multiple-cursors "1.2.2") (clojure-mode "5.6.1") (cider "0.17.0") (edn "1.1.2") (inflections "2.3") (hydra "0.13.2")) | ||
|
||
;; This program is free software; you can redistribute it and/or | ||
;; modify it under the terms of the GNU General Public License | ||
|
@@ -155,6 +155,13 @@ as can be." | |
:group 'cljr | ||
:type 'boolean) | ||
|
||
(defcustom cljr-suppress-no-project-warning nil | ||
"If t, no warning is printed when starting a REPL outside a project. | ||
By default, a warning is printed in this case since clj-refactor | ||
will not work as expected in such REPLs." | ||
:group 'cljr | ||
:type 'boolean) | ||
|
||
(defcustom cljr-find-usages-ignore-analyzer-errors nil | ||
"DEPRECATED: use `cljr-ignore-analyzer-errors' instead. | ||
If t, `cljr-find-usages' ignores namespaces that cannot be analyzed. | ||
|
@@ -786,6 +793,10 @@ A new record is created to define this constructor." | |
car) | ||
"")) | ||
|
||
(defun cljr--inside-project-p () | ||
"Return non-nil if `default-directory' is inside a Clojure project." | ||
(not (string-empty-p (cljr--project-dir)))) | ||
|
||
(defun cljr--project-file () | ||
(let ((project-dir (cljr--project-dir))) | ||
(or (let ((file (expand-file-name "project.clj" project-dir))) | ||
|
@@ -3142,15 +3153,21 @@ if REMOVE-PACKAGE_VERSION is t get rid of the (package: 20150828.1048) suffix." | |
|
||
(defun cljr--check-middleware-version () | ||
"Check whether clj-refactor and nrepl-refactor versions are the same" | ||
(let ((refactor-nrepl-version (or (cljr--middleware-version) | ||
"n/a"))) | ||
(unless (string-equal (downcase refactor-nrepl-version) | ||
(downcase (cljr--version :remove-package-version))) | ||
(cider-repl-emit-interactive-stderr | ||
(format "WARNING: clj-refactor and refactor-nrepl are out of sync. | ||
(if (cljr--inside-project-p) | ||
(let ((refactor-nrepl-version (or (cljr--middleware-version) | ||
"n/a"))) | ||
(unless (string-equal (downcase refactor-nrepl-version) | ||
(downcase (cljr--version :remove-package-version))) | ||
(cider-repl-emit-interactive-stderr | ||
(format "WARNING: clj-refactor and refactor-nrepl are out of sync. | ||
Their versions are %s and %s, respectively. | ||
You can mute this warning by changing cljr-suppress-middleware-warnings." | ||
(cljr--version) refactor-nrepl-version))))) | ||
(cljr--version) refactor-nrepl-version)))) | ||
(unless cljr-suppress-no-project-warning | ||
(cider-repl-emit-interactive-stderr | ||
"WARNING: No Clojure project was detected. The | ||
refactor-nrepl middleware was not enabled. (You can mute this | ||
warning by customizing `cljr-suppress-no-project-warning'.)")))) | ||
|
||
;;;###autoload | ||
(defun cljr-version () | ||
|
@@ -3178,16 +3195,10 @@ You can mute this warning by changing cljr-suppress-middleware-warnings." | |
(cider-repl-emit-interactive-stderr | ||
(format "WARNING: Can't determine Clojure version. The refactor-nrepl middleware requires clojure %s (or newer)" cljr-minimum-clojure-version)))) | ||
|
||
(defun cljr--check-project-context () | ||
(unless (cljr--project-dir) | ||
(cider-repl-emit-interactive-stderr | ||
(format "WARNING: No clojure project detected. The refactor-nrepl middleware won't work and has been disabled!")))) | ||
|
||
(defun cljr--init-middleware () | ||
(unless cljr-suppress-middleware-warnings | ||
(cljr--check-clojure-version) | ||
(cljr--check-middleware-version)) | ||
(cljr--check-project-context) | ||
;; Best effort; don't freak people out with errors | ||
(ignore-errors | ||
(when (cljr--middleware-version) ; check if middleware is running | ||
|
@@ -4002,15 +4013,22 @@ See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-change-function- | |
(kill-buffer cljr--manual-intervention-buffer)) | ||
(pop-to-buffer cljr--change-signature-buffer)))) | ||
|
||
;;;###autoload | ||
(defun cljr--inject-middleware-p (&rest _) | ||
"Return non-nil if nREPL middleware should be injected." | ||
(cljr--inside-project-p)) | ||
|
||
;;;###autoload | ||
(defun cljr--inject-jack-in-dependencies () | ||
"Inject the REPL dependencies of clj-refactor at `cider-jack-in'. | ||
If injecting the dependencies is not preferred set `cljr-inject-dependencies-at-jack-in' to nil." | ||
(when (and cljr-inject-dependencies-at-jack-in | ||
(boundp 'cider-jack-in-lein-plugins) | ||
(boundp 'cider-jack-in-nrepl-middlewares)) | ||
(add-to-list 'cider-jack-in-lein-plugins `("refactor-nrepl" ,(cljr--version t))) | ||
(add-to-list 'cider-jack-in-nrepl-middlewares "refactor-nrepl.middleware/wrap-refactor"))) | ||
(add-to-list 'cider-jack-in-lein-plugins `("refactor-nrepl" ,(cljr--version t) | ||
:predicate cljr--inject-middleware-p)) | ||
(add-to-list 'cider-jack-in-nrepl-middlewares '("refactor-nrepl.middleware/wrap-refactor" | ||
:predicate cljr--inject-middleware-p)))) | ||
|
||
;;;###autoload | ||
(eval-after-load 'cider | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this should be called
cljr--inject-middleware-p?
to better reflect its usage.Also, shouldn't it have an argument list like
(&rest _)
since it's actually expecting 3 arguments, that are ignored?Edit: I see it's used in two places, so I'd suggest leaving this and creating another function,
cljr--inject-middleware-p
that just has the right argument list and calls out to this one.