def k(d): try: d['d'] = d d['force'] = force # print('handler calls sync', pprint.pformat(d)) msg = utils.safe_kwcall(sync, d) # print('sync called', status, result, pprint.pformat(d)) if 'result' in msg: d['result'] = msg['result'] print('Calling', f.__name__, pprint.pformat(d)[:500]) msg = utils.safe_kwcall(f, d) if msg: print('Answer from', f.__name__, ':', msg) d['pipe'](msg) else: print('Error: ', msg) d['pipe'](''' echo -debug When handling {}: echo -debug {} echo -markup "{{red}}Error from language server (see *debug* buffer)" '''.format( utils.single_quoted(f.__name__), utils.single_quoted(pprint.pformat(msg)))) except: import traceback msg = f.__name__ + ' ' + traceback.format_exc() print(msg) d['pipe'](''' echo -debug When handling {}: echo -debug {} echo -markup "{{red}}Error from language client (see *debug* buffer)" '''.format(utils.single_quoted(f.__name__), utils.single_quoted(msg)))
def sync(d, line, column, buffile, filetype, timestamp, pwd, cmd, client, reply): d['pos'] = {'line': line - 1, 'character': column - 1} d['uri'] = uri = 'file://' + six.moves.urllib.parse.quote(buffile) if cmd in self.langservers: print(filetype + ' already spawned') else: push = self.push_message(filetype) self.langservers[cmd] = Langserver(pwd, cmd, push, self.mock) if not client: print("Client was empty when syncing") d['langserver'] = langserver = self.langservers[cmd] old_timestamp = self.timestamps.get((filetype, buffile)) if old_timestamp == timestamp and not d['force']: print('no need to send update') reply('') else: self.timestamps[(filetype, buffile)] = timestamp with tempfile.NamedTemporaryFile() as tmp: write = "eval -no-hooks 'write {}'".format(tmp.name) libkak.pipe(reply, write, client=client, sync=True) print('finished writing to tempfile') contents = open(tmp.name, 'r').read() self.client_editing[filetype, buffile] = client if old_timestamp is None: langserver.call('textDocument/didOpen', { 'textDocument': { 'uri': uri, 'version': timestamp, 'languageId': filetype, 'text': contents } })() else: langserver.call('textDocument/didChange', { 'textDocument': { 'uri': uri, 'version': timestamp }, 'contentChanges': [{'text': contents}] })() print('sync: waiting for didChange reply...') print('sync: got didChange reply...') if method: print(method, 'calling langserver') q = Queue() langserver.call(method, utils.safe_kwcall( make_params, d))(q.put) return q.get() else: return {'result': None}
def listen(self): _debug(self.f.__name__ + ' ' + self.fifo + ' waiting for call...') with open(self.fifo, 'r') as fp: line = utils.decode(fp.readline()).rstrip() if line == '_q': self.fifo_cleanup() _debug(self.fifo, 'demands quit') raise RuntimeError('fifo demands quit') _debug(self.f.__name__ + ' ' + self.fifo + ' replied:' + repr(line)) r = self.parse(line) try: def _pipe(msg, sync=False): return pipe(self.session, msg, r['client'], sync) r['pipe'] = _pipe d = {} if 'reply_fifo' in r: d['reply_calls'] = 0 def reply(msg): d['reply_calls'] += 1 with open(r['reply_fifo'], 'w') as fp: fp.write(msg) r['reply'] = reply result = utils.safe_kwcall(self.f, r) if self.puns else self.f(r) if 'reply_fifo' in r: if d['reply_calls'] != 1: print('!!! [ERROR] Must make exactly 1 call to reply, ' + self.f + ' ' + self.r + ' made ' + d['reply_calls'], file=sys.stderr) return result except TypeError as e: print(str(e), file=sys.stderr)