Skip to content
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

Improvement: Multiple Diagnostic Errors #16

Merged
merged 2 commits into from
Jan 9, 2024
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
17 changes: 7 additions & 10 deletions src/eval.janet
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,22 @@

(def eval-fiber
(fiber/new
|(do (var returnval :ok)
|(do (var returnval @[])
(try (run-context {:chunks chunks
:on-compile-error (fn compile-error [msg errf where line col]
(set returnval [:error {:message msg
:location [line col]}]))
(array/push returnval {:message msg
:location [line col]}))
:on-parse-error (fn parse-error [p x]
(set returnval [:error {:message (parser/error p)
:location (parser/where p)}]))
(array/push returnval {:message (parser/error p)
:location (parser/where p)}))
:evaluator flycheck-evaluator
:fiber-flags :i
:source filename})
([err]
(set returnval [:error {:message err
:location [0 0]}])))
# (logging/log (string/format "from within fiber, returnval is: %m" returnval))
(array/push returnval {:message err
:location [0 0]})))
returnval) :e (dyn :eval-env)))
(def eval-fiber-return (resume eval-fiber))
# (logging/log (string/format "eval-fiber-return is: %m" eval-fiber-return))
# (logging/log (string/format "fiber last value was: %m" (fiber/last-value eval-fiber)))
eval-fiber-return)

# tests
Expand Down
21 changes: 11 additions & 10 deletions src/main.janet
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@
(defn on-document-diagnostic [state params]
(let [uri (get-in params ["textDocument" "uri"])
content (get-in state [:documents uri :content])
items @[]]

(match (eval/eval-buffer content (path/basename uri))
:ok ()
[:error {:location [line col] :message message}]
(array/push items
{:range
{:start {:line (max 0 (dec line)) :character col}
:end {:line (max 0 (dec line)) :character col}}
:message message}))
items @[]
eval-result (eval/eval-buffer content (path/basename uri))]

(each res eval-result
(match res
{:location [line col] :message message}
(array/push items
{:range
{:start {:line (max 0 (dec line)) :character col}
:end {:line (max 0 (dec line)) :character col}}
:message message})))

[:ok state {:kind "full"
:items items}]))
Expand Down