@@ -1230,11 +1230,19 @@ If FORCE? decide to CLOSE? or not."
12301230 " ) "
12311231 (truncate-string-to-width description (* 100 eca-chat-window-width)))))
12321232
1233- (defun eca-chat--completion-context-exit-function (item _status )
1233+ (defun eca-chat--completion-context-from-new-context- exit-function (item _status )
12341234 " Add to context the selected ITEM."
12351235 (eca-chat--add-context (get-text-property 0 'eca-chat-completion-item item))
12361236 (end-of-line ))
12371237
1238+ (defun eca-chat--completion-context-from-prompt-exit-function (item _status )
1239+ " Add to context the selected ITEM.
1240+ Add text property to prompt text to match context."
1241+ (eca-chat--add-context (get-text-property 0 'eca-chat-completion-item item))
1242+ (put-text-property (1- (- (point ) (length item))) (point ) 'font-lock-face (get-text-property 0 'face item))
1243+ (end-of-line )
1244+ (insert " " ))
1245+
12381246(defun eca-chat--completion-prompt-exit-function (item _status )
12391247 " Finish prompt completion for ITEM."
12401248 (-let* (((&plist :arguments arguments) (get-text-property 0 'eca-chat-completion-item item)))
@@ -1253,15 +1261,23 @@ If FORCE? decide to CLOSE? or not."
12531261
12541262(defun eca-chat--context-to-completion (context )
12551263 " Convert CONTEXT to a completion item."
1256- (propertize
1257- (pcase (plist-get context :type )
1258- (" file" (f-filename (plist-get context :path )))
1259- (" directory" (f-filename (plist-get context :path )))
1260- (" repoMap" " repoMap" )
1261- (" cursor" " cursor" )
1262- (" mcpResource" (concat (plist-get context :server ) " :" (plist-get context :name )))
1263- (_ (concat " Unknown - " (plist-get context :type ))))
1264- 'eca-chat-completion-item context))
1264+ (let ((raw-label (pcase (plist-get context :type )
1265+ (" file" (f-filename (plist-get context :path )))
1266+ (" directory" (f-filename (plist-get context :path )))
1267+ (" repoMap" " repoMap" )
1268+ (" cursor" " cursor" )
1269+ (" mcpResource" (concat (plist-get context :server ) " :" (plist-get context :name )))
1270+ (_ (concat " Unknown - " (plist-get context :type )))))
1271+ (face (pcase (plist-get context :type )
1272+ (" file" 'eca-chat-context-file-face )
1273+ (" directory" 'eca-chat-context-file-face )
1274+ (" repoMap" 'eca-chat-context-repo-map-face )
1275+ (" cursor" 'eca-chat-context-cursor-face )
1276+ (" mcpResource" 'eca-chat-context-mcp-resource-face )
1277+ (_ nil ))))
1278+ (propertize raw-label
1279+ 'eca-chat-completion-item context
1280+ 'face face)))
12651281
12661282(defun eca-chat--command-to-completion (command )
12671283 " Convert COMMAND to a completion item."
@@ -1453,7 +1469,11 @@ string."
14531469 (type (cond
14541470 ; ; completing contexts
14551471 ((eca-chat--point-at-new-context-p)
1456- 'contexts )
1472+ 'contexts-from-new-context )
1473+
1474+ ((when-let (last-word (car (last (string-split full-text " [\s ]" ))))
1475+ (string-match-p " ^@" last-word))
1476+ 'contexts-from-prompt )
14571477
14581478 ; ; completing commands with `/`
14591479 ((and (eca-chat--point-at-prompt-field-p)
@@ -1470,9 +1490,10 @@ string."
14701490 (eca-api-catch 'input
14711491 (eca-api-while-no-input
14721492 (pcase type
1473- ('contexts
1493+ ((or 'contexts-from-prompt
1494+ 'contexts-from-new-context )
14741495 (let ((query (eca-chat--context-find-typed-query)))
1475- (or (gethash query eca-chat--context-completion-cache)
1496+ (or ; (gethash query eca-chat--context-completion-cache)
14761497 (-let* (((&plist :contexts contexts) (eca-api-request-while-no-input
14771498 (eca-session)
14781499 :method " chat/queryContext"
@@ -1501,11 +1522,13 @@ string."
15011522 (:interrupted nil )
15021523 (`, res res))))
15031524 (exit-fn (pcase type
1504- ('contexts #'eca-chat--completion-context-exit-function )
1525+ ('contexts-from-new-context #'eca-chat--completion-context-from-new-context-exit-function )
1526+ ('contexts-from-prompt #'eca-chat--completion-context-from-prompt-exit-function )
15051527 ('prompts #'eca-chat--completion-prompt-exit-function )
15061528 (_ nil )))
15071529 (annotation-fn (pcase type
1508- ('contexts (-partial #'eca-chat--completion-context-annotate (eca--session-workspace-folders (eca-session))))
1530+ ((or 'contexts-from-prompt
1531+ 'contexts-from-new-context ) (-partial #'eca-chat--completion-context-annotate (eca--session-workspace-folders (eca-session))))
15091532 ('prompts #'eca-chat--completion-prompts-annotate ))))
15101533 (list
15111534 bounds-start
0 commit comments