|
1 |
| -import threading |
| 1 | +import deoplete.logger |
2 | 2 | # Adds a git submodule to the import path
|
3 | 3 | import sys
|
4 | 4 | import os
|
5 | 5 | basedir = os.path.dirname(os.path.realpath(__file__))
|
6 | 6 | sys.path.append(os.path.join(basedir, "../../acid"))
|
7 | 7 | sys.path.append(os.path.join(basedir, "../../../../pythonx/"))
|
8 | 8 |
|
9 |
| -try: |
10 |
| - from acid.nvim import localhost, path_to_ns |
11 |
| - from acid.session import SessionHandler, send |
12 |
| - loaded = True |
13 |
| -except: |
14 |
| - loaded = False |
15 |
| - |
16 |
| -from async_clj_omni.cider import cider_gather # NOQA |
| 9 | +from async_clj_omni.acid import Acid_nrepl, AcidManager |
17 | 10 | from .base import Base # NOQA
|
18 | 11 |
|
19 | 12 |
|
20 |
| -class Acid_nrepl: |
21 |
| - def __init__(self, wc): |
22 |
| - self.wc = wc |
23 |
| - |
24 |
| - def send(self, msg): |
25 |
| - self.wc.send(msg) |
26 |
| - |
27 |
| - def watch(self, name, q, callback): |
28 |
| - self.wc.watch(name, q, callback) |
29 |
| - |
30 |
| - def unwatch(self, name): |
31 |
| - self.wc.unwatch(name) |
32 |
| - |
33 |
| - |
34 | 13 | class Source(Base):
|
35 | 14 | def __init__(self, vim):
|
36 | 15 | Base.__init__(self, vim)
|
37 | 16 | self.name = "acid"
|
38 | 17 | self.mark = "[acid]"
|
39 | 18 | self.filetypes = ['clojure']
|
40 | 19 | self.rank = 200
|
41 |
| - self.__conns = {} |
| 20 | + self._vim = vim |
| 21 | + self._AcidManager = AcidManager(deoplete.logger.getLogger('acid_cider_completion_manager'), vim) |
42 | 22 |
|
43 | 23 | def on_init(self, context):
|
44 |
| - if loaded: |
45 |
| - self.acid_sessions = SessionHandler() |
46 |
| - else: |
47 |
| - self.debug('echomsg "Acid.nvim not found. Please install it."') |
48 |
| - self.sessions = {} |
49 |
| - |
50 |
| - def get_wc(self, url): |
51 |
| - return self.acid_sessions.get_or_create(url) |
52 |
| - |
53 |
| - def get_session(self, url, wc): |
54 |
| - if url in self.sessions: |
55 |
| - return self.sessions[url] |
56 |
| - |
57 |
| - session_event = threading.Event() |
58 |
| - |
59 |
| - def clone_handler(msg, wc, key): |
60 |
| - wc.unwatch(key) |
61 |
| - self.sessions[url] = msg['new-session'] |
62 |
| - session_event.set() |
63 |
| - |
64 |
| - wc.watch('dyn-session', {'new-session': None}, clone_handler) |
65 |
| - wc.send({'op': 'clone'}) |
66 |
| - session_event.wait(0.5) |
67 |
| - |
68 |
| - return self.sessions[url] |
| 24 | + self._AcidManager.on_init() |
69 | 25 |
|
70 | 26 | def gather_candidates(self, context):
|
71 |
| - if not loaded: |
72 |
| - return [] |
73 |
| - |
74 |
| - address = localhost(self.vim) |
75 |
| - if address is None: |
76 |
| - return [] |
77 |
| - url = "nrepl://{}:{}".format(*address) |
78 |
| - wc = self.get_wc(url) |
79 |
| - session = self.get_session(url, wc) |
80 |
| - ns = path_to_ns(self.vim) |
81 |
| - |
82 |
| - def global_watch(cmsg, cwc, ckey): |
83 |
| - self.debug("Received message for {}".format(url)) |
84 |
| - self.debug(cmsg) |
85 |
| - |
86 |
| - wc.watch('global_watch', {}, global_watch) |
87 |
| - |
88 |
| - return cider_gather(self, |
89 |
| - Acid_nrepl(wc), |
90 |
| - context["complete_str"], |
91 |
| - session, |
92 |
| - ns) |
| 27 | + return self._AcidManager.gather_candidates(context["complete_str"]) |
0 commit comments