emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 b2f8b8b 16/39: More Flymake cleanup before advanc


From: João Távora
Subject: [Emacs-diffs] emacs-26 b2f8b8b 16/39: More Flymake cleanup before advancing to backend redesign
Date: Tue, 3 Oct 2017 10:04:49 -0400 (EDT)

branch: emacs-26
commit b2f8b8b47ad6fe1550a183c5e96896ff587cd5f0
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    More Flymake cleanup before advancing to backend redesign
    
    Diagnostics are reported for buffers, not necessarily files.  It’s the
    backend’s responsibility to compute the buffer where the diagnostic is
    applicable.  For now, this has to match the buffer where flymake-mode
    is active and which is at the origin of the backend call.
    
    flymake.el knows nothing about line/column diagnostics (except for
    backward-compatible flymake-ler-make-ler, which must yet be tested).
    It’s also the backend’s reponsibility to compute a BEG and END
    positions for the diagnostic in the relevant buffer.
    
    * lisp/progmodes/flymake-proc.el
    (flymake-proc--diagnostics-for-pattern): Convert LINE/COL to
    region here.  Check file buffer here.
    (flymake-proc--process-sentinel): Don’t kill output buffer if
    high enough log level.
    
    * lisp/progmodes/flymake.el (flymake-diag-region): Make this a utility
    function.  (flymake--highlight-line): Diagnostic has region now.
    (flymake-popup-current-error-menu): Don’t add file and line numbers to
    already this silly menu.  (flymake--fix-line-numbers): Remove.
    (flymake-report): No need to fix diagnostics here.
---
 lisp/progmodes/flymake-proc.el | 33 ++++++++++++--------
 lisp/progmodes/flymake.el      | 68 ++++++++++++++++++++----------------------
 2 files changed, 53 insertions(+), 48 deletions(-)

diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index 2e593bd..05f2cab 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -423,18 +423,24 @@ Create parent directories as needed."
          for col-string = (and col-idx (match-string col-idx))
          for col-number = (and col-string
                                (string-to-number col-string))
