Add struct call tip expansion and error handler
This commit is contained in:
parent
4c6b5ab00d
commit
fb06673ad3
|
|
@ -123,27 +123,30 @@ If you want to restart server, use `ac-dcd-init-server' instead."
|
||||||
(push match lines))))
|
(push match lines))))
|
||||||
lines))
|
lines))
|
||||||
|
|
||||||
|
(defvar ac-dcd-error-message-regexp
|
||||||
|
(rx (and (submatch (* nonl)) ": " (submatch (* nonl)) ": " (submatch (* nonl) eol)))
|
||||||
|
"If it matches first line of dcd-output, it would be error message.")
|
||||||
|
|
||||||
(defun ac-dcd-handle-error (res args)
|
(defun ac-dcd-handle-error (res args)
|
||||||
"Notify error on parse failure."
|
"Notify error."
|
||||||
(goto-char (point-min))
|
(let* ((errbuf (get-buffer-create ac-dcd-error-buffer-name))
|
||||||
(let* ((buf (get-buffer-create ac-dcd-error-buffer-name))
|
(outbuf (get-buffer ac-dcd-output-buffer-name))
|
||||||
(cmd (concat ac-dcd-executable " " (mapconcat 'identity args " ")))
|
(cmd (concat ac-dcd-executable " " (mapconcat 'identity args " ")))
|
||||||
(pattern (format ac-dcd-completion-pattern ""))
|
(errstr
|
||||||
(err (if (re-search-forward pattern nil t)
|
(with-current-buffer outbuf
|
||||||
(buffer-substring-no-properties (point-min)
|
(goto-char (point-min))
|
||||||
(1- (match-beginning 0)))
|
(re-search-forward ac-dcd-error-message-regexp)
|
||||||
;; Warn the user more agressively if no match was found.
|
(concat
|
||||||
(message "dcd-client failed with error %d:\n%s" res cmd)
|
(match-string 2) " : " (match-string 3)))
|
||||||
(buffer-string))))
|
))
|
||||||
(with-current-buffer buf
|
(with-current-buffer errbuf
|
||||||
(let ((inhibit-read-only t))
|
(erase-buffer)
|
||||||
(erase-buffer)
|
(insert (current-time-string)
|
||||||
(insert (current-time-string)
|
"\n\"" cmd "\" failed."
|
||||||
(format "\ndcd-client failed with error %d:\n" res)
|
(format "\nError type is: %s\n" errstr)
|
||||||
cmd "\n\n")
|
)
|
||||||
(insert err)
|
(goto-char (point-min)))
|
||||||
(setq buffer-read-only t)
|
(display-buffer errbuf)))
|
||||||
(goto-char (point-min))))))
|
|
||||||
|
|
||||||
|
|
||||||
;; utility functions to call process
|
;; utility functions to call process
|
||||||
|
|
@ -157,7 +160,8 @@ If you want to restart server, use `ac-dcd-init-server' instead."
|
||||||
args
|
args
|
||||||
))
|
))
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(unless (eq 0 res)
|
(goto-char (point-min))
|
||||||
|
(when (re-search-forward ac-dcd-error-message-regexp nil t)
|
||||||
(ac-dcd-handle-error res args))
|
(ac-dcd-handle-error res args))
|
||||||
;; Still try to get any useful input.
|
;; Still try to get any useful input.
|
||||||
(ac-dcd-parse-output prefix))))
|
(ac-dcd-parse-output prefix))))
|
||||||
|
|
@ -228,6 +232,7 @@ TODO: multi byte character support"
|
||||||
))))
|
))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun ac-dcd-action ()
|
(defun ac-dcd-action ()
|
||||||
"Try function calltip expansion."
|
"Try function calltip expansion."
|
||||||
(when (featurep 'yasnippet)
|
(when (featurep 'yasnippet)
|
||||||
|
|
@ -237,6 +242,9 @@ TODO: multi byte character support"
|
||||||
((equal "f" (get-text-property 0 'ac-dcd-help lastcompl)) ; when it was a function
|
((equal "f" (get-text-property 0 'ac-dcd-help lastcompl)) ; when it was a function
|
||||||
(progn
|
(progn
|
||||||
(ac-complete-dcd-calltips)))
|
(ac-complete-dcd-calltips)))
|
||||||
|
((equal "s" (get-text-property 0 'ac-dcd-help lastcompl)) ; when it was a struct
|
||||||
|
(progn
|
||||||
|
(ac-complete-dcd-calltips-for-struct-constructor)))
|
||||||
(t nil)
|
(t nil)
|
||||||
))))
|
))))
|
||||||
|
|
||||||
|
|
@ -355,13 +363,44 @@ This function should be called at *dcd-output* buf."
|
||||||
(defun ac-dcd-calltip-prefix ()
|
(defun ac-dcd-calltip-prefix ()
|
||||||
(car ac-last-completion))
|
(car ac-last-completion))
|
||||||
|
|
||||||
(ac-define-source dcd-calltips
|
(defvar dcd-calltips
|
||||||
'((candidates . ac-dcd-calltip-candidate)
|
'((candidates . ac-dcd-calltip-candidate)
|
||||||
(prefix . ac-dcd-calltip-prefix)
|
(prefix . ac-dcd-calltip-prefix)
|
||||||
(action . ac-dcd-calltip-action)
|
(action . ac-dcd-calltip-action)
|
||||||
(cache)
|
(cache)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(defun ac-complete-dcd-calltips ()
|
||||||
|
(auto-complete '(dcd-calltips)))
|
||||||
|
|
||||||
|
|
||||||
|
;; struct constructor calltip expansion
|
||||||
|
|
||||||
|
(defsubst ac-dcd-replace-this-to-struct-name (struct-name)
|
||||||
|
"When to complete struct constructor calltips, dcd-client outputs candidates which begins with\"this\",
|
||||||
|
so I have to replace it with struct name."
|
||||||
|
(while (search-forward "this" nil t))
|
||||||
|
(replace-match struct-name))
|
||||||
|
|
||||||
|
(defun ac-dcd-calltip-candidate-for-struct-constructor ()
|
||||||
|
"Almost the same as `ac-dcd-calltip-candidate', but calls `ac-dcd-replace-this-to-struct-name' before parsing."
|
||||||
|
(let ((buf (get-buffer-create ac-dcd-output-buffer-name)))
|
||||||
|
(ac-dcd-call-process-for-calltips)
|
||||||
|
(with-current-buffer buf
|
||||||
|
(ac-dcd-replace-this-to-struct-name (cdr ac-last-completion))
|
||||||
|
(ac-dcd-parse-calltips))
|
||||||
|
))
|
||||||
|
|
||||||
|
(defvar dcd-calltips-for-struct-constructor
|
||||||
|
'((candidates . ac-dcd-calltip-candidate-for-struct-constructor)
|
||||||
|
(prefix . ac-dcd-calltip-prefix)
|
||||||
|
(action . ac-dcd-calltip-action)
|
||||||
|
(cache)
|
||||||
|
))
|
||||||
|
|
||||||
|
(defun ac-complete-dcd-calltips-for-struct-constructor ()
|
||||||
|
(auto-complete '(dcd-calltips-for-struct-constructor)))
|
||||||
|
|
||||||
|
|
||||||
;;show document
|
;;show document
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue