@@ -290,6 +290,25 @@ CB allows chaining an action after clearing."
290
290
(get-buffer-process (current-buffer ))
291
291
(format " %s \t " input-string)))
292
292
293
+ (defun js-comint--process-completion-output (completion prefix )
294
+ " Format COMPLETION string as a list of candidates.
295
+ PREFIX is the original completion prefix string."
296
+ (let* ((completion-res (split-string completion nil 't ))
297
+ (completion-res (seq-remove (apply-partially #'string-search " " ) completion-res)))
298
+ (cond
299
+ ; ; For an exact match the response is: MATCH^M// type info^M^[[...PROMPT
300
+ ((equal " //" (elt completion-res 1 ))
301
+ (list (car completion-res)))
302
+
303
+ ; ; When completing, e.g "console.", the prefix is included in every completion.
304
+ ; ; TODO for console.[name] completion, want name to display in list, but console.name as completion
305
+ ((string-suffix-p " ." prefix)
306
+ (cdr ; ; first is always the prefix in this case
307
+ (seq-map (apply-partially #'string-remove-prefix prefix) completion-res)))
308
+
309
+ ('t
310
+ completion-res))))
311
+
293
312
(defun js-comint--completion-filter (output )
294
313
" Intercepts completions in comint OUTPUT."
295
314
(message " |%s | " output)
@@ -323,23 +342,12 @@ CB allows chaining an action after clearing."
323
342
(js-comint--clear-repl-input)))
324
343
(when (string-match-p " \\ [[[:digit:]]+[AG]$" js-comint--completion-output)
325
344
(message " candidates " )
326
- (let* ((completion-res (string-split js-comint--completion-output nil 't ))
327
- (completion-res (seq-remove (apply-partially #'string-prefix-p " " ) completion-res))
328
- ; ; special case of exact match
329
- ; ; node seems to print type info in comment format
330
- (completion-res (if (equal " //" (elt completion-res 1 ))
331
- (list (car completion-res))
332
- completion-res))
333
- ; ; when completing console. the prefix is included in completions
334
- ; ; TODO for console.[name] completion, want name to display in list, but console.name as completion
335
- (completion-res (if (string-suffix-p " ." js-comint--completion-prefix)
336
- (seq-map (apply-partially #'string-remove-prefix js-comint--completion-prefix) completion-res)
337
- completion-res)))
338
- ; ; this clears the input used to trigger completion
345
+ (let ((completion-res (js-comint--process-completion-output js-comint--completion-output js-comint--completion-prefix)))
339
346
(print completion-res)
340
347
(funcall js-comint--post-completion-cb completion-res)
341
348
(setq js-comint--post-completion-cb nil )
342
349
(js-comint--reset-completion-state)
350
+ ; ; this clears the input used to trigger completion
343
351
(js-comint--clear-repl-input))))
344
352
output)
345
353
0 commit comments