Fork me on GitHub
#vim
<
2019-07-18
>
dominicm10:07:33

mylanguage#get_async_completions is the fireplace part of the code in their example. Their example is how to integrate mylanguage#get_async_completions with asyncomplete (e.g. the kind of thing I do in async_clj_omni)

dominicm10:07:14

@tpope does the cider-nrepl completion api even stream the results? It's been a while since I looked, but I don't think it does.

tpope13:07:00

it doesn't 😞

tpope14:07:03

and i just think it's weird that asyncomplete would be like "just write a generic async completion function" and then make you jump through a bunch of hoops to use it. this could be a 1 liner!

tpope22:07:11

@dominicm try fireplace#omnicomplete(function('callback'), fireplace#omnicomplete(1, '')) on the asyncomplete branch

👀 4
dominicm07:07:25

It's kinda frustrating that s:get_complete_context cannot be trivially rewritten to use a specified location rather than the cursor. e.g. for command line completion. It's only minor I guess, but it would be nice.

dominicm07:07:19

(more of a vim complaint hat a fireplace one)

dominicm08:07:49

Ctrl-X Ctrl-O seems to be giving me a E745: Using a List as a Number and not filtering the results.

dominicm08:07:29

Your example never gives me any hits, but fireplace#omnicomplete(function('callback'), 'yad') does (filtering for "yad" typed in)

dominicm08:07:26

anyway, this is working an absolute treat with asyncomplete. I'll give it a test in the slow env.

dominicm13:07:08

I've hooked this up to a local change to async_clj_omni, and with asyncomplete this is really snappy, great! (and not much code either!). I've introduced a (Thread/sleep 3000) into cider-nrepl to observe the effects of delays on locking up:

diff --git a/project.clj b/project.clj
index 079a19d..2487431 100644
--- a/project.clj
+++ b/project.clj
@@ -1,4 +1,4 @@
-(defproject cider/cider-nrepl "0.21.1"
+(defproject cider/cider-nrepl "0.21.1-SLOWMO"
   :description "nREPL middlewares for CIDER"
   :url ""
   :license {:name "Eclipse Public License"
diff --git a/src/cider/nrepl/middleware/complete.clj b/src/cider/nrepl/middleware/complete.clj
index 2a9e733..5a5d8e7 100644
--- a/src/cider/nrepl/middleware/complete.clj
+++ b/src/cider/nrepl/middleware/complete.clj
@@ -25,6 +25,7 @@
     (jvm-complete/documentation (str symbol) (u/as-sym ns))))
 
 (defn complete-reply [msg]
+  (Thread/sleep 3000)
   {:completions (complete msg)})
 
 (defn doc-reply
With this, I've observed that vim does lock up when using mucomplete. If I use Ctrl-X Ctrl-O after disabling mucomplete and continue typing, it also locks up for 3s. So I feel confident that the omnicomplete isn't async.

dominicm13:07:38

I think bfredl mentioned he'd introduced an asyncish implementation in his plugins, probably for julia

tpope14:07:13

oh yeah, I mis-remembered what fireplace#omnicomplete(1, '') did. you'll need to use that integer to extract the keyword from the current line

tpope14:07:16

looks like getline('.')[fireplace#omnicomplete(1, '') : col('.')] will do it

dominicm21:07:16

regarding the asyncish implementation by bredl: https://github.com/bfredl/nvim-ipy/blob/14d2399ead1d7cf9e8aa6cdbe6c7bf241be76026/rplugin/python3/nvim_ipy/__init__.py#L346-L357 he has a custom binding which he binds to C-f in his special repl buffer.

dominicm21:07:32

this just calls complete() later. So it's not magical 🙂

dominicm06:07:03

Putting a 3s delay into complete has some really interesting effects on clients.

dominicm06:07:16

I have working local copies of async_clj_omni with ncm2 now also. ncm2 is a fairly major async completion plugin, so that should cover most things for most people.

tpope16:07:35

using that asyncomplete branch?

tpope16:07:55

i can ship that branch if you think it's ready

dominicm19:07:14

I'm still getting issues using Ctrl-X Ctrl-O with that branch

tpope21:07:22

if you mean it was happening on that branch just with the built-in completion, possibly, but the latest rebase i pushed up today is working fine for me

dominicm07:07:28

I'll give it another go. But yeah, I meant with built-in omnicompletion. Worked great for me 😛

dominicm07:07:58

As an aside, you can definitely remove the async code intended for use from Ctrl-X Ctrl-O.

dominicm07:07:11

Hmm, in neovim I'm still not having success with Ctrl-X Ctrl-O

dominicm07:07:15

ah, nvm. Looks like it's something on neovim master, so unrelated. Great 🙂

dominicm07:07:51

it behaves kinda strange on neovim 0.3.8 too though. Very odd :thinking_face:

tpope15:07:31

seems fine on my old 0.3.8 install

tpope15:07:40

does it also behave strange on master? afaik this branch only adds an async api, it shouldn't affect ctrl-x ctrl-o

dominicm19:07:34

Maybe it's something environmental. If you have it fine on 0.3.8 then it should be okay 🙂

tpope02:07:23

just shipped it, looking forward to seeing what you rig up

dominicm07:07:07

will merge my equivalent branch to master 🙂

tpope17:07:45

i'm open to adding this to fireplace proper once you're confident it's stable

tpope17:07:45

https://github.com/clojure-vim/async-clj-omni/blob/master/autoload/async_clj_omni/sources.vim#L2-L8 stuff like this should be replaced with a call to fireplace#omnicomplete(1, '') to get the column fireplace thinks it should start in

dominicm20:07:22

aren't those essentially equivalent?

tpope20:07:20

fireplace uses \k\+ which is presumably the same with the default value of iskeyword

tpope20:07:11

but it's not a guarantee. technically it should include ' in all but the first position. if i fix that your code will break

tpope20:07:16

i guess it depends on the interface you have to implement though. the omni function is looking at the current line while it looks like asyncomplete passes in a typed field?

dominicm06:07:26

Yeah, assuming that the regexs match the same thing then they are equivalent. Yeah, asyncomplete etc. provides a 'typed' field, and pretty much all the completion plugins do. coc.nvim seems to use \k\+ as an 'input' field. I need to dig deeper to figure out if those are conveniences or if they're key to how the plugins work. At the moment the only risk is that you will occasionally get/not get certain locals so I'm not too worried about the fireplace side. I am less worried about it because I understand it. coc.nvim is 40k lines of typescript, much harder to understand.

tpope21:07:20

holy cow, latest neovim passes '1' rather than 1 as a:findstart

dominicm07:07:43

ah, that makes sense 😂

dominicm07:07:53

but yeah, that was my issue.

dominicm07:07:14

did you open an issue on neovim?

tpope14:07:48

no, too much else on my plate