def cquery_publishSemanticHighlighting(filetype, params): print("published semantic highlighting") buffile = utils.uri_to_file(params['uri']) clientp = client.client_editing.get((filetype, buffile)) if not clientp: print("No client found for {} {}".format(filetype, buffile)) print("client_editing: {}".format(client.client_editing)) return r = libkak.Remote.onclient(client.session, clientp, sync=False) @r def _(timestamp, pipe): flags = [str(timestamp)] for hl in params['symbols']: face = face_for_symbol(hl) if face is None: print("No face found for {}".format(hl)) continue for range in hl['ranges']: (line0, col0), (line1, col1) = utils.range(range) flags.append("{}.{},{}.{}|{}".format( line0, col0, line1, col1, face)) # todo:Set for the other buffers too (but they need to be opened) msg = 'try %{add-highlighter buffer/ ranges cquery_semhl}\n' msg += 'set buffer=' + buffile + ' cquery_semhl ' msg += utils.single_quoted(':'.join(flags)) print(msg) pipe(msg)
def apply_textdocumentedit(edit): filename = utils.uri_to_file(edit['textDocument']['uri']) if filename: return 'edit {}; {}; write'.format( filename, '; '.join(apply_textedit(textedit) for textedit in edit['edits'])) else: return 'echo -markup {red}Cannot open {}'.format(filename)
def window_logMessage(filetype, params): libkak._debug('Log message', params) if 'message' in params: libkak._debug('Adding debug print', params) libkak.pipe(client.session, 'echo -debug ' + utils.single_quote_escape(params['message'])) if 'uri' not in params: return buffile = utils.uri_to_file(params['uri']) clientp = client.client_editing.get((filetype, buffile)) if not clientp: return libkak.pipe(client.session, 'echo ' + utils.single_quote_escape(params['message']), client=clientp)
def textDocument_publishDiagnostics(filetype, params): buffile = utils.uri_to_file(params['uri']) clientp = client.client_editing.get((filetype, buffile)) if not clientp: return r = libkak.Remote.onclient(client.session, clientp, sync=False) r.arg_config['disabled'] = ('kak_opt_lsp_' + filetype + '_disabled_diagnostics', libkak.Args.string) @r def _(timestamp, pipe, disabled): client.diagnostics[filetype, buffile] = defaultdict(list) client.diagnostics[filetype, buffile]['timestamp'] = timestamp flags = [str(timestamp), '1| '] from_severity = [ u'', u'{red}\u2022 ', u'{yellow}\u2022 ', u'{blue}\u2022 ', u'{green}\u2022 ' ] for diag in params['diagnostics']: if disabled and re.match(disabled, diag['message']): continue (line0, col0), end = utils.range(diag['range']) flags.append( str(line0) + '|' + from_severity[diag.get('severity', 1)]) client.diagnostics[filetype, buffile][line0].append({ 'col': col0, 'end': end, 'message': diag['message'] }) # todo: Set for the other buffers too (but they need to be opened) msg = 'try %{add-highlighter window/ flag_lines default lsp_flags}\n' msg += 'set buffer=' + buffile + ' lsp_flags ' msg += utils.single_quoted(':'.join(flags)) pipe(msg)
def options(): for uri, pos in six.iteritems(m): loc = utils.drop_prefix(utils.uri_to_file(uri), pwd).lstrip('/') or uri entry = u'{} ({} references)'.format(loc, len(pos)) yield entry, edit_uri_select(uri, pos)
def edit_uri_select(uri, positions): filename = utils.uri_to_file(uri) if filename: return 'edit {}; {}'.format(filename, libkak.select(positions)) else: return 'echo -markup {red}Cannot open {}'.format(uri)