Skip to content

Commit

Permalink
Merge pull request #65 from nosami/faster-completions
Browse files Browse the repository at this point in the history
Faster completions
  • Loading branch information
rneatherway committed Apr 5, 2016
2 parents 27e9e8e + 933abdc commit 2ed8f6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
54 changes: 27 additions & 27 deletions fsharp-mode-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ If set to nil, display in a help buffer instead.")
(defconst fsharp-ac--completion-bufname
(concat "*" fsharp-ac--completion-procname "*"))

(defvar-local fsharp-ac-last-parsed-line -1
"The line number that we last requested a parse for completions")

(defun fsharp-ac--log (str)
(when fsharp-ac-debug
(unless (get-buffer fsharp-ac--log-buf)
Expand Down Expand Up @@ -137,11 +140,6 @@ since the last request."
(buffer-substring-no-properties (point-min) (point-max)))))
(setq fsharp-ac-last-parsed-ticks (buffer-chars-modified-tick)))))

(defun fsharp-ac-parse-file (file)
(with-current-buffer (find-file-noselect file)
(fsharp-ac-parse-current-buffer)))


(defun fsharp-ac--isIdChar (c)
(let ((gc (get-char-code-property c 'general-category)))
(or
Expand Down Expand Up @@ -228,12 +226,12 @@ For indirect buffers return the truename of the base buffer."

;;; ----------------------------------------------------------------------------
;;; Display Requests

(defun fsharp-ac-send-pos-request (cmd file line col)
(log-psendstr fsharp-ac-completion-process
(format "%s \"%s\" %d %d %d %s\n" cmd file line col
(* 1000 fsharp-ac-blocking-timeout)
(if (string= cmd "completion") "filter=StartsWith" ""))))
(let ((linestr (replace-regexp-in-string "\"" "\\\""(buffer-substring-no-properties (line-beginning-position) (line-end-position)) t t)))
(log-psendstr fsharp-ac-completion-process
(format "%s \"%s\" \"%s\" %d %d %d %s\n" cmd file linestr line col
(* 1000 fsharp-ac-blocking-timeout)
(if (string= cmd "completion") "filter=StartsWith" "")))))

(defun fsharp-ac--process-live-p ()
"Check whether the background process is live."
Expand Down Expand Up @@ -341,12 +339,16 @@ For indirect buffers return the truename of the base buffer."
(setq fsharp-ac-status 'wait)
(setq fsharp-ac-current-candidate nil)
(clrhash fsharp-ac-current-helptext)
(fsharp-ac-parse-current-buffer)
(fsharp-ac-send-pos-request
"completion"
(fsharp-ac--buffer-truename)
(line-number-at-pos)
(+ 1 (current-column))))
(let ((line (line-number-at-pos)))
(if (not (eq fsharp-ac-last-parsed-line line))
(progn
(setq fsharp-ac-last-parsed-line line)
(fsharp-ac-parse-current-buffer)))
(fsharp-ac-send-pos-request
"completion"
(fsharp-ac--buffer-truename)
line
(+ 1 (current-column)))))

(require 'cl-lib)

Expand All @@ -359,19 +361,19 @@ For indirect buffers return the truename of the base buffer."
(if (and (fsharp-ac-can-make-request 't)
(eq fsharp-ac-status 'idle))
(progn
(setq fsharp-company-callback callback)
(fsharp-ac-make-completion-request))
(setq fsharp-company-callback callback)
(fsharp-ac-make-completion-request))
(funcall callback nil)))

(defun fsharp-ac-add-annotation-prop (s candidate)
(propertize s 'annotation (gethash "GlyphChar" candidate)))

(defun fsharp-ac-completion-done ()
(->> (-map (lambda (candidate)
(let ((s (gethash "Name" candidate)))
(if (fsharp-ac--isNormalId s) (fsharp-ac-add-annotation-prop s candidate)
(s-append "``" (s-prepend "``" (fsharp-ac-add-annotation-prop s candidate))))))
fsharp-ac-current-candidate)
(let ((s (gethash "Name" candidate)))
(if (fsharp-ac--isNormalId s) (fsharp-ac-add-annotation-prop s candidate)
(s-append "``" (s-prepend "``" (fsharp-ac-add-annotation-prop s candidate))))))
fsharp-ac-current-candidate)
(funcall fsharp-company-callback)))

(defun completion-char-p (c)
Expand All @@ -396,7 +398,7 @@ For indirect buffers return the truename of the base buffer."
(doc-buffer (company-doc-buffer (fsharp-ac-document arg)))))

(defconst fsharp-ac--ident
(rx (one-or-more (not (any ".` \t\r\n"))))
(rx (one-or-more (not (any ".` ,(\t\r\n"))))
"Regexp for normal identifiers.")

; Note that this regexp is not 100% correct.
Expand Down Expand Up @@ -430,7 +432,7 @@ For indirect buffers return the truename of the base buffer."
(or (regexp ,fsharp-ac--ident)
(regexp ,fsharp-ac--rawIdent))
"."))
(group (zero-or-more (not (any ".` \t\r\n"))))
(group (zero-or-more (not (any ".` ,(\t\r\n"))))
string-end))
"Regexp for a dotted ident with a standard residue.")

Expand Down Expand Up @@ -495,7 +497,6 @@ on QUIET to FSHARP-AC-CAN-MAKE-REQUEST. This is a bit of hack to
prevent usage errors being displayed by FSHARP-DOC-MODE."
(interactive)
(when (fsharp-ac-can-make-request quiet)
(fsharp-ac-parse-current-buffer)
(fsharp-ac-send-pos-request "tooltip"
(fsharp-ac--buffer-truename)
(line-number-at-pos)
Expand All @@ -505,7 +506,6 @@ prevent usage errors being displayed by FSHARP-DOC-MODE."
"Find the uses in this file of the symbol at point."
(interactive)
(when (fsharp-ac-can-make-request)
(fsharp-ac-parse-current-buffer)
(fsharp-ac-send-pos-request "symboluse"
(fsharp-ac--buffer-truename)
(line-number-at-pos)
Expand All @@ -515,7 +515,6 @@ prevent usage errors being displayed by FSHARP-DOC-MODE."
"Find the point of declaration of the symbol at point and goto it."
(interactive)
(when (fsharp-ac-can-make-request)
(fsharp-ac-parse-current-buffer)
(fsharp-ac-send-pos-request "finddecl"
(fsharp-ac--buffer-truename)
(line-number-at-pos)
Expand All @@ -530,6 +529,7 @@ prevent usage errors being displayed by FSHARP-DOC-MODE."
(interactive)
(when (and (fsharp-ac-can-make-request quiet)
(eq fsharp-ac-status 'idle))
(fsharp-ac-parse-current-buffer)
(company-complete)))

(defun fsharp-ac--parse-current-file ()
Expand Down
2 changes: 1 addition & 1 deletion fsharp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
(setq company-backends (list 'fsharp-ac/company-backend))
(setq company-auto-complete 't)
(setq company-auto-complete-chars ".")
(setq company-idle-delay 0.5)
(setq company-idle-delay 0.03)
(setq company-minimum-prefix-length 0)
(setq company-require-match 'nil)
(setq company-tooltip-align-annotations 't)
Expand Down

0 comments on commit 2ed8f6a

Please sign in to comment.