-         collect (with-current-buffer (process-buffer proc)
-                   (flymake-make-diagnostic
-                    :file fname
-                    :line line-number
-                    :col col-number
-                    :type (guess-type flymake-proc-diagnostic-type-pred 
message)
-                    :text message
-                    :full-file (and fname
-                                    (funcall
-                                     (flymake-proc--get-real-file-name-function
-                                      fname)
-                                     fname)))))
+         for full-file = (with-current-buffer (process-buffer proc)
+                           (and fname
+                                (funcall
+                                 (flymake-proc--get-real-file-name-function
+                                  fname)
+                                 fname)))
+         for buffer = (and full-file
+                           (find-buffer-visiting full-file))
+         if (eq buffer (process-buffer proc))
+         collect (with-current-buffer buffer
+                   (pcase-let ((`(,beg . ,end)
+                                (flymake-diag-region line-number col-number)))
+                     (flymake-make-diagnostic
+                      buffer beg end
+                      (guess-type flymake-proc-diagnostic-type-pred message)
+                      message)))
+         else
+         do (flymake-log 2 "No buffer found for diagnosed file %s" fname))
       (error
        (flymake-log 1 "Error parsing process output for pattern %s: %s"
                     pattern err)
@@ -486,7 +492,8 @@ Create parent directories as needed."
 
       (flymake-log 2 "process %d exited with code %d"
                    (process-id process) exit-status)
-      (kill-buffer (process-get process 'flymake-proc--output-buffer))
+      (unless (> flymake-log-level 2)
+        (kill-buffer (process-get process 'flymake-proc--output-buffer)))
       (condition-case err
           (progn
             (flymake-log 3 "cleaning up using %s" cleanup-f)
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index b5abf5c..ea9e7c9 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -139,10 +139,29 @@ are the string substitutions (see the function `format')."
        (message "%s" msg))))
 
 (cl-defstruct (flymake--diag
-               (:constructor flymake-make-diagnostic))
-  file line col type text full-file)
-(define-obsolete-function-alias 'flymake-ler-make 'flymake-make-diagnostic 
"26.1"
-  "Constructor for objects of type `flymake--diag'")
+               (:constructor flymake--diag-make))
+  buffer beg end type text)
+
+(defun flymake-make-diagnostic (buffer
+                                beg
+                                end
+                                type
+                                text)
+  "Mark BUFFER's region from BEG to END with a flymake diagnostic.
+TYPE is a key to `flymake-diagnostic-types-alist' and TEXT is a
+description of the problem detected in this region."
+  (flymake--diag-make :buffer buffer :beg beg :end end :type type :text text))
+
+(defun flymake-ler-make-ler (file line type text &optional full-file)
+  (let* ((file (or full-file file))
+         (buf (find-buffer-visiting file)))
+    (unless buf (error "No buffer visiting %s" file))
+    (pcase-let* ((`(,beg . ,end)
+                  (with-current-buffer buf
+                    (flymake-diag-region line nil))))
+      (flymake-make-diagnostic buf beg end type text))))
+
+(make-obsolete 'flymake-ler-make-ler 'flymake-make-diagnostic "26.1")
 
 (cl-defun flymake--overlays (&key beg end filter compare key)
   "Get flymake-related overlays.
@@ -201,15 +220,14 @@ verify FILTER, sort them by COMPARE (using KEY)."
 (define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1")
 (define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1")
 
-(defun flymake--diag-region (diagnostic)
-  "Return the region (BEG . END) for DIAGNOSTIC.
+(defun flymake-diag-region (line col)
+  "Compute region (BEG . END) corresponding to LINE and COL.
 Or nil if the region is invalid."
-  ;; FIXME: make this a generic function
   (condition-case-unless-debug _err
-      (save-excursion
-        (goto-char (point-min))
-        (let ((line (flymake--diag-line diagnostic))
-              (col (flymake--diag-col diagnostic)))
+      (let ((line (min (max line 1)
+                       (line-number-at-pos (point-max) 'absolute))))
+        (save-excursion
+          (goto-char (point-min))
           (forward-line (1- line))
           (cl-flet ((fallback-bol
                      () (progn (back-to-indentation) (point)))
@@ -316,8 +334,9 @@ If TYPE doesn't declare PROP in either
 
 (defun flymake--highlight-line (diagnostic)
   "Highlight buffer with info in DIAGNOSTIC."
-  (when-let* ((region (flymake--diag-region diagnostic))
-              (ov (make-overlay (car region) (cdr region))))
+  (when-let* ((ov (make-overlay
+                   (flymake--diag-beg diagnostic)
+                   (flymake--diag-end diagnostic))))
     ;; First set `category' in the overlay, then copy over every other
     ;; property.
     ;;
@@ -387,12 +406,7 @@ If TYPE doesn't declare PROP in either
                          (user-error "No flymake problem for current line")))
          (menu (mapcar (lambda (ov)
                          (let ((diag (overlay-get ov 'flymake--diagnostic)))
-                           (cons (format "%s - %s(%s)"
-                                         (flymake--diag-text diag)
-                                         (or (flymake--diag-file diag)
-                                             "(no file)")
-                                         (or (flymake--diag-line diag)
-                                             "?"))
+                           (cons (flymake--diag-text diag)
                                  ov)))
                        diag-overlays))
          (event (if (mouse-event-p event)
@@ -444,26 +458,10 @@ If TYPE doesn't declare PROP in either
   (flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status 
%s, warning %s"
                (buffer-name) status warning))
 
-(defun flymake--fix-line-numbers (diagnostic)
-  "Ensure DIAGNOSTIC has sensible error lines"
-  (setf (flymake--diag-line diagnostic)
-        (min (max (flymake--diag-line diagnostic)
-                  1)
-             (line-number-at-pos (point-max) 'absolute))))
-
 (defun flymake-report (diagnostics)
   (save-restriction
     (widen)
     (flymake-delete-own-overlays)
-    (setq diagnostics
-          (cl-remove-if-not
-           (lambda (diag)
-             (let ((ff (flymake--diag-full-file diag)))
-               (and ff
-                    (equal (expand-file-name ff)
-                           (expand-file-name (buffer-file-name))))))
-           diagnostics))
-    (mapc #'flymake--fix-line-numbers diagnostics)
     (mapc #'flymake--highlight-line diagnostics)
     (let ((err-count (cl-count-if #'flymake--diag-errorp diagnostics))
           (warn-count (cl-count-if-not #'flymake--diag-errorp diagnostics)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]