File tree 5 files changed +52
-22
lines changed
5 files changed +52
-22
lines changed Original file line number Diff line number Diff line change 12
12
* This increases the chances that a namespace will be found, which in turns makes refactor-nrepl more complete/accurate.
13
13
* Replace Cheshire with ` clojure.data.json `
14
14
* Build ASTs more robustly (by using locks and ruling out certain namespaces like refactor-nrepl itself)
15
+ * Honor internal ` future-cancel ` calls, improving overall responsiveness and stability.
15
16
16
17
### Bugs fixed
17
18
* [ #289 ] ( https://github.com/clojure-emacs/refactor-nrepl/issues/289 ) : Fix an edge-case with involving keywords that caused find-symbol to crash.
Original file line number Diff line number Diff line change 55
55
opts {:read-cond :allow :features #{:clj } :eof :eof }]
56
56
(loop [macros [], form (reader/read opts rdr)]
57
57
(cond
58
- (= form :eof ) macros
58
+ (or (= form :eof )
59
+ (util/interrupted? )) macros
59
60
(and (sequential? form) (= (first form) 'defmacro))
60
61
(recur (conj macros (build-macro-meta form f))
61
62
(reader/read opts rdr))
82
83
" Finds all macros that are defined in the project."
83
84
[ignore-errors?]
84
85
(->> (core/find-in-project (util/with-suppressed-errors
85
- (some-fn core/cljc-file? core/clj-file?)
86
+ (every-pred (complement util/interrupted?)
87
+ (some-fn core/cljc-file? core/clj-file?))
86
88
ignore-errors?))
87
89
(mapcat #(try
88
90
(get-macro-definitions-in-file-with-caching %)
217
219
(when (fully-qualified-name? fully-qualified-name)
218
220
(let [all-defs (find-macro-definitions-in-project ignore-errors?)
219
221
macro-def (first (filter #(= (:name %) fully-qualified-name) all-defs))
220
- tracker (tracker/build-tracker (util/with-suppressed-errors tracker/default-file-filter-predicate ignore-errors?))
222
+ tracker (tracker/build-tracker (util/with-suppressed-errors
223
+ (every-pred (complement util/interrupted?)
224
+ tracker/default-file-filter-predicate)
225
+ ignore-errors?))
221
226
origin-ns (symbol (core/prefix fully-qualified-name))
222
227
dependents (tracker/get-dependents tracker origin-ns)]
223
228
(some->> macro-def
224
229
^String (:file )
225
230
File.
226
231
(conj dependents)
227
- (mapcat (partial find-usages-in-file [macro-def]))
232
+ (keep (fn [x]
233
+ (when-not (util/interrupted? )
234
+ (find-usages-in-file [macro-def] x))))
235
+ (apply concat)
228
236
(into #{})
229
237
(remove nil?)
230
238
(sort-by :line-beg )))))
Original file line number Diff line number Diff line change 137
137
(str/join " /" [namespace var-name]))
138
138
referred-syms (libspecs/referred-syms-by-file&fullname ignore-errors)]
139
139
(->> (core/dirs-on-classpath )
140
- (mapcat (partial core/find-in-dir (util/with-suppressed-errors
141
- (every-pred (some-fn core/clj-file? core/cljc-file?)
142
- (fn [f]
143
- (try
144
- (let [n (some-> f
145
- core/read-ns-form
146
- parse/name-from-ns-decl)]
147
- (if-not n
148
- false
149
- (not (self-referential? n))))
150
- (catch Exception e
151
- (util/maybe-log-exception e)
152
- false ))))
153
- ignore-errors)))
154
- (mapcat (partial find-symbol-in-file fully-qualified-name ignore-errors referred-syms)))))
140
+ (keep (fn [x]
141
+ (when-not (util/interrupted? )
142
+ (core/find-in-dir (util/with-suppressed-errors
143
+ (every-pred (some-fn core/clj-file? core/cljc-file?)
144
+ (fn [f]
145
+ (try
146
+ (let [n (some-> f
147
+ core/read-ns-form
148
+ parse/name-from-ns-decl)]
149
+ (if-not n
150
+ false
151
+ (not (self-referential? n))))
152
+ (catch Exception e
153
+ (util/maybe-log-exception e)
154
+ false ))))
155
+ ignore-errors)
156
+ x))))
157
+ (apply concat)
158
+ (keep (fn [x]
159
+ (when-not (util/interrupted? )
160
+ (find-symbol-in-file fully-qualified-name ignore-errors referred-syms x))))
161
+ (apply concat))))
155
162
156
163
(defn- get &read-enclosing-sexps
157
164
[file-content {:keys [^long line-beg ^long col-beg]}]
249
256
macros (future (find-macro (core/fully-qualify ns name) ignore-errors?))
250
257
globals (->> (find-global-symbol file ns name ignore-errors?)
251
258
distinct
252
- (remove find-util/spurious?)
259
+ (remove (some-fn util/interrupted?
260
+ find-util/spurious?))
253
261
future)]
254
262
255
263
(or
Original file line number Diff line number Diff line change 53
53
" Get the dependent files for ns from tracker."
54
54
[tracker my-ns]
55
55
(let [deps (dep/immediate-dependents (:clojure.tools.namespace.track/deps tracker)
56
- (symbol my-ns))]
56
+ (symbol my-ns))
57
+ deps-set (set deps)]
57
58
(for [[file ns ] (:clojure.tools.namespace.file/filemap tracker)
58
- :when ((set deps) ns )]
59
+ :when (and (not (util/interrupted? ))
60
+ (deps-set ns ))]
59
61
file)))
60
62
61
63
(defn- in-refresh-dirs? [refresh-dirs file]
Original file line number Diff line number Diff line change 88
88
(maybe-log-exception e)
89
89
; ; return false, because `with-suppressed-errors` is oriented for predicate usage
90
90
false )))))
91
+
92
+ (defn interrupted?
93
+ " Has the current thread been interrupted?
94
+
95
+ Observing this condition helps `future-cancel` effectively cancel `future`s."
96
+ ([]
97
+ (interrupted? ::_ ))
98
+ ; ; The arity with a "useless" arg is there so that this can be used as a predicate
99
+ ; ; in other places that already are using `some-fn`, `every-pred`, etc
100
+ ([_]
101
+ (.isInterrupted (Thread/currentThread ))))
You can’t perform that action at this time.
0 commit comments