Ejemplo n.º 1
0
Archivo: lspc.py Proyecto: danr/libkak
def info_somewhere(msg, pos, where):
    """
    where = cursor | info | docsclient | echo
    """
    if not msg:
        return
    msg = msg.rstrip()
    if where == 'cursor':
        return 'info -placement above -anchor {} {}'.format(
            format_pos(pos),
            utils.single_quoted(utils.join(msg.split('\n')[0:10], '\n')))
    elif where == 'info':
        return 'info ' + utils.single_quoted(
            utils.join(msg.split('\n')[0:20], '\n'))
    elif where == 'docsclient':
        tmp = tempfile.mktemp()
        open(tmp, 'wb').write(utils.encode(msg))
        return """
            eval -no-hooks -try-client %opt[docsclient] %[
              edit! -scratch '*doc*'
              exec \%d|cat<space> {tmp}<ret>
              exec \%|fmt<space> - %val[window_width] <space> -s <ret>
              exec gg
              set buffer filetype rst
              try %[rmhl number_lines]
              %sh[rm {tmp}]
            ]""".format(tmp=tmp)
    elif where == 'echo':
        return 'echo ' + utils.single_quoted(msg.split('\n')[-1])
Ejemplo n.º 2
0
Archivo: lspc.py Proyecto: danr/libkak
 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)))
Ejemplo n.º 3
0
Archivo: lspc.py Proyecto: danr/libkak
 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)
Ejemplo n.º 4
0
Archivo: lspc.py Proyecto: danr/libkak
 def s(opt, chars):
     if chars:
         m = '\nset buffer='
         m += buffile
         m += ' ' + opt
         m += ' ' + utils.single_quoted(''.join(chars))
         return m
     else:
         return ''
Ejemplo n.º 5
0
 def pre(f):
     s = 'def -allow-override -params {params} -docstring {docstring} {name} {hidden}'
     s = s.format(name=r._f_name(),
                  params=params,
                  hidden=(hidden and "-hidden") or '',
                  docstring=utils.single_quoted(
                      utils.deindent(f.__doc__ or '')))
     if enum:
         sh = '\n'.join(
             '[ $kak_token_to_complete -eq {} ] && printf "{}\n"'.
             format(i, '\\n'.join(es)) for i, es in enumerate(enum))
         s += ' -shell-candidates %{' + sh + '} '
     s += ' %('
     s += r_pre(f)
     return s
Ejemplo n.º 6
0
        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)
Ejemplo n.º 7
0
 def hook(self_or_session,
          scope,
          name,
          group=None,
          filter='.*',
          sync_setup=False,
          client=None):
     r = Remote._resolve(self_or_session)
     r.sync_setup = sync_setup
     group = ' -group ' + group if group else ''
     filter = utils.single_quoted(filter)
     cmd = 'hook' + group + ' ' + scope + ' ' + name + ' ' + filter + ' %('
     r_pre = r.pre
     r.pre = lambda f: cmd + r_pre(f)
     r.post = ')' + r.post
     r.ret = lambda: utils.fork(loop=True)(r.listen)
     if client:
         r.onclient(r, client)
     return r
Ejemplo n.º 8
0
Archivo: lspc.py Proyecto: danr/libkak
    def lsp_complete(line, column, timestamp, buffile, completers, result):
        """
        Complete at the main cursor.

        Example to force completion at word begin:

        map global insert <a-c> '<a-;>:eval -draft %(exec b; lsp-complete)<ret>'

        The option lsp_completions is prepended to the completers if missing.
        """
        if not result:
            return
        cs = complete_items(result.get('items', []))
        s = utils.single_quoted(libkak.complete(line, column, timestamp, cs))
        setup = ''
        opt = 'option=lsp_completions'
        if opt not in completers:
            # put ourclient as the first completer if not listed
            setup = 'set buffer=' + buffile + ' completers '
            setup += ':'.join([opt] + completers) + '\n'
        return setup + 'set buffer=' + buffile + ' lsp_completions ' + s
Ejemplo n.º 9
0
 def call_from_python(client, *args):
     escaped = [utils.single_quoted(arg) for arg in args]
     pipe(r.session,
          ' '.join([r._f_name()] + escaped),
          client,
          sync=sync_python_calls)
Ejemplo n.º 10
0
Archivo: lspc.py Proyecto: danr/libkak
 def lsp_execute_command(args, result):
     """Execute custom command"""
     return 'echo ' + utils.single_quoted(str(result))