109109 " Severity level for `lsp-treemacs-error-list-mode' . 1 (highest) to 3 (lowest)"
110110 :type 'number )
111111
112+ (defcustom lsp-treemacs-error-list-current-project-only nil
113+ " List the error list of the current project only if available.
114+ Fallback to list all workspaces if no project root is found."
115+ :type 'boolean
116+ :group 'lsp-treemacs )
117+
112118(defun lsp-treemacs--open-file-in-mru (file )
113119 (select-window (get-mru-window (selected-frame ) nil :not-selected ))
114120 (find-file file))
@@ -1202,35 +1208,44 @@ With prefix 2 show both."
12021208 count)))
12031209 (seq-some #'identity )))
12041210
1211+ (defun lsp-treemacs--build-error-list (folder )
1212+ (when-let ((diags (append (lsp-diagnostics-stats-for folder) ())))
1213+ (when (lsp-treemacs-errors--diags? diags)
1214+ (list :label (format
1215+ (propertize " %s %s %s" 'face 'default )
1216+ (f-filename folder)
1217+ (->> diags
1218+ (-map-indexed
1219+ (lambda (index count )
1220+ (when (and (not (zerop count))
1221+ (<= index lsp-treemacs-error-list-severity))
1222+ (propertize
1223+ (number-to-string count)
1224+ 'face (alist-get index lsp-treemacs-file-face-map)))))
1225+ (-filter #'identity )
1226+ (s-join " /" ))
1227+ (propertize (f-dirname folder)
1228+ 'face 'lsp-lens-face ))
1229+ :id folder
1230+ :icon 'root
1231+ :children (-partial #'lsp-treemacs-errors--list-files folder)
1232+ :ret-action (lambda (&rest _ )
1233+ (interactive )
1234+ (lsp-treemacs--open-file-in-mru folder))))))
1235+
1236+ (defvar lsp-treemacs--current-workspaces nil )
1237+
12051238(defun lsp-treemacs-errors-list--refresh ()
12061239 (lsp-treemacs-render
1207- (->> (lsp-session)
1208- (lsp-session-folders)
1209- (-keep
1210- (lambda (folder )
1211- (when-let ((diags (append (lsp-diagnostics-stats-for folder) ())))
1212- (when (lsp-treemacs-errors--diags? diags)
1213- (list :label (format
1214- (propertize " %s %s %s" 'face 'default )
1215- (f-filename folder)
1216- (->> diags
1217- (-map-indexed
1218- (lambda (index count )
1219- (when (and (not (zerop count))
1220- (<= index lsp-treemacs-error-list-severity))
1221- (propertize
1222- (number-to-string count)
1223- 'face (alist-get index lsp-treemacs-file-face-map)))))
1224- (-filter #'identity )
1225- (s-join " /" ))
1226- (propertize (f-dirname folder)
1227- 'face 'lsp-lens-face ))
1228- :id folder
1229- :icon 'root
1230- :children (-partial #'lsp-treemacs-errors--list-files folder)
1231- :ret-action (lambda (&rest _ )
1232- (interactive )
1233- (lsp-treemacs--open-file-in-mru folder))))))))
1240+ (if (and lsp-treemacs-error-list-current-project-only
1241+ lsp-treemacs--current-workspaces)
1242+ (->> lsp-treemacs--current-workspaces
1243+ (-map #'lsp-workspace-folders )
1244+ (-flatten)
1245+ (-keep #'lsp-treemacs--build-error-list ))
1246+ (->> (lsp-session)
1247+ (lsp-session-folders)
1248+ (-keep #'lsp-treemacs--build-error-list )))
12341249 " Errors List"
12351250 nil
12361251 lsp-treemacs-errors-buffer-name
@@ -1239,6 +1254,7 @@ With prefix 2 show both."
12391254;;;### autoload
12401255(defun lsp-treemacs-errors-list ()
12411256 (interactive )
1257+ (setq lsp-treemacs--current-workspaces (lsp-workspaces))
12421258 (-if-let (buffer (get-buffer lsp-treemacs-errors-buffer-name))
12431259 (progn
12441260 (select-window (display-buffer-in-side-window buffer '((side . bottom))))
0 commit comments