def on_handle(self, msg, *_): if 'file' in msg: f = find_file_in_path(self.nvim, msg) if f is None: warning(self.nvim, "File not found") return c = msg.get('column', 1) l = msg.get('line', 1) current_scrolloff = self.nvim.options['scrolloff'] self.nvim.options['scrolloff'] = 999 try: if self.nvim.funcs.expand('%').endswith(f): self.nvim.funcs.cursor(l, c) else: self.nvim.command("edit +{} {}".format(l, f)) except Exception as e: error(self.nvim, "Error while navigating: {}".format(str(e))) finally: self.nvim.options['scrolloff'] = current_scrolloff elif 'no-info' in msg['status']: warning(self.nvim, 'No information found for symbol')
def on_handle(self, msg, *_): if 'no-info' in msg.get('status', []): warning(self.nvim, "No information for symbol") return try: lines = self.transform(msg) except Exception as e: warning(self.nvim, "Couldn't transform msg into doc.") log_error(e) return no_doc_buffer = self.doc_buf_nr is None buf_win_nr = self.nvim.funcs.bufwinnr(self.doc_buf_nr) doc_len = len(lines) if no_doc_buffer or buf_win_nr == -1: cmds = ['file acid://doc', 'wincmd p'] self.doc_buf_nr = build_window( self.nvim, close=1, commands=cmds, throwaway=1, orientation="leftabove {} split".format(doc_len)) else: self.nvim.command('{} wincmd w | resize {} | wincmd p'.format( buf_win_nr, doc_len)) log_debug(lines) self.nvim.buffers[self.doc_buf_nr][:] = lines
def prepare_payload(self, *args): if len(args) == 0: ns = path_to_ns(self.nvim) if ns is None: warning( "Unable to require: couldn't find namespace from path.") return None else: ns = " ".join(args) return {"code": "(require '[{}] :reload)".format(ns)}
def acid_eval(self, data): payload = data[0] handler = len(data) > 1 and data[1] or 'MetaRepl' config = len(data) > 2 and data[2] or None handler = self.get_handler(handler) if handler is None: warning(self.nvim, "Handler not found") return context = self.context() if config is not None: handler = handler.configure(config, **context) else: handler = handler.configure(**context) self.command(payload, [handler])
def prepare_payload(self, ns): files = list(list_clj_files(self.nvim)) path = '{}.clj'.format(ns_to_path(ns)) log.log_debug('Found all this clojure files: {}', files) log.log_debug('Attempting to match against {}', path) match = list(filter(lambda k: k.endswith(path), files)) if any(match): fpath, *_ = match fpath = os.path.relpath(fpath, start=current_path(self.nvim)) with open(fpath, 'r') as source: data = '\n'.join(source.readlines()) return { 'file': data, 'file-path': fpath, 'file-name': os.path.basename(fpath) } else: log.warning(self.nvim, 'no file found!')
def acid_eval(self, data): payload = data[0] handler = len(data) > 1 and data[1] or 'MetaRepl' config = len(data) > 2 and data[2] or None url = len(data) > 3 and (format_addr(*data[3]) or formatted_localhost_address(self.nvim)) handler = self.get_handler(handler) if handler is None: warning(self.nvim, "Handler not found") return context = self.context() if config is not None: handler = handler.configure(config, **context) else: handler = handler.configure(**context) self.command(payload, [handler], url)
def on_handle(self, msg, *_): if 'err' in msg: warning(self.nvim, msg['err'])
def on_handle(self, msg, *_): if not 'no-info' in msg.get('status', []): name = msg['name'] ns = msg.get('ns', '') arglist = msg.get('arglists-str', []) doc = msg.get('doc', '') javadoc = msg.get('javadoc', '') added = msg.get('added', '') super_ = msg.get('super', '') modifiers = msg.get('modifiers', []) see_also = msg.get('see-also', []) interfaces = msg.get('interfaces', []) if arglist: fn_calls = ["({}{})".format(name, " {}".format(i) if i else "") for i in arglist[2:-2].split('] [')] else: fn_calls = [name] if see_also: see_also = ["https://clojuredocs.org/{}".format(i) for i in see_also] docl = [i for i in [ " ".join(fn_calls), ns, modifiers, " ", javadoc, *doc.split('\n'), " ", added and "Since version {}".format(added), interfaces and "Implements: {}".format( ",".join(interfaces) ) or "", super_ and "Extends: {}".format(super_) or "", see_also and "See also:" or "", *see_also, ] if i ] no_doc_buffer = self.doc_buf_nr is None buf_win_nr = self.nvim.funcs.bufwinnr(self.doc_buf_nr) doc_len = len(docl) if no_doc_buffer or buf_win_nr == -1: cmds = ['file acid://doc', 'wincmd p', ] self.doc_buf_nr = build_window( self.nvim, close=1, commands=cmds, throwaway=1, orientation="leftabove {} split".format(doc_len) ) else: self.nvim.command('{} wincmd w | resize {} | wincmd p'.format( buf_win_nr, doc_len )) info(self.nvim, "Documentation for {}/{}".format(ns, name)) log_debug(docl) exec_cmd = "bd {} | au! AcidDoc".format(self.doc_buf_nr) self.nvim.buffers[self.doc_buf_nr][:] = docl self.nvim.command('augroup AcidDoc') self.nvim.command('au!') self.nvim.command( 'au CursorMoved * exec "{}"'.format(exec_cmd)) self.nvim.command('augroup END') else: warning(self.nvim, "No information for symbol")