From 765b3d784fe7f6ddd13901328b75e538d2c9c472 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sat, 25 Nov 2023 21:45:01 -0800 Subject: [PATCH] Change format of --check output to look like compiler errors. They'll look like this now: src/fennel-ls/compiler.fnl:123:15 unused definition: ?definition src/fennel-ls/compiler.fnl:5:52 unused definition: view src/fennel-ls/compiler.fnl:197:13 unused definition: i src/fennel-ls/compiler.fnl:271:25 unnecessary : call; use multisym src/fennel-ls/handlers.fnl:14:10 unused definition: view src/fennel-ls/handlers.fnl:170:3 unused definition: create-completion-item src/fennel-ls/language.fnl:187:3 unused definition: does-not-contain? src/fennel-ls/language.fnl:221:28 unused definition: i src/fennel-ls/language.fnl:4:51 unused definition: view src/fennel-ls/language.fnl:171:3 unused definition: past? src/fennel-ls/language.fnl:208:23 unused definition: i src/fennel-ls/searcher.fnl:12:4 unnecessary : call; use multisym src/fennel-ls/state.fnl:23:3 unused definition: get-by-path src/fennel-ls/state.fnl:12:2 unnecessary : call; use multisym src/fennel-ls/utils.fnl:15:16 unused definition: i This has the advantage of making it so that existing tooling will work with it; for example, Emacs can hyperlink these and jump right to the code causing the issue. Use 1-indexed line numbers instead of 0-indexing because Emacs and Vim expect this. --- src/fennel-ls.fnl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fennel-ls.fnl b/src/fennel-ls.fnl index 9d672de..ccc4328 100644 --- a/src/fennel-ls.fnl +++ b/src/fennel-ls.fnl @@ -13,9 +13,11 @@ :rootUri "file://"}})) file (state.get-by-uri server (.. "file://" filename))] (diagnostics.check server file) - (each [_ v (ipairs file.diagnostics)] - ;; perhaps nicer formatting in the future? - (print (view v))))) + (each [_ {: message :range {: start}} (ipairs file.diagnostics)] + (print (: "%s:%s:%s %s" :format filename + ;; LSP line numbers are zero-indexed, but Emacs and Vim both use + ;; 1-indexing for this. + (+ (or start.line 0) 1) (or start.character "?") message))))) (λ main-loop [in out] (local send (partial json-rpc.write out)) @@ -27,7 +29,6 @@ (λ main [] (case arg ["--check" & filenames] (each [_ filename (ipairs filenames)] - (print "Checking" filename) (check filename)) (where (or ["--server"] [nil])) (main-loop (io.input) (io.output))