Skip to content

Commit 9005c83

Browse files
committed
Improve contexts completion description
1 parent efce217 commit 9005c83

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

eca-chat.el

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,16 @@ If FORCE? decide to CLOSE? or not."
11131113
""
11141114
key-vals))
11151115

1116+
(defun eca-chat--relativize-filename-for-workspace-root (filename roots &optional hide-filename?)
1117+
"Relativize the FILENAME if a workspace root is found for ROOTS.
1118+
Show parent upwards if HIDE-FILENAME? is non nil."
1119+
(let ((relative-path (or (-some->> (-first (lambda (root) (f-ancestor-of? root filename)) roots)
1120+
(f-relative filename))
1121+
filename)))
1122+
(if hide-filename?
1123+
(f-parent relative-path)
1124+
relative-path)))
1125+
11161126
(defun eca-chat--file-change-diff (path diff roots)
11171127
"Return a diff block for relative PATH from ROOTS with DIFF."
11181128
(concat "\n"
@@ -1133,12 +1143,6 @@ If FORCE? decide to CLOSE? or not."
11331143
" "
11341144
(propertize (concat "-" (number-to-string (plist-get details :linesRemoved))) 'font-lock-face 'error)))
11351145

1136-
(defun eca-chat--relativize-filename-for-workspace-root (filename roots)
1137-
"Relativize the FILENAME if a workspace root is found for ROOTS."
1138-
(or (-some->> (-first (lambda (root) (f-ancestor-of? root filename)) roots)
1139-
(f-relative filename))
1140-
filename))
1141-
11421146
(defun eca-chat--context-presentable-path (filename)
11431147
"Return the presentable string for FILENAME."
11441148
(or (when (-first (lambda (root) (f-ancestor-of? root filename))
@@ -1261,8 +1265,8 @@ If STATIC? return strs with no dynamic values."
12611265
"Annonate ITEM-LABEL detail for ROOTS."
12621266
(-let (((&plist :type type :path path :description description) (get-text-property 0 'eca-chat-completion-item item-label)))
12631267
(pcase type
1264-
("file" (eca-chat--relativize-filename-for-workspace-root path roots))
1265-
("directory" (eca-chat--relativize-filename-for-workspace-root path roots))
1268+
("file" (eca-chat--relativize-filename-for-workspace-root path roots 'hide-filename))
1269+
("directory" (eca-chat--relativize-filename-for-workspace-root path roots 'hide-filename))
12661270
("repoMap" "Summary view of workspaces files")
12671271
("cursor" "Current cursor file + position")
12681272
("mcpResource" description)
@@ -1271,7 +1275,7 @@ If STATIC? return strs with no dynamic values."
12711275
(defun eca-chat--completion-file-annotate (roots item-label)
12721276
"Annonate ITEM-LABEL detail for ROOTS."
12731277
(-let (((&plist :path path) (get-text-property 0 'eca-chat-completion-item item-label)))
1274-
(eca-chat--relativize-filename-for-workspace-root path roots)))
1278+
(eca-chat--relativize-filename-for-workspace-root path roots 'hide-filename)))
12751279

12761280
(defun eca-chat--completion-prompts-annotate (item-label)
12771281
"Annonate prompt ITEM-LABEL."

0 commit comments

Comments
 (0)