From 2e0317dd43e01a7b6fffc779b683993c3222faa2 Mon Sep 17 00:00:00 2001 From: nosami Date: Fri, 18 Mar 2016 21:39:51 +0000 Subject: [PATCH 1/8] Make completion faster by parsing once per line --- fsharp-mode-completion.el | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index 3ed6b74..6bc2136 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -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) @@ -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 @@ -233,7 +231,7 @@ For indirect buffers return the truename of the base buffer." (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" "")))) + (if (string= cmd "completion") "filter=StartsWith" "")))) (defun fsharp-ac--process-live-p () "Check whether the background process is live." @@ -341,12 +339,15 @@ 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)) + (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) From 99adfb2233e49798b2d6104dc442553bddeeed3d Mon Sep 17 00:00:00 2001 From: nosami Date: Sun, 20 Mar 2016 21:33:28 +0000 Subject: [PATCH 2/8] Don't require a full parse before sending completions --- fsharp-mode-completion.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index 6bc2136..90a4ba3 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -228,10 +228,11 @@ 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 (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) + (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." @@ -341,8 +342,9 @@ For indirect buffers return the truename of the base buffer." (clrhash fsharp-ac-current-helptext) (let ((line (line-number-at-pos))) (if (not (eq fsharp-ac-last-parsed-line line)) - (setq fsharp-ac-last-parsed-line line) - (fsharp-ac-parse-current-buffer)) + (progn + (setq fsharp-ac-last-parsed-line line) + (fsharp-ac-parse-current-buffer))) (fsharp-ac-send-pos-request "completion" (fsharp-ac--buffer-truename) From dff39103466bddb56fc97247637d4107a1fa48d9 Mon Sep 17 00:00:00 2001 From: nosami Date: Mon, 21 Mar 2016 09:53:47 +0000 Subject: [PATCH 3/8] This makes the speedup more apparent --- fsharp-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsharp-mode.el b/fsharp-mode.el index e6ab226..c6e9b8d 100644 --- a/fsharp-mode.el +++ b/fsharp-mode.el @@ -252,7 +252,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) From fc35dc37fbf0729677bc65f3c39de8e66a373109 Mon Sep 17 00:00:00 2001 From: nosami Date: Thu, 24 Mar 2016 13:24:12 +0000 Subject: [PATCH 4/8] untabify --- fsharp-mode-completion.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index 90a4ba3..cf19e13 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -362,8 +362,8 @@ 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) @@ -371,10 +371,10 @@ For indirect buffers return the truename of the base buffer." (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) From 6313a38d7ef45a2808279cea31286a465b38acf6 Mon Sep 17 00:00:00 2001 From: nosami Date: Thu, 24 Mar 2016 13:37:51 +0000 Subject: [PATCH 5/8] Remove parse from other commands --- fsharp-mode-completion.el | 3 --- 1 file changed, 3 deletions(-) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index cf19e13..e1c8382 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -498,7 +498,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) @@ -508,7 +507,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) @@ -518,7 +516,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) From 98157f415fcc43d68f39224feb099cf7fdd8e1f1 Mon Sep 17 00:00:00 2001 From: nosami Date: Sat, 26 Mar 2016 15:10:23 +0000 Subject: [PATCH 6/8] escape double quotes in lineStr --- fsharp-mode-completion.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index e1c8382..0dc9e5e 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -226,9 +226,8 @@ For indirect buffers return the truename of the base buffer." ;;; ---------------------------------------------------------------------------- ;;; Display Requests - (defun fsharp-ac-send-pos-request (cmd file line col) - (let ((linestr (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) + (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) From c43672c2bc9cb296e722708f9373a0c988d45fa4 Mon Sep 17 00:00:00 2001 From: nosami Date: Sat, 26 Mar 2016 19:09:12 +0000 Subject: [PATCH 7/8] Force parse when pressing C-c, C-. --- fsharp-mode-completion.el | 1 + 1 file changed, 1 insertion(+) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index 0dc9e5e..4c837f6 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -529,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 () From 933abdcd99aba1fd823fb35bedf6d8b66621e85a Mon Sep 17 00:00:00 2001 From: nosami Date: Mon, 28 Mar 2016 03:54:12 +0100 Subject: [PATCH 8/8] Added left parens and comma as excluded chars in fsharp-ac-residue --- fsharp-mode-completion.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index 4c837f6..bbd5bfc 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -398,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. @@ -432,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.")