feat(emacs/lean-company): call FINDG if cursor is at "_"
This commit is contained in:
parent
4f604544c4
commit
3682ca32d2
3 changed files with 44 additions and 20 deletions
|
@ -31,22 +31,34 @@
|
||||||
"Returns the symbol to complete. Also, if point is on a dot,
|
"Returns the symbol to complete. Also, if point is on a dot,
|
||||||
triggers a completion immediately."
|
triggers a completion immediately."
|
||||||
(let ((prefix (company-grab-symbol)))
|
(let ((prefix (company-grab-symbol)))
|
||||||
(when (and
|
(cond ((looking-at (rx symbol-start "_")) "")
|
||||||
(company-lean--need-autocomplete)
|
((and
|
||||||
(or
|
(company-lean--need-autocomplete)
|
||||||
(> (length prefix) 3)
|
(or
|
||||||
(string-match "[_.]" prefix)))
|
(> (length prefix) 3)
|
||||||
prefix)))
|
(string-match "[_.]" prefix)))
|
||||||
|
prefix))))
|
||||||
|
|
||||||
(defun company-lean--make-candidate (arg)
|
(defun company-lean--make-candidate (arg)
|
||||||
(propertize (car arg) 'type (cdr arg)))
|
(propertize (car arg) 'type (cdr arg)))
|
||||||
|
|
||||||
(defun company-lean--candidates (prefix)
|
(defun company-lean--candidates (prefix)
|
||||||
(let ((line-number (line-number-at-pos)))
|
(let ((line-number (line-number-at-pos))
|
||||||
(lean-server-send-cmd-sync (lean-cmd-findp line-number prefix)
|
(column-number (current-column))
|
||||||
(lambda (candidates)
|
pattern)
|
||||||
(lean-server-debug "executing continuation for FINDP")
|
(lean-server-send-cmd-sync (lean-cmd-wait))
|
||||||
(-map 'company-lean--make-candidate candidates)))))
|
(cond
|
||||||
|
((looking-at (rx symbol-start "_"))
|
||||||
|
(setq pattern (read-string "Filter for find declarations (e.g: +intro -and): " "" nil ""))
|
||||||
|
(lean-server-send-cmd-sync (lean-cmd-findg line-number column-number pattern)
|
||||||
|
(lambda (candidates)
|
||||||
|
(lean-server-debug "executing continuation for FINDG")
|
||||||
|
(-map 'company-lean--make-candidate candidates))))
|
||||||
|
(t
|
||||||
|
(lean-server-send-cmd-sync (lean-cmd-findp line-number prefix)
|
||||||
|
(lambda (candidates)
|
||||||
|
(lean-server-debug "executing continuation for FINDP")
|
||||||
|
(-map 'company-lean--make-candidate candidates)))))))
|
||||||
|
|
||||||
(defun company-lean--location (arg)
|
(defun company-lean--location (arg)
|
||||||
(lean-generate-tags)
|
(lean-generate-tags)
|
||||||
|
@ -74,6 +86,10 @@ triggers a completion immediately."
|
||||||
"...")))
|
"...")))
|
||||||
annotation-str))))
|
annotation-str))))
|
||||||
|
|
||||||
|
(defun company-lean--pre-completion (args)
|
||||||
|
(when (looking-at (rx "_"))
|
||||||
|
(delete-forward-char 1)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun company-lean (command &optional arg &rest ignored)
|
(defun company-lean (command &optional arg &rest ignored)
|
||||||
(case command
|
(case command
|
||||||
|
@ -81,6 +97,7 @@ triggers a completion immediately."
|
||||||
(candidates (company-lean--candidates arg))
|
(candidates (company-lean--candidates arg))
|
||||||
(annotation (company-lean--annotation arg))
|
(annotation (company-lean--annotation arg))
|
||||||
(location (company-lean--location arg))
|
(location (company-lean--location arg))
|
||||||
|
(pre-completion (company-lean--pre-completion arg))
|
||||||
(sorted t)))
|
(sorted t)))
|
||||||
|
|
||||||
(defadvice company--window-width
|
(defadvice company--window-width
|
||||||
|
|
|
@ -54,12 +54,14 @@
|
||||||
|
|
||||||
|
|
||||||
(defun lean-check-expansion ()
|
(defun lean-check-expansion ()
|
||||||
|
(interactive)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(if (looking-at "\\_>") t
|
(if (looking-at (rx symbol-start "_")) t
|
||||||
(backward-char 1)
|
(if (looking-at "\\_>") t
|
||||||
(if (looking-at "\\.") t
|
|
||||||
(backward-char 1)
|
(backward-char 1)
|
||||||
(if (looking-at "->") t nil)))))
|
(if (looking-at "\\.") t
|
||||||
|
(backward-char 1)
|
||||||
|
(if (looking-at "->") t nil))))))
|
||||||
|
|
||||||
(defun lean-tab-indent-or-complete ()
|
(defun lean-tab-indent-or-complete ()
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
|
@ -258,8 +258,10 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
|
||||||
('OPTIONS ())
|
('OPTIONS ())
|
||||||
('SHOW (lean-server-check-current-file))
|
('SHOW (lean-server-check-current-file))
|
||||||
('VALID (lean-server-check-current-file))
|
('VALID (lean-server-check-current-file))
|
||||||
('FINDP (lean-server-check-current-file))
|
('FINDP (lean-flush-changed-lines)
|
||||||
('FINDG (lean-server-check-current-file))))
|
(lean-server-check-current-file))
|
||||||
|
('FINDG (lean-flush-changed-lines)
|
||||||
|
(lean-server-check-current-file))
|
||||||
('WAIT (lean-server-check-current-file))))
|
('WAIT (lean-server-check-current-file))))
|
||||||
|
|
||||||
(defun lean-server-after-send-cmd (cmd)
|
(defun lean-server-after-send-cmd (cmd)
|
||||||
|
@ -278,7 +280,7 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
|
||||||
('SHOW ())
|
('SHOW ())
|
||||||
('VALID ())
|
('VALID ())
|
||||||
('FINDP ())
|
('FINDP ())
|
||||||
('FINDG ())))
|
('FINDG ())
|
||||||
('WAIT ())))
|
('WAIT ())))
|
||||||
|
|
||||||
(defun lean-server-send-cmd (cmd)
|
(defun lean-server-send-cmd (cmd)
|
||||||
|
@ -361,7 +363,8 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
|
||||||
(lean-server-set-timer-for-event-handler)))
|
(lean-server-set-timer-for-event-handler)))
|
||||||
|
|
||||||
(defun lean-server-consume-all-async-tasks ()
|
(defun lean-server-consume-all-async-tasks ()
|
||||||
(lean-server-debug "lean-server-consume-all-async-tasks")
|
(lean-server-debug "lean-server-consume-all-async-tasks: queue size = %d"
|
||||||
|
(lean-server-async-task-queue-len))
|
||||||
(while lean-global-async-task-queue
|
(while lean-global-async-task-queue
|
||||||
(accept-process-output (lean-server-get-process) 0 50 t)
|
(accept-process-output (lean-server-get-process) 0 50 t)
|
||||||
(let* ((cont (lean-server-async-task-queue-peek-front))
|
(let* ((cont (lean-server-async-task-queue-peek-front))
|
||||||
|
@ -370,7 +373,9 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd.
|
||||||
(`(PROCESSED ,ret)
|
(`(PROCESSED ,ret)
|
||||||
(lean-server-async-task-queue-pop-front)
|
(lean-server-async-task-queue-pop-front)
|
||||||
(lean-server-debug "lean-server-consume-all-sync-tasks: processed. queue size = %d"
|
(lean-server-debug "lean-server-consume-all-sync-tasks: processed. queue size = %d"
|
||||||
(lean-server-async-task-queue-len)))))))
|
(lean-server-async-task-queue-len))))))
|
||||||
|
(lean-server-debug "lean-server-consume-all-async-tasks: over. queue size = %d"
|
||||||
|
(lean-server-async-task-queue-len)))
|
||||||
|
|
||||||
(defun lean-server-send-cmd-sync (cmd &optional cont)
|
(defun lean-server-send-cmd-sync (cmd &optional cont)
|
||||||
"Send cmd to lean-server (sync)."
|
"Send cmd to lean-server (sync)."
|
||||||
|
|
Loading…
Reference in a new issue