-
Notifications
You must be signed in to change notification settings - Fork 4
/
workbench.lisp
331 lines (220 loc) · 6.54 KB
/
workbench.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
(defpackage #:breeze.workbench
(:documentation "Don't load this, it's for interactive development of breeze.")
(:use #:cl #:breeze.thread))
(in-package #:breeze.workbench)
;; List all threads
(find-threads nil nil)
;; List all threads except the current one
(find-threads nil)
;; Find all of slime's "worker" thread
(find-threads-by-name "worker")
;; Find all of slime's "worker" thread, including this one
(find-threads-by-name "worker" :exclude-self-p nil)
;; Kill all Slime's worker threads
(kill-worker-threads)
;; Find the number of currently running breeze commands
(length (find-threads-by-name "breeze command handler"))
;; Kill all currently running breeze-commands
(kill-threads-by-name "breeze command handler")
(defvar *default-trace-report-default* sb-debug:*trace-report-default*)
;; tracing is very very useful for debugging, but the default way sbcl
;; often prints "way too much" stuff
(defun trace-report (depth function event stack-frame values)
;; (pprint-logical-block stream values :prefix ... :suffix ...)
(let ((*print-pretty* nil)
(stream *standard-output*))
(terpri stream)
(pprint-logical-block (stream values
:per-line-prefix (format nil "~v@{~A~:*~}" depth " |"))
;; (loop :repeat depth :do (format stream " |"))
(pprint-indent :current depth stream)
(case event
(:enter
(format stream "~3d (~a ~{~a~^ ~})" depth function values))
(:exit
(format stream "~3d => ~{~a~^, ~}" depth values))
(t
(format stream "~3d ~s (~a ~{~a~^ ~})" depth event function values))))))
(setf sb-debug:*trace-report-default* 'trace-report)
(setf *break-on-signals* 'error)
(setf *break-on-signals* nil)
(in-package #:breeze.command)
;;; Tracing important functions in the "command" package.
(trace
find-actor
;; start-command ; don't: too verbose
call-with-cancel-command-on-error
cancel-command
continue-command
donep)
(trace
%recv
%send
insert
read-string
read-string-then-insert
choose)
(trace
chanl:send
chanl:recv)
(untrace)
;;; Manually testing "actors"
(defparameter *id*
(start-command 'breeze.test.command::test-insert nil '("Mark")))
(find-actor *id* :errorp t)
(recv-from (find-actor *id* :errorp t))
(donep
(find-actor *actor-id-counter* :errorp t))
(recv-from
(find-actor *actor-id-counter* :errorp t))
(outgoing-messages-p
(find-actor *actor-id-counter* :errorp t))
(clear-actors)
;;; Inspecting a command's actor after the command is done
;; Find the latest command
(apply #'max (alexandria:hash-table-keys *actors*))
;; Find the ids of the commands that ran for/from a specific file
(loop
:for actor-id :being :the :hash-key :of *actors* :using (hash-value actor)
:for filename = (context-buffer-file-name (context actor))
:when (alexandria:ends-with-subseq "breeze/kite/kite.lisp" filename)
:collect actor-id)
(defparameter *a* (gethash 9 *actors*))
(context *a*)
;;; Prototyping the request thingy...
(request 'x)
;; => nil
(handler-bind
((request #'(lambda (request)
;; (format t "~%request: ~s" request)
(if (eq (what request) 'x)
(answer 42)
(signal request)))))
(mapcar (lambda (what)
(multiple-value-list (request what)))
'(x y)))
;; => ((42 T) (NIL))
(with-answers
())
;; refactor.lisp
(in-package #:breeze.refactor)
(list-all-commands)
(let* ((context (cdr (assoc :context *qf*)))
(inner-node (gethash 'BREEZE.COMMAND::INNER-NODE context))
(nodes (gethash 'BREEZE.COMMAND::NODEs context)))
;; context
;; (mapcar-form-p inner-node)
(values nodes
(nodes-emptyp nodes))
;; (node-symbol= 'uiop:define-package inner-node)
)
(let* ((*standard-output* *debug-io*)
(nodes)
(path)
(outer-node)
(parent-node)
(inner-node))
(loop :for (node . index) :in path
:for i :from 0
:do (format t "~%=== Path part #~d, index ~d ===~%~s"
i index node))
(format t "~%innore-node source: ~d-~d"
(node-start inner-node)
(node-end inner-node))
(format t "~%unparsed inner-node: ~s"
(breeze.reader:unparse-to-string inner-node))
(format t "~%nearest in-package: ~a" (find-nearest-in-package-form nodes outer-node))
(format t "~%parent node: ~a" parent-node))
(cdr (assoc :context *qf*))
(trace
shortcircuit
compute-suggestions
suggest-defpackage
suggest-system-definition
suggest-lambda
suggest-loop-clauses
suggest-defpackage-clauses
suggest-other)
;;; reader.lisp
(in-package #:breeze.reader)
(sb-profile:profile
parse
read-all-forms
eclector.parse:read-from-string
make-instance
eclector.parse-result:make-expression-result
eclector.parse-result:read-preserving-whitespace
raw)
;; #+ (or) (sb-profile:report)
;;; lossless-reader.lisp
(in-package #:breeze.lossless-reader)
(trace
read-string*
read-char*
read-while)
(trace
read-whitespaces
read-block-comment
read-line-comment
read-sharpsign-dispatching-reader-macro
read-punctuation
;; read-quoted-string
read-string
read-token
read-parens
read-extraneous-closing-parens
read-any
parse)
(untrace)
(in-package #:breeze.pattern)
(trace iterator-next
iterator-maybe-push
iterator-maybe-pop)
(trace merge-bindings)
(trace match)
(untrace)
(in-package #:breeze.test.pattern)
(test-match '(:zero-or-more a b) '(a b a b))
(trace compile-pattern)
(trace match :methods t)
(trace :wherein test-match-ref
;; match
merge-bindings)
(in-package #:breeze.test.analysis)
(trace in-package-node-p
:wherein test-in-package-node-p)
(trace :wherein test-lint
in-package-node-p)
(trace match
:wherein test-in-package-node-p)
(trace
:wherein test-match-parse
match
breeze.analysis::match-symbol-to-token
breeze.analysis::match-node)
(untrace)
(trace lint)
(in-package #:breeze.listener)
(trace suggest-symbol
suggest-package
suggest-class)
(progn
;; List the slot of a condition
(sb-kernel::condition-assigned-slots *condition*)
;; Get the first element of a condition's format arguments
(car
(slot-value *condition*
'sb-kernel::format-arguments)))
(defparameter *condition* *last-condition*
"Just a quick way to save the last-condition.")
#+ (or)
(type-of *condition*)
;; => SB-PCL::MISSING-SLOT
(prin t)
(commmon-lisp:print :oups)
(cl:prin :oups)
(call-with-correction-suggestion (lambda () (eval '(prin))))
(make-instance 'typos)
#|
TODO Would be nice to have a "Shadow-import all" restart.
|#