Skip to content

xref-js2 false-positive checks keeps all checked buffer files open #15

@mohkale

Description

@mohkale

this is the code block in question.

(defun xref-js2--false-positive (candidate)
  "Return non-nil if CANDIDATE is a false positive.
Filtering is done using the AST from js2-mode."
  (let* ((file (map-elt candidate 'file))
         (buffer-open (get-file-buffer file)))
    (prog1
        (with-current-buffer (find-file-noselect file t)
          (save-excursion
            (save-restriction
              (widen)
              (unless (or (eq major-mode 'js2-mode)
                          (seq-contains (map-keys minor-mode-alist) 'js2-minor-mode))
                (js2-minor-mode 1))
              (goto-char (point-min))
              (forward-line (1- (map-elt candidate 'line)))
              (search-forward (map-elt candidate 'symbol) nil t)
              ;; js2-mode fails to parse the AST for some minified files
              (ignore-errors
                (let ((node (js2-node-at-point)))
                  (or (js2-string-node-p node)
                      (js2-comment-node-p node))))))))))

there's a get-file-buffer call in the let clause, but the evaluated variable is never used. the body is also wrapped in a prog1 despite not needing to be. Both these reasons lead me to conclude the that after the false-positive-check buffer-open was supposed to be used to check whether the opened buffer should be killed or not (killed if the corresponding file wasn't already open). For one reason or another it was either never implemented or deprecated in favor of the current solution. Regardless, for large projects (and over controlling weirdos like myself 😈) having so many open buffers is inconvenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions