fix(completion/marginalia): improve issues with project-buffer annotations

Show project relative file paths even when project root and file paths
start with a mixure of "~/" and absolute path.

Also handle buffers not backed by a file on disk by falling back onto
marginalia--buffer-file.
This commit is contained in:
2023-05-11 01:19:05 +01:00
parent 15278d5abe
commit 4654ea5e80
2 changed files with 10 additions and 6 deletions

View File

@@ -27,6 +27,7 @@
(require 'siren-cape)
(require 'siren-company)
(require 'siren-copilot)
(require 'siren-marginalia)
;; Documentation
(require 'siren-dash-at-point)
@@ -38,7 +39,6 @@
(require 'siren-display-indentation)
(require 'siren-display-line-numbers)
(require 'siren-embark)
(require 'siren-marginalia)
(require 'siren-minions)
(require 'siren-mwim)
(require 'siren-origami)

View File

@@ -63,11 +63,15 @@ mode."
:face 'marginalia-file-name))))
(defun marginalia--project-buffer-file (buffer)
"Return the file or process name of BUFFER relative to project root, if it
is within project root."
(let ((root (marginalia--project-root))
(file (marginalia--buffer-file buffer)))
(if (string-equal root file) file
"Return the file or process name of BUFFER relative to project root."
(let* ((root (expand-file-name (marginalia--project-root)))
(raw-file (marginalia--buffer-file buffer))
(file (if (string-prefix-p "~/" raw-file)
(expand-file-name raw-file)
raw-file)))
(if (or (string-empty-p root)
(string-equal root file))
raw-file
(string-remove-prefix root file))))
:config