def _recv(): while True: try: ln = gs.mg9_recv_q.get() try: ln = ln.strip() if ln: r, _ = gs.json_decode(ln, {}) token = r.get("token", "") tag = r.get("tag", "") k = REQUEST_PREFIX + token req = gs.attr(k, {}) gs.del_attr(k) if req and req.f: if tag != TAG: gs.notice( DOMAIN, "\n".join( [ "GoSublime/MarGo appears to be out-of-sync.", "Maybe restart Sublime Text.", "Received tag `%s', expected tag `%s'. " % (tag, TAG), ] ), ) err = r.get("error", "") gs.debug( DOMAIN, "margo response: %s" % { "method": req.method, "tag": tag, "token": token, "dur": "%0.3fs" % (time.time() - req.tm), "err": err, "size": "%0.1fK" % (len(ln) / 1024.0), }, ) dat = expand_jdata(r.get("data", {})) try: keep = req.f(dat, err) is True if keep: req.tm = time.time() gs.set_attr(k, req) except Exception: gs.error_traceback(DOMAIN) else: gs.debug(DOMAIN, "Ignoring margo: token: %s" % token) except Exception: gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def run(self, edit, pos, content, added_path=''): pos = int(pos) # un-f*****g-believable view = self.view dirty, err = gspatch.merge(view, pos, content, edit) if err: gs.notice_undo(DOMAIN, err, view, dirty) elif dirty: k = 'last_import_path.%s' % gs.view_fn(self.view) if added_path: gs.set_attr(k, added_path) else: gs.del_attr(k)
def _recv(): while True: try: ln = gs.mg9_recv_q.get() try: ln = ln.strip() if ln: r, _ = gs.json_decode(ln, {}) token = r.get('token', '') tag = r.get('tag', '') k = REQUEST_PREFIX + token req = gs.attr(k, {}) gs.del_attr(k) if req and req.f: if tag != TAG: gs.notice( DOMAIN, "\n".join([ "GoSublime/MarGo appears to be out-of-sync.", "Maybe restart Sublime Text.", "Received tag `%s', expected tag `%s'. " % (tag, TAG), ])) err = r.get('error', '') ev.debug( DOMAIN, "margo response: %s" % { 'method': req.method, 'tag': tag, 'token': token, 'dur': '%0.3fs' % (time.time() - req.tm), 'err': err, 'size': '%0.1fK' % (len(ln) / 1024.0), }) dat = expand_jdata(r.get('data', {})) try: keep = req.f(dat, err) is True if keep: req.tm = time.time() gs.set_attr(k, req) except Exception: gs.error_traceback(DOMAIN) else: ev.debug(DOMAIN, 'Ignoring margo: token: %s' % token) except Exception: gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def run(self, edit, pos, content, added_path=''): pos = int(pos) # un-f*****g-believable view = self.view dirty, err = gspatch.merge(view, pos, content, edit) if err: ui.error(DOMAIN, err) if dirty: sublime.set_timeout(lambda: view.run_command('undo'), 0) elif dirty: k = 'last_import_path.%s' % vu.V(view).vfn() if added_path: gs.set_attr(k, added_path) else: gs.del_attr(k)
def _recv(): while True: try: ln = gs.mg9_recv_q.get() try: ln = ln.strip() if ln: r, _ = gs.json_decode(ln, {}) token = r.get('token', '') tag = r.get('tag', '') k = REQUEST_PREFIX+token req = gs.attr(k, {}) gs.del_attr(k) if req and req.f: if tag != TAG: gs.notice(DOMAIN, "\n".join([ "GoSublime/MarGo appears to be out-of-sync.", "Maybe restart Sublime Text.", "Received tag `%s', expected tag `%s'. " % (tag, TAG), ])) err = r.get('error', '') ev.debug(DOMAIN, { '_mode': 'response', 'method': req.method, 'tag': tag, 'token': token, 'dur': '%0.3fs' % (time.time() - req.tm), 'err': err, 'size': '%0.1fK' % (len(ln)/1024.0), }) dat = expand_jdata(r.get('data', {})) try: keep = req.f(dat, err) is True if keep: req.tm = time.time() gs.set_attr(k, req) except Exception: gs.error_traceback(DOMAIN) else: ev.debug(DOMAIN, 'Ignoring margo: token: %s' % token) except Exception: gs.print_traceback() except Exception: gs.print_traceback() break
def killSrv(): p = gs.del_attr(PROC_ATTR_NAME) if p: try: p.stdout.close() except Exception: pass try: p.stdin.close() except Exception: pass
def killSrv(): """Kills server on process exit, registered by 'gs_init'. """ p = gs.del_attr(PROC_ATTR_NAME) if p: try: p.stdout.close() except Exception: pass try: p.stdin.close() except Exception: pass
def _recv(): while True: try: ln = gs.mg9_recv_q.get() try: ln = ln.strip() if ln: r, _ = gs.json_decode(ln, {}) token = r.get('token', '') k = REQUEST_PREFIX+token req = gs.attr(k) gs.del_attr(k) if req and req.f: gs.debug(DOMAIN, "margo response: method: %s, token: %s, dur: %0.3fs, err: `%s'" % ( req.method, req.token, (time.time() - req.tm), r.get('error', ''), )) dat = expand_jdata(r.get('data', {})) err = r.get('error', '') try: keep = req.f(dat, err) is not True if keep: req.tm = time.time() gs.set_attr(k, req) except Exception: gs.error_traceback(DOMAIN) else: gs.debug(DOMAIN, 'Ignoring margo: token: %s' % token) except Exception: gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def _recv(): """Polls the mg9_recv_q queue parsing responses. """ # TODO: REFACTOR. while True: try: ln = gs.mg9_recv_q.get() try: ln = ln.strip() if ln: r, _ = gs.json_decode(ln, {}) token = r.get("token", "") tag = r.get("tag", "") k = REQUEST_PREFIX + token # TODO: try req = gs.del_attr(k) req = gs.attr(k, {}) gs.del_attr(k) if req and req.f: if tag != TAG: gs.notice( DOMAIN, "\n".join( [ "GoSublime/MarGo appears to be out-of-sync.", "Maybe restart Sublime Text.", "Received tag `%s', expected tag `%s'. " % (tag, TAG), ] ), ) err = r.get("error", "") # TODO: Check if debug is enabled (len()). ev.debug( DOMAIN, "margo response: %s" % { "method": req.method, "tag": tag, "token": token, "dur": "%0.3fs" % (time.time() - req.tm), "err": err, "size": "%0.1fK" % (len(ln) / 1024.0), }, ) # CEV: req.f is the callback 'cb' set in _send(). # dat = expand_jdata(r.get("data", {})) try: # Add request back to the attr dict. # # TODO: Document, which calls keep the request. keep = req.f(dat, err) is True if keep: req.tm = time.time() gs.set_attr(k, req) except Exception: gs.error_traceback(DOMAIN) else: ev.debug(DOMAIN, "Ignoring margo: token: %s" % token) except Exception: gs.println(gs.traceback()) except Exception: gs.println(gs.traceback()) break
def cb(): gs.del_attr(mg9._inst_name()) out = mg9.install('', True, True) gs.notify(DOMAIN, 'MarGo re-installed done') push_output(view, rkey, out)