Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .lispwords
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
(define-json-union 1)
(call-with-read-lock 1)
(call-with-write-lock 1)
(define-syntax-parse-rule 1)
52 changes: 52 additions & 0 deletions common/debug.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#lang racket/base
(require racket/file
racket/runtime-path
racket/match
racket/string
racket/format)

(provide
maybe-debug-log
maybe-debug-file
D
T)

(define debug? #f)

(define-runtime-path df "debug.out.rkt")
(define (maybe-debug-file t)
(when debug?
(display-to-file t df #:exists 'replace)))

(define-runtime-path dp "debug.log")
(define (maybe-debug-log m)
(when debug?
(with-output-to-file dp
#:exists 'append
(lambda ()
(writeln m)))))

(define (err-log tag name msg)
(eprintf "[~a] ~a:\n~a\n" tag name msg))

;; DEBUG macro: evaluates the expression, logs the result, and returns the result.
(define-syntax-rule (D expr)
(call-with-values
(lambda () expr)
(lambda results
(err-log 'DEBUG (quote expr)
(match results
[(list) (format "void")]
[(list x) (~v x)]
[_ (string-join (map ~v results) "\n")]))
(apply values results))))

;; TIME macro: evaluates the expression, logs the time taken, and returns the result.
(define-syntax-rule (T expr)
(let-values ([(results cpu-time real-time gc-time)
(time-apply (lambda () expr) '())])
(err-log 'TIME (quote expr)
(format "cpu time: ~a real time: ~a gc time: ~a"
cpu-time real-time gc-time))
(apply values results)))

23 changes: 0 additions & 23 deletions lsp/debug.rkt

This file was deleted.

2 changes: 1 addition & 1 deletion main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
racket/class
racket/async-channel
"common/interfaces.rkt"
"lsp/debug.rkt"
"common/debug.rkt"
"lsp/methods.rkt"
"lsp/msg-io.rkt"
"lsp/responses.rkt")
Expand Down