From 071154f92ea89fb43490f85d46b7a2b46f807684 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sun, 16 Feb 2025 14:14:14 -0800 Subject: [PATCH] Diagnostics aren't guaranteed to have ranges. --- src/fennel-ls.fnl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/fennel-ls.fnl b/src/fennel-ls.fnl index 2ee59e2..e42b64a 100644 --- a/src/fennel-ls.fnl +++ b/src/fennel-ls.fnl @@ -2,6 +2,13 @@ (local dispatch (require :fennel-ls.dispatch)) (local json-rpc (require :fennel-ls.json-rpc)) +(fn print-diagnostic [filename message ?range] + (print (: "%s:%s:%s: %s" :format filename + ;; LSP line numbers are zero-indexed, but Emacs and Vim both use + ;; 1-indexing for this. + (+ (or (?. ?range :start :line) 0) 1) + (or (?. ?range :start :character) "?") message))) + (λ lint [filenames] "non-interactive mode that gets executed from CLI with --lint. runs lints on each file, then formats and prints them" @@ -19,11 +26,8 @@ (each [_ filename (ipairs filenames)] (let [file (files.get-by-uri server (.. "file://" filename))] (lint.add-lint-diagnostics server file) - (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))) + (each [_ {: message : range} (ipairs file.diagnostics)] + (print-diagnostic filename message range)) (if (. file.diagnostics 1) (set should-err? true)))) (if should-err?