[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint 61724881c3 10/17: Use a defstruct for diag objec
From: |
ELPA Syncer |
Subject: |
[elpa] externals/relint 61724881c3 10/17: Use a defstruct for diag objects instead of raw vectors |
Date: |
Thu, 1 Aug 2024 12:59:05 -0400 (EDT) |
branch: externals/relint
commit 61724881c30265c30c134f3b1c596cd2b820ecff
Author: Mattias EngdegÄrd <mattiase@acm.org>
Commit: Mattias EngdegÄrd <mattiase@acm.org>
Use a defstruct for diag objects instead of raw vectors
Not clear if we should expose those objects to callers of
`relint-buffer`, or stick to vectors in the API for decoupling.
---
relint.el | 73 +++++++++++++++++++++++++++++++--------------------------------
1 file changed, 36 insertions(+), 37 deletions(-)
diff --git a/relint.el b/relint.el
index 31d9f15895..2fe2df00b4 100644
--- a/relint.el
+++ b/relint.el
@@ -76,6 +76,24 @@ In interactive mode, relint uses the
`relint-buffer-highlight' face instead."
(defvar relint--force-batch-output nil) ; for testing only
+(cl-defstruct (relint-diag
+ (:constructor nil)
+ (:constructor
+ relint--make-diag (message expr-pos beg-pos end-pos string
+ beg-idx end-idx severity))
+ (:copier nil)
+ (:type vector)
+ (:conc-name relint-diag--))
+ message ; string of message
+ expr-pos ; position of expression or nil
+ beg-pos ; exact first position of error or nil
+ end-pos ; exact last position of error or nil
+ string ; string inside which the complaint occurs or nil
+ beg-idx ; starting index into `string' or nil
+ end-idx ; ending index into `string' or nil
+ severity ; `error', `warning' or `info'
+ )
+
(defun relint--get-error-buffer ()
"Buffer to which errors are printed, or nil if noninteractive."
(and (not noninteractive)
@@ -238,18 +256,14 @@ in case it occupies more than one position in the buffer."
(goto-char pos)
(1+ (current-column))))
-(defun relint--output-complaint (error-buffer file complaint)
- ;; FIXME: Use accessors or destructuring
- (let* ((message (aref complaint 0))
- (expr-pos (aref complaint 1))
- (beg-pos (aref complaint 2))
- (end-pos (aref complaint 3))
- (str (aref complaint 4))
- (beg-idx (aref complaint 5))
- (end-idx (aref complaint 6))
- (severity (aref complaint 7))
- (beg (or beg-pos expr-pos))
- (end end-pos)
+(defun relint--output-complaint (error-buffer file diag)
+ (let* ((str (relint-diag--string diag))
+ (beg-idx (relint-diag--beg-idx diag))
+ (end-idx (relint-diag--end-idx diag))
+ (severity (relint-diag--severity diag))
+ (beg (or (relint-diag--beg-pos diag)
+ (relint-diag--expr-pos diag)))
+ (end (relint-diag--end-pos diag))
(beg-line (line-number-at-pos beg t))
(end-line (cond ((eq beg end) beg-line)
(end (line-number-at-pos end t))))
@@ -296,7 +310,7 @@ in case it occupies more than one position in the buffer."
(format "%s:%s: " file loc-str)
(cond ((eq severity 'error) "error: ")
((eq severity 'info) "info: "))
- message
+ (relint-diag--message diag)
(cond ((and beg-idx end-idx (< beg-idx end-idx))
(format " (pos %d..%d)" beg-idx end-idx))
(beg-idx (format " (pos %d)" beg-idx)))
@@ -311,32 +325,17 @@ in case it occupies more than one position in the buffer."
(defvar relint--suppression-count)
(defvar relint--complaints
- ;; list of lists of
- ;; [MESSAGE EXPR-POS BEG-POS END-POS STRING BEG-IDX END-IDX SEVERITY]
- ;; with fields:
- ;; MESSAGE string of message
- ;; EXPR-POS position of expression or nil
- ;; BEG-POS exact first position of error or nil
- ;; END-POS exact last position of error or nil
- ;; STRING string inside which the complaint occurs or nil
- ;; BEG-IDX starting index into STRING or nil
- ;; END-IDX ending index into STRING or nil
- ;; SEVERITY `error', `warning' or `info'
+ ;; list of lists of `relint-diag' objects
)
(defun relint--report-group (group)
- (let* ((diag (car group))
- (message (aref diag 0))
- (expr-pos (aref diag 1))
- (beg-pos (aref diag 2)))
- (if (relint--suppression (or expr-pos beg-pos) message)
+ (let ((diag (car group)))
+ (if (relint--suppression (or (relint-diag--expr-pos diag)
+ (relint-diag--beg-pos diag))
+ (relint-diag--message diag))
(setq relint--suppression-count (1+ relint--suppression-count))
(push group relint--complaints))))
-(defsubst relint--make-diag (message expr-pos beg-pos end-pos
- str beg-idx end-idx severity)
- (vector message expr-pos beg-pos end-pos str beg-idx end-idx severity))
-
(defun relint--report-one (message expr-pos beg-pos end-pos
str beg-idx end-idx severity)
(relint--report-group
@@ -2670,10 +2669,9 @@ The keys are sorted numerically, in ascending order.")
(relint--sort-with-key
;; Sort by error position if available, expression position otherwise.
(lambda (g)
- (let* ((c (car g))
- (expr-pos (aref c 1))
- (error-pos (aref c 2)))
- (or error-pos expr-pos)))
+ (let ((c (car g)))
+ (or (relint-diag--beg-pos c)
+ (relint-diag--expr-pos c))))
complaints)
relint--suppression-count))))
@@ -2843,6 +2841,7 @@ where
The intent is that BEG-POS..END-POS is the buffer range that
corresponds to STRING at BEG-IDX..END-IDX, if such a location can be
determined."
+ ;; FIXME: expose `relint-diag' objects instead of explicit vector?
(let ((groups (car (relint--scan-buffer buffer))))
(apply #'append groups))) ; flatten groups
- [elpa] externals/relint updated (9cb20f89ce -> 38c0468a05), ELPA Syncer, 2024/08/01
- [elpa] externals/relint d0bb526e77 02/17: Faster (nonrecursive) traversal of let* bindings, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 89e15852b1 01/17: Move version history to separate NEWS file, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 7abad19169 03/17: Adapt to xr changes: ranged diagnostics with severity field, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 61724881c3 10/17: Use a defstruct for diag objects instead of raw vectors,
ELPA Syncer <=
- [elpa] externals/relint 38c0468a05 17/17: Github CI: ignore changes to NEWS in actions, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 35a2bc31c8 11/17: Simplify: remove expr-pos from diag object, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 458a920b46 06/17: Use a vector instead of list for complaint tuple, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 79ba1f0183 14/17: Require Emacs 27 or newer, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 8cd09d69ae 16/17: NEWS entry for upcoming version 2.0, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 94b23171f0 12/17: Add pos-type field in diag object, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 5c63370936 04/17: Adapt to xr grouped diagnostics, ELPA Syncer, 2024/08/01
- [elpa] externals/relint caea432bb4 09/17: Better string range highlighting in output, ELPA Syncer, 2024/08/01
- [elpa] externals/relint 8e8db0e4b3 07/17: Simplify: xr-lint no longer signals errors, ELPA Syncer, 2024/08/01
- [elpa] externals/relint bc17dfcd16 05/17: Use ranges in relint's own diags, ELPA Syncer, 2024/08/01