|
13 | 13 |
|
14 | 14 | (use judge)
|
15 | 15 |
|
16 |
| -(def version "0.0.9") |
| 16 | +(def version "0.0.10") |
17 | 17 | (def commit
|
18 | 18 | (with [proc (os/spawn ["git" "rev-parse" "--short" "HEAD"] :xp {:out :pipe})]
|
19 | 19 | (let [[out] (ev/gather
|
|
38 | 38 | (if (string/has-prefix? "file:" uri)
|
39 | 39 | (string/slice uri 5) uri)))]
|
40 | 40 |
|
41 |
| - (logging/info (string/format "`eval-buffer` returned: %m" diagnostics) [:evaluation]) |
| 41 | + (logging/info (string/format "`eval-buffer` returned: %m" diagnostics) [:evaluation] 3) |
42 | 42 |
|
43 | 43 | (each res diagnostics
|
44 | 44 | (match res
|
|
49 | 49 | :end {:line (max 0 (dec line)) :character col}}
|
50 | 50 | :message message})))
|
51 | 51 |
|
52 |
| - (logging/info (string/format "`run-diagnostics` is returning these errors: %m" items) [:evaluation]) |
53 |
| - (logging/info (string/format "`run-diagnostics` is returning this eval-context: %m" env) [:evaluation] 1) |
| 52 | + (logging/info (string/format "`run-diagnostics` is returning these errors: %m" items) [:evaluation] 2) |
| 53 | + (logging/info (string/format "`run-diagnostics` is returning this eval-context: %m" env) [:evaluation] 3) |
54 | 54 | [items env]))
|
55 | 55 |
|
56 | 56 | (def uri-percent-encoding-peg
|
|
154 | 154 | ~(let [,$name ,name
|
155 | 155 | ,$eval-env ,eval-env
|
156 | 156 | s (get-in ,$eval-env [,$name :value] ,$name)]
|
157 |
| - (,logging/log (string/format "binding-to-lsp-item: s is %m" s) [:completion] 2) |
| 157 | + (,logging/log (string/format "binding-to-lsp-item: s is %m" s) [:completion] 3) |
158 | 158 | {:label ,$name :kind
|
159 | 159 | (case (type s)
|
160 | 160 | :symbol 12 :boolean 6
|
|
343 | 343 | [:noresponse state])
|
344 | 344 |
|
345 | 345 | (defn on-janet-tell-joke [state params]
|
346 |
| - # (eprint "What's brown and sticky? A stick!") |
347 | 346 | (let [message {:question "What's brown and sticky?"
|
348 | 347 | :answer "A stick!"}]
|
349 | 348 | (logging/message message [:joke])
|
350 | 349 | [:ok state message]))
|
351 | 350 |
|
| 351 | +(defn on-enable-debug [state params] |
| 352 | + (let [message {:message "Enabled :debug"}] |
| 353 | + (setdyn :debug true) |
| 354 | + (try (spit "janetlsp.log" "") |
| 355 | + ([_] (logging/err "Tried to write to janetlsp.log, but couldn't" [:core]))) |
| 356 | + (logging/message message [:debug]) |
| 357 | + [:ok state message])) |
| 358 | + |
| 359 | +(defn on-disable-debug [state params] |
| 360 | + (let [message {:message "Disabled :debug"}] |
| 361 | + (setdyn :debug false) |
| 362 | + (setdyn :log-level 2) |
| 363 | + (logging/message message [:debug]) |
| 364 | + [:ok state message])) |
| 365 | + |
| 366 | +(defn do-set-log-level [state params kind] |
| 367 | + (let [new-level-string (params "level") |
| 368 | + new-level ({"off" 0 "messages" 1 "verbose" 2 "veryverbose" 3} new-level-string) |
| 369 | + message {:message (string/format "Set %s to %s" kind new-level-string)}] |
| 370 | + (logging/message message [:loglevel]) |
| 371 | + (setdyn kind new-level) |
| 372 | + [:noresponse state])) |
| 373 | + |
| 374 | +(defmacro on-set-log-level [state params] |
| 375 | + ~(,do-set-log-level ,state ,params :log-level)) |
| 376 | + |
| 377 | +(defmacro on-set-file-log-level [state params] |
| 378 | + ~(,do-set-log-level ,state ,params :log-to-file-level)) |
| 379 | + |
352 | 380 | (defn handle-message [message state]
|
353 | 381 | (let [id (get message "id")
|
354 | 382 | method (get message "method")
|
|
370 | 398 | "textDocument/definition" (on-document-definition state params)
|
371 | 399 | "janet/serverInfo" (on-janet-serverinfo state params)
|
372 | 400 | "janet/tellJoke" (on-janet-tell-joke state params)
|
| 401 | + "enableDebug" (on-enable-debug state params) |
| 402 | + "disableDebug" (on-disable-debug state params) |
| 403 | + "setLogLevel" (on-set-log-level state params) |
| 404 | + "setLogToFileLevel" (on-set-file-log-level state params) |
373 | 405 | "shutdown" (on-shutdown state params)
|
374 | 406 | "exit" (on-exit state params)
|
375 | 407 | "$/setTrace" (on-set-trace state params)
|
|
446 | 478 | (defn start-language-server []
|
447 | 479 | (print "Starting LSP " version "-" commit)
|
448 | 480 | (when (dyn :debug)
|
449 |
| - (try (spit "janetlsp.log.txt" "") |
| 481 | + (try (spit "janetlsp.log" "") |
450 | 482 | ([_] (logging/err "Tried to write to janetlsp.log txt, but couldn't" [:core]))))
|
451 | 483 |
|
452 | 484 | (merge-module root-env jpm-defs nil true)
|
|
488 | 520 | [[--dont-search-jpm-tree -j] (flag) "Whether to search `jpm_tree` for modules."
|
489 | 521 | --stdio (flag) "Use STDIO."
|
490 | 522 | [--debug -d] (flag) "Print debug messages."
|
491 |
| - [--log-level -l] (optional :int++ 0) "What level of logging to display. Defaults to 0." |
| 523 | + [--log-level -l] (optional :int++ 1) "What level of logging to display. Defaults to 1." |
| 524 | + [--log-to-file-level -f] (optional :int++ 2) "What level of logging to write to the log file. Defaults to 2." |
492 | 525 | [--log-category -L] (tuple :string) "Enable logging by category. For multiple categories, repeat the flag."
|
493 | 526 | [--console -c] (flag) "Start a debug console instead of starting the Language Server."
|
494 | 527 | [--debug-port -p] (optional :int++) "What port to start or connect to the debug console on. Defaults to 8037."]
|
|
505 | 538 | (setdyn :opts opts)
|
506 | 539 | (when debug (setdyn :debug true)) #(setdyn :debug true)
|
507 | 540 | (setdyn :log-level log-level) #(setdyn :log-level 2)
|
508 |
| - (setdyn :log-categories @[:core ;(map keyword log-category)]) #(setdyn :log-categories [:core :priority :diagnostics]) |
| 541 | + (setdyn :log-to-file-level log-to-file-level) #(setdyn :log-level 3) |
| 542 | + (setdyn :log-categories @[:core ;(map keyword log-category)]) #(setdyn :log-categories [:core :priority :loglevel]) |
509 | 543 | (setdyn :out stderr)
|
510 | 544 | (put root-env :out stderr)
|
511 | 545 |
|
|
0 commit comments