aaronjensen/company-flow

Does not complete full flow type syntax?

Closed this issue · 28 comments

I have a function definition
function(User: Class<UserModel>,

trying to recreate with company-flowonly autocompletesUserModelit dosen't contain theClass<>` syntax

Hi, thanks for the report, but for autocomplete issues, I'd recommend opening an issue on https://github.com/facebook/flow/issues

company-flow only ties into that.

@aaronjensen Maybe you can answer from your personal experience. Should I expect that kind of syntax completed? Or is that a bad assumption? Are you telling me you have to manually type out th e Class<> part?

To be honest, I'm not really sure what the situation your'e describing is. Could you tell me what the text looks like when you expect the completion to happen and what the completion you expect is (and where the point is)

Something like:

function(User: C|

Where the point is at | and you expect Class to be a completion option

Thanks for responding @aaronjensen

It looks like the real problem is that company-flow is not loading as a used backend.

I discovered this from the thread at #11

company-diag displays the following:

Emacs 25.3.1 (x86_64-apple-darwin13.4.0) of 2017-09-12 on builder10-9.local
Company 0.9.6

company-backends: ((company-tern company-web-html :with company-yasnippet)
 company-flow company-web-html company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
 (company-dabbrev-code company-gtags company-etags company-keywords)
 company-oddmuse company-dabbrev)

Used backend: (company-tern company-web-html :with company-yasnippet)

Major mode: rjsx-mode
Prefix: ("" . t)

Completions: none

per b226369 I thought this was in by default.

I have the package configured with

(use-package company-flow
  :ensure t
  :defer t
  :init
  (with-eval-after-load 'company
    (add-to-list 'company-backends 'company-flow))
  :config
  (add-to-list 'company-flow-modes 'rjsx-mode))

ah, so what you're actually seeing here is that company-flow is in your list of backends but company-tern is in front of it. company-tern can handle this, so it is being selected as the "Used backend".

You'll probably want to disable company-tern entirely if you're going to use company-flow.

You also should be able to M-: (add-to-list 'company-flow-modes 'rjsx-mode) within your buffer to bump flow to the front of the list for testing purposes. Ultimately though, I prefer to not use tern at all when using flow or typescript.

ok I have dropped company-tern

I am still having issues and the company-diag now shows:

Emacs 25.3.1 (x86_64-apple-darwin13.4.0) of 2017-09-12 on builder10-9.local
Company 0.9.6

company-backends: (company-flow company-web-html company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Used backend: (company-dabbrev-code company-gtags company-etags company-keywords)

Major mode: rjsx-mode
Prefix: ""
Completions:
  "account"
  "getLinkedAccountsAsync"
  "await"
  "linkedAccounts"
  "const"
  "user"
  "admin"
  "denyOnBitMEXUser"
  "await"
  "HTTPError"

this is after manually executing M-: (add-to-list 'company-flow-modes 'rjsx-mode)

Does this mean that (company-dabbrev-code company-gtags company-etags company-keywords)(company-dabbrev-code company-gtags company-etags company-keywords) is now overriding (company-flow) ??

Check your value of company-flow-executable. This should eval to a path: M-: (executable-find company-flow-executable)

I do something like this:

(defun flow/set-flow-executable ()
  (interactive)
  (let* ((os (pcase system-type
               ('darwin "osx")
               ('gnu/linux "linux64")
               (_ nil)))
         (root (locate-dominating-file  buffer-file-name  "node_modules/flow-bin"))
         (executable (car (file-expand-wildcards
                           (concat root "node_modules/flow-bin/*" os "*/flow")))))
    (setq-local flow-minor-default-binary executable)
    (setq-local company-flow-executable executable)
    (setq-local flycheck-javascript-flow-executable executable)))

(add-hook 'rjsx-mode-hook #'flow/set-flow-executable t)

"/usr/local/bin/flow"

This is a sym link. Not sure if it matters.

0 lrwxr-xr-x 1 kevzettler admin 53B Apr 19 10:25 flow -> /Users/kevzettler/.nvm/versions/node/v9.11.1/bin/flow

Does M-: (company-flow-prefix) eval to anything? If not, you'll need to figure out which condition in it is failing.

(make sure your point is at the end of a word in an rjsx-mode buffer before you eval that

uh does this mean its failing?

Debugger entered--Lisp error: (void-variable company-flow-prefix)
  eval(company-flow-prefix nil)
  eval-expression(company-flow-prefix nil)
  funcall-interactively(eval-expression company-flow-prefix nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)
  read-from-minibuffer("M-x " "^" (keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) keymap (3 keymap (19 . ivy-rotate-sort) (1 . ivy-toggle-ignore) (15 . ivy-occur)) (67108903 . ivy-avy) (33554464 . ivy-restrict-to-matches) (15 . hydra-ivy/body) (22 . ivy-scroll-up-command) (prior . ivy-scroll-down-command) (next . ivy-scroll-up-command) (7 . minibuffer-keyboard-quit) (32 . self-insert-command) (18 . ivy-reverse-i-search) (19 . ivy-next-line-or-history) (remap keymap (describe-mode . ivy-help) (kill-ring-save . ivy-kill-ring-save) (kill-line . ivy-kill-line) (scroll-down-command . ivy-scroll-down-command) (scroll-up-command . ivy-scroll-up-command) (end-of-buffer . ivy-end-of-buffer) (beginning-of-buffer . ivy-beginning-of-buffer) (kill-word . ivy-kill-word) (forward-char . ivy-forward-char) (delete-char . ivy-delete-char) (backward-kill-word . ivy-backward-kill-word) (backward-delete-char-untabify . ivy-backward-delete-char) (delete-backward-char . ivy-backward-delete-char) (previous-line . ivy-previous-line) (next-line . ivy-next-line)) (9 . ivy-partial-or-done) (10 . ivy-alt-done) (27 keymap (1 . ivy-read-action) (15 . ivy-dispatching-call) (111 . ivy-dispatching-done) (105 . ivy-insert-current) (106 . ivy-yank-word) (114 . ivy-toggle-regexp-quote) (16 . ivy-previous-line-and-call) (14 . ivy-next-line-and-call) (118 . ivy-scroll-down-command) (112 . ivy-previous-history-element) (110 . ivy-next-history-element) (10 . ivy-immediate-done) (13 . ivy-call)) (13 . ivy-done)) nil counsel-M-x-history)
  ivy-read("M-x " [## bookmark-bmenu-file-column rjsx-identifier js2-xml-prop-ref-node-colon-pos--cmacro lm-get-package-name true-expr declaration debugger-previous-window recentf-sort-directories-descending js2-apply-jslint-declaration-externs misearch-unload-function cl-struct-js2-xml-pi-node-tags copy-js2-keyword-node js2-xml-dot-query-node-p bookmark-current-buffer rjsx-print-debug-message starttls-extra-args js2-end-of-defun initprop cl-struct-rjsx-member-tags js2-current-scope js2-class-node-p rjsx-node-closing-tag--cmacro HTMLHRElement rjsx-member-full-name recentf-set-menu-element-value depositAddress recentf-dump-variable js2-xml-dot-query-node-right--cmacro bookmark-menu-bookmark js2-visit-call-node cl-struct-rjsx-wrapped-expr bookmark-set-position bookmark-bmenu-2-window UserModel addr js2--get-name-node recentf-mode-on-hook vc-git--call tree-widget--locate-sub-directory vc-git-extra-fileinfo-p--cmacro js2-mode-reset starterlen rjsx-node-name recentf-elements js2-infix-node-parent--cmacro js2-digit-p js2-class-node-form--cmacro rjsx-mode-map responses ...] :predicate commandp :require-match t :history counsel-M-x-history :action #[257 "\304\305!\203\f�\306\307�!!\210��\307�!\211��\310\307�!\311\")\207" [current-prefix-arg prefix-arg this-command real-this-command featurep smex smex-rank intern command-execute record] 4 "\n\n(fn CMD)"] :sort t :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)
  read-from-minibuffer("M-x " "^" (keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) keymap (3 keymap (19 . ivy-rotate-sort) (1 . ivy-toggle-ignore) (15 . ivy-occur)) (67108903 . ivy-avy) (33554464 . ivy-restrict-to-matches) (15 . hydra-ivy/body) (22 . ivy-scroll-up-command) (prior . ivy-scroll-down-command) (next . ivy-scroll-up-command) (7 . minibuffer-keyboard-quit) (32 . self-insert-command) (18 . ivy-reverse-i-search) (19 . ivy-next-line-or-history) (remap keymap (describe-mode . ivy-help) (kill-ring-save . ivy-kill-ring-save) (kill-line . ivy-kill-line) (scroll-down-command . ivy-scroll-down-command) (scroll-up-command . ivy-scroll-up-command) (end-of-buffer . ivy-end-of-buffer) (beginning-of-buffer . ivy-beginning-of-buffer) (kill-word . ivy-kill-word) (forward-char . ivy-forward-char) (delete-char . ivy-delete-char) (backward-kill-word . ivy-backward-kill-word) (backward-delete-char-untabify . ivy-backward-delete-char) (delete-backward-char . ivy-backward-delete-char) (previous-line . ivy-previous-line) (next-line . ivy-next-line)) (9 . ivy-partial-or-done) (10 . ivy-alt-done) (27 keymap (1 . ivy-read-action) (15 . ivy-dispatching-call) (111 . ivy-dispatching-done) (105 . ivy-insert-current) (106 . ivy-yank-word) (114 . ivy-toggle-regexp-quote) (16 . ivy-previous-line-and-call) (14 . ivy-next-line-and-call) (118 . ivy-scroll-down-command) (112 . ivy-previous-history-element) (110 . ivy-next-history-element) (10 . ivy-immediate-done) (13 . ivy-call)) (13 . ivy-done)) nil counsel-M-x-history)
  ivy-read("M-x " [## bookmark-bmenu-file-column rjsx-identifier js2-xml-prop-ref-node-colon-pos--cmacro lm-get-package-name true-expr declaration debugger-previous-window recentf-sort-directories-descending js2-apply-jslint-declaration-externs misearch-unload-function cl-struct-js2-xml-pi-node-tags copy-js2-keyword-node js2-xml-dot-query-node-p bookmark-current-buffer rjsx-print-debug-message starttls-extra-args js2-end-of-defun initprop cl-struct-rjsx-member-tags js2-current-scope js2-class-node-p rjsx-node-closing-tag--cmacro HTMLHRElement rjsx-member-full-name recentf-set-menu-element-value depositAddress recentf-dump-variable js2-xml-dot-query-node-right--cmacro bookmark-menu-bookmark js2-visit-call-node cl-struct-rjsx-wrapped-expr bookmark-set-position bookmark-bmenu-2-window UserModel addr js2--get-name-node recentf-mode-on-hook vc-git--call tree-widget--locate-sub-directory vc-git-extra-fileinfo-p--cmacro js2-mode-reset starterlen rjsx-node-name recentf-elements js2-infix-node-parent--cmacro js2-digit-p js2-class-node-form--cmacro rjsx-mode-map responses ...] :predicate commandp :require-match t :history counsel-M-x-history :action #[257 "\304\305!\203\f�\306\307�!!\210��\307�!\211��\310\307�!\311\")\207" [current-prefix-arg prefix-arg this-command real-this-command featurep smex smex-rank intern command-execute record] 4 "\n\n(fn CMD)"] :sort t :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)
  read-from-minibuffer("M-x " "^" (keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) keymap (3 keymap (19 . ivy-rotate-sort) (1 . ivy-toggle-ignore) (15 . ivy-occur)) (67108903 . ivy-avy) (33554464 . ivy-restrict-to-matches) (15 . hydra-ivy/body) (22 . ivy-scroll-up-command) (prior . ivy-scroll-down-command) (next . ivy-scroll-up-command) (7 . minibuffer-keyboard-quit) (32 . self-insert-command) (18 . ivy-reverse-i-search) (19 . ivy-next-line-or-history) (remap keymap (describe-mode . ivy-help) (kill-ring-save . ivy-kill-ring-save) (kill-line . ivy-kill-line) (scroll-down-command . ivy-scroll-down-command) (scroll-up-command . ivy-scroll-up-command) (end-of-buffer . ivy-end-of-buffer) (beginning-of-buffer . ivy-beginning-of-buffer) (kill-word . ivy-kill-word) (forward-char . ivy-forward-char) (delete-char . ivy-delete-char) (backward-kill-word . ivy-backward-kill-word) (backward-delete-char-untabify . ivy-backward-delete-char) (delete-backward-char . ivy-backward-delete-char) (previous-line . ivy-previous-line) (next-line . ivy-next-line)) (9 . ivy-partial-or-done) (10 . ivy-alt-done) (27 keymap (1 . ivy-read-action) (15 . ivy-dispatching-call) (111 . ivy-dispatching-done) (105 . ivy-insert-current) (106 . ivy-yank-word) (114 . ivy-toggle-regexp-quote) (16 . ivy-previous-line-and-call) (14 . ivy-next-line-and-call) (118 . ivy-scroll-down-command) (112 . ivy-previous-history-element) (110 . ivy-next-history-element) (10 . ivy-immediate-done) (13 . ivy-call)) (13 . ivy-done)) nil counsel-M-x-history)
  ivy-read("M-x " [## bookmark-bmenu-file-column rjsx-identifier js2-xml-prop-ref-node-colon-pos--cmacro lm-get-package-name true-expr declaration debugger-previous-window recentf-sort-directories-descending js2-apply-jslint-declaration-externs misearch-unload-function cl-struct-js2-xml-pi-node-tags copy-js2-keyword-node js2-xml-dot-query-node-p bookmark-current-buffer rjsx-print-debug-message starttls-extra-args js2-end-of-defun initprop cl-struct-rjsx-member-tags js2-current-scope js2-class-node-p rjsx-node-closing-tag--cmacro HTMLHRElement rjsx-member-full-name recentf-set-menu-element-value depositAddress recentf-dump-variable js2-xml-dot-query-node-right--cmacro bookmark-menu-bookmark js2-visit-call-node cl-struct-rjsx-wrapped-expr bookmark-set-position bookmark-bmenu-2-window UserModel addr js2--get-name-node recentf-mode-on-hook vc-git--call tree-widget--locate-sub-directory vc-git-extra-fileinfo-p--cmacro js2-mode-reset starterlen rjsx-node-name recentf-elements js2-infix-node-parent--cmacro js2-digit-p js2-class-node-form--cmacro rjsx-mode-map responses ...] :predicate commandp :require-match t :history counsel-M-x-history :action #[257 "\304\305!\203\f�\306\307�!!\210��\307�!\211��\310\307�!\311\")\207" [current-prefix-arg prefix-arg this-command real-this-command featurep smex smex-rank intern command-execute record] 4 "\n\n(fn CMD)"] :sort t :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)
  read-from-minibuffer("M-x " "^" (keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) keymap (3 keymap (19 . ivy-rotate-sort) (1 . ivy-toggle-ignore) (15 . ivy-occur)) (67108903 . ivy-avy) (33554464 . ivy-restrict-to-matches) (15 . hydra-ivy/body) (22 . ivy-scroll-up-command) (prior . ivy-scroll-down-command) (next . ivy-scroll-up-command) (7 . minibuffer-keyboard-quit) (32 . self-insert-command) (18 . ivy-reverse-i-search) (19 . ivy-next-line-or-history) (remap keymap (describe-mode . ivy-help) (kill-ring-save . ivy-kill-ring-save) (kill-line . ivy-kill-line) (scroll-down-command . ivy-scroll-down-command) (scroll-up-command . ivy-scroll-up-command) (end-of-buffer . ivy-end-of-buffer) (beginning-of-buffer . ivy-beginning-of-buffer) (kill-word . ivy-kill-word) (forward-char . ivy-forward-char) (delete-char . ivy-delete-char) (backward-kill-word . ivy-backward-kill-word) (backward-delete-char-untabify . ivy-backward-delete-char) (delete-backward-char . ivy-backward-delete-char) (previous-line . ivy-previous-line) (next-line . ivy-next-line)) (9 . ivy-partial-or-done) (10 . ivy-alt-done) (27 keymap (1 . ivy-read-action) (15 . ivy-dispatching-call) (111 . ivy-dispatching-done) (105 . ivy-insert-current) (106 . ivy-yank-word) (114 . ivy-toggle-regexp-quote) (16 . ivy-previous-line-and-call) (14 . ivy-next-line-and-call) (118 . ivy-scroll-down-command) (112 . ivy-previous-history-element) (110 . ivy-next-history-element) (10 . ivy-immediate-done) (13 . ivy-call)) (13 . ivy-done)) nil counsel-M-x-history)
  ivy-read("M-x " [## bookmark-bmenu-file-column rjsx-identifier js2-xml-prop-ref-node-colon-pos--cmacro lm-get-package-name true-expr declaration debugger-previous-window recentf-sort-directories-descending js2-apply-jslint-declaration-externs misearch-unload-function cl-struct-js2-xml-pi-node-tags copy-js2-keyword-node js2-xml-dot-query-node-p bookmark-current-buffer rjsx-print-debug-message starttls-extra-args js2-end-of-defun initprop cl-struct-rjsx-member-tags js2-current-scope js2-class-node-p rjsx-node-closing-tag--cmacro HTMLHRElement rjsx-member-full-name recentf-set-menu-element-value depositAddress recentf-dump-variable js2-xml-dot-query-node-right--cmacro bookmark-menu-bookmark js2-visit-call-node cl-struct-rjsx-wrapped-expr bookmark-set-position bookmark-bmenu-2-window UserModel addr js2--get-name-node recentf-mode-on-hook vc-git--call tree-widget--locate-sub-directory vc-git-extra-fileinfo-p--cmacro js2-mode-reset starterlen rjsx-node-name recentf-elements js2-infix-node-parent--cmacro js2-digit-p js2-class-node-form--cmacro rjsx-mode-map responses ...] :predicate commandp :require-match t :history counsel-M-x-history :action #[257 "\304\305!\203\f�\306\307�!!\210��\307�!\211��\310\307�!\311\")\207" [current-prefix-arg prefix-arg this-command real-this-command featurep smex smex-rank intern command-execute record] 4 "\n\n(fn CMD)"] :sort t :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)

company-flow-prefix is not a variable, you need the ('s around it when you eval it.

Eval: (company-flow-prefix)
eval: Symbol’s function definition is void: company-flow-prefix

Ah, sorry, it's (company-flow--prefix)

ah sorry if I do it at the end of a line

// @flow
const foo: Array<number> = [3]
foo.

it returns ("" . t)

ok, then that's working. what does M-x company-diag say at that point?

It is now saying:
company--force-sync: Company: backend company-flow async timeout with args (candidates )

this is after minimizing my init.el to just company mode basics

sometimes, what happens is that you have two flow versions and they each stop the other, which means each flow request ends up restarting flow, which is slow. Try manually setting company-flow-executable to the flow executable in your node_modules

ok I sorted out the overlapping flow binaries and now company-diag gives me:

Emacs 25.3.1 (x86_64-apple-darwin13.4.0) of 2017-09-12 on builder10-9.local
Company 0.9.6

company-backends: (company-flow company-web-html company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Used backend: (company-dabbrev-code company-gtags company-etags company-keywords)

Major mode: rjsx-mode
Prefix: ""
Completions:
  "number"
  "Array"
  "const"

I'd expect to see something in prefix. Try:

// @flow
const foo: Array<number> = [3]
foo.pu|

(point at |)

Ok that has completions now

Emacs 25.3.1 (x86_64-apple-darwin13.4.0) of 2017-09-12 on builder10-9.local
Company 0.9.6

company-backends: (company-flow company-web-html company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Used backend: (company-dabbrev-code company-gtags company-etags company-keywords)

Major mode: rjsx-mode
Prefix: ""
Completions:
  "http"
  "type"
  "accepts"
  "description"
  "remoteMethod"
  "User"
  "users"
  "return"
  "account"
  "marginRow"
  "marginRow"
  "kdbMarginRows"
  "where"
  "find"
  "User"
  "await"
  "users"
  "const"
  "account"
  "getLinkedAccountsAsync"
  "await"
  "kdbMarginRows"

so I guess we're good?

Are you sure that's the correct company-diag? It's still showing "" as the prefix. If you're getting flow completions then (push, for example) then yea you're probably good to go, it's just that that company-diag wasn't correct.

yeah I am not getting .push and Used backend is still not showing company-flow

Sorry, I can't tell what's going on remotely and I don't know exactly what your setup is or what you're doing to test it. You're going to have to debug it to find out if company-flow is getting called and what it's doing.

Thanks for all your help on this definitely appreciated, I owe you one. Sorry I messed up that cursor in that example.

Emacs 25.3.1 (x86_64-apple-darwin13.4.0) of 2017-09-12 on builder10-9.local
Company 0.9.6

company-backends: (company-flow company-bbdb company-nxml company-css company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Used backend: (company-dabbrev-code company-gtags company-etags company-keywords)

Major mode: rjsx-mode
Prefix: #("pu" 0 2
  (fontified t font-lock-face js2-object-property-access))

Completions: none

the prefix is updated here. How would you recommend I further debug? I have been disabling chunks of my init.el config turning off things like flycheck and tern. Anything that could conflict. I"m not sure what next steps to take.

As I said above, there's not really much more I can do remotely. Take a look at company-flow--candidates-query. Try adding:

    (message (string-join command " "))

before the set-process-sentinel

That will print the command it's running. In order to use it, you'll need to have the buffer saved as it was and redirect the same file into it, something like this:

/prj/node_modules/flow-bin/flow-osx-v0.65.0/flow autocomplete --quiet /prj/index.js 21 6 < /prj/index.js

You may need to play around with the line number / column number (21 6) in my example to get output, but you should see output if flow is working.

You can also add (message "%S" (process-status process)) to company-flow--handle-signal to see what it's exiting as.

(message (company-flow--get-output process)) in the same place will display the output received from flow.

You may also want to step through that function to see how it works and where it may be going wrong for you. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Edebug.html

Good luck.