示例#1
0
 def prepare_payload(self, path):
     current = current_file(self.nvim)
     root = current_path(self.nvim)
     new = path.replace('-', '_').split('.')
     new[-1] = '{}.{}'.format(new[-1], current.split('.')[-1])
     final = os.path.join(root, 'src', *new)
     return {"old-path": current, "new-path": final}
示例#2
0
    def prepare_payload(self):
        src = src_paths(self.nvim)
        test = test_paths(self.nvim)
        path = current_file(self.nvim)
        root_path = current_path(self.nvim)
        rel_path = os.path.relpath(path, start=root_path).split('/')
        open_with = self.nvim.vars.get(
            'acid_open_alternate_file_with',
            self.nvim.vars.get('acid_open_new_file_with', 'edit')
        )

        if rel_path[0] in src:
            log_debug("Current file is a 'src', changing to 'test'")
            alt_path = to_alt_path(
                rel_path, test, root_path,
                lambda f: '{}_test'.format(f),
                'test'
            )
        else:
            log_debug("Current file is a 'test', changing to 'src'")
            alt_path = to_alt_path(
                rel_path, src, root_path,
                lambda f: f.split('_')[0],
                'src'
            )

        if os.path.exists(alt_path):
            self.nvim.command('silent {} {}'.format(open_with, alt_path))
        else:
            ns = path_to_ns(alt_path, test | src)
            self.nvim.command('AcidNewFile {}'.format(ns))


        return None
示例#3
0
 def transform(self, msg):
     return {
         'op': 'find-symbol',
         'dir': current_path(self.nvim),
         'file': current_file(self.nvim),
         'ns': msg['ns'],
         'name': msg['name'],
         'line': msg.get('line', 1),
         'column': msg.get('column', 1),
         'serialization-format': 'bencode'
     }
示例#4
0
    def acid_command(self, args):
        cmd, *args = args
        log_info(r"Received args for command {}: {}", cmd, args)
        url = formatted_localhost_address(self.nvim)

        if url is None:
            path = current_path(self.nvim)
            echo(self.nvim, "No REPL open")
            log_info("No repl open on path {}".format(path))
            return

        command = self.extensions['commands'].get(cmd.strip())
        command.call(self, self.context(), *args)
示例#5
0
文件: new.py 项目: NRoos/acid.nvim
    def prepare_payload(self, ns):
        fname = "{}.clj".format(ns_to_path(ns))
        base = 'test' if ns.endswith('-test') else 'src'
        open_with = self.nvim.vars.get('acid_open_new_file_with', 'edit')
        path = os.path.join(current_path(self.nvim), base, fname)
        directory = os.path.dirname(path)
        if not os.path.exists(directory):
            os.makedirs(directory)

        with open(path, 'w') as fpath:
            fpath.write('(ns {})'.format(ns))

        self.nvim.command('silent {} {}'.format(open_with, path))

        # Does not interact with nrepl
        return None
示例#6
0
    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!')