def gather_candidates(self, context: UserContext) -> Candidates: result = parse_jump_line( self.vim.call('getcwd'), context['__line']) try: if not result or not Path(result[0]).is_file(): result = parse_jump_line( self.vim.call('getcwd'), context['__cfile']) if result and Path(result[0]).is_file(): return [{ 'word': '{}: {}{}: {}'.format( result[0], result[1], (':' + result[2] if result[2] != '0' else ''), result[3]), 'action__path': result[0], 'action__line': result[1], 'action__col': result[2], }] cfile = context['__cfile'] cpath = Path(abspath(self.vim, cfile)) if match('[./]+$', cfile): return [] if cpath.exists() and cpath.is_file(): return [{'word': cfile, 'action__path': abspath(self.vim, cfile)}] if _checkhost(cfile) or match( r'https?://(127\.0\.0\.1|localhost)[:/]', cfile): return [{'word': cfile, 'action__path': cfile}] except OSError: pass return []
def test_parse_jump_line(): assert util.parse_jump_line( '', 'file:text') == [] assert util.parse_jump_line( '', 'file:3:text') == ['file', '3', '0', 'text'] assert util.parse_jump_line( '', 'file:3:4:text') == ['file', '3', '4', 'text']
def test_parse_jump_line(): assert util.parse_jump_line( '', 'file:text') == [] assert util.parse_jump_line( '', 'file:3:text') == ['file', '3', '0', 'text'] assert util.parse_jump_line( '', 'file:3:4:text') == ['file', '3', '4', 'text'] assert util.parse_jump_line( '', 'C:/file:3:4:text') == ['C:/file', '3', '4', 'text']
def __async_gather_candidates(self, context, timeout): outs, errs = self.__proc.communicate(timeout=timeout) context['is_async'] = not self.__proc.eof() candidates = [] for line in outs: result = parse_jump_line(context['__directory'], line) if result: candidates.append({ 'word': '{0}:{1}{2}: {3}'.format( os.path.relpath(result[0], start=context['__directory']), result[1], (':' + result[2] if result[2] != '0' else ''), result[3]), 'action__path': result[0], 'action__line': result[1], 'action__col': result[2], }) return candidates
def __async_gather_candidates(self, context, timeout): outs, errs = context['__proc'].communicate(timeout=timeout) context['is_async'] = not context['__proc'].eof() if context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line('', line) if not result: continue if context['__paths']: if len(context['__paths']) == 1: candidate = _candidate( result, os.path.relpath(result[0], start=context['__paths'][0])) else: candidate = _candidate(result, result[0]) else: candidate = _candidate( result, os.path.relpath(result[0], start=context['path'])) candidates.append(candidate) return candidates
def _async_gather_candidates(self, context: UserContext, timeout: float) -> Candidates: outs, errs = context['__proc'].communicate(timeout=timeout) if errs: self.error_message(context, errs) context['is_async'] = (context['__proc'] and not context['__proc'].eof()) if context['__proc'] and context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line(context['path'], line) if not result: continue path = result[0] for searching_path in context['__paths']: if path == searching_path: continue if path.startswith(context['path'] + sep): # relative to context path path = str(Path(path).relative_to(context['path'])) break elif path.startswith(searching_path + sep): # relative to parent searching_path path = str( Path(path).relative_to(Path(searching_path).parent)) break truncated = truncate(self.vim, path, self.vars['max_path_length']) candidates.append(_candidate(result, truncated)) return candidates
def __async_gather_candidates(self, context, timeout): outs, errs = context["__proc"].communicate(timeout=timeout) context["is_async"] = not context["__proc"].eof() if context["__proc"].eof(): context["__proc"] = None candidates = [] for line in outs: if context["__paths"]: if len(context["__paths"]) == 1: result = util.parse_jump_line(context["__paths"][0], line) if result: candidates.append(_candidate(result, os.path.relpath(result[0], start=context["__paths"][0]))) else: result = util.parse_jump_line("", line) if result: candidates.append(_candidate(result, result[0])) else: result = util.parse_jump_line(context["path"], line) if result: candidates.append(_candidate(result, os.path.relpath(result[0], start=context["path"]))) return candidates
def __async_gather_candidates(self, context, timeout): outs, errs = context['__proc'].communicate(timeout=timeout) context['is_async'] = not context['__proc'].eof() if context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line(context['path'], line) if not result: continue path = relpath(result[0], start=context['path']) candidates.append(_candidate(result, path)) return candidates
def _async_gather_candidates(self, context, timeout): outs, errs = context['__proc'].communicate(timeout=timeout) if errs: self.error_message(context, errs) context['is_async'] = not context['__proc'].eof() if context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line(context['path'], line) if not result: continue path = relpath(result[0], start=context['path']) candidates.append(_candidate(result, path)) return candidates
def _async_gather_candidates(self, context: UserContext, timeout: float) -> Candidates: outs, errs = context['__proc'].communicate(timeout=timeout) if errs: self.error_message(context, errs) context['is_async'] = not context['__proc'].eof() if context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line(context['path'], line) if not result: continue candidates.append( _candidate(result, context['__bufnr'], context['__fmt'])) return candidates
def _async_gather_candidates(self, context: UserContext, timeout: float) -> Candidates: outs, errs = context['__proc'].communicate(timeout=timeout) if errs: self.error_message(context, errs) context['is_async'] = (context['__proc'] and not context['__proc'].eof()) if context['__proc'] and context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line(context['path'], line) if not result: continue path = truncate(self.vim, relpath(result[0], start=context['path']), self.vars['max_path_length']) candidates.append(_candidate(result, path)) return candidates
def gather_candidates(self, context): cfile = context['__cfile'] if cfile == '.' or cfile == '..': return [] if os.path.exists(cfile): return [{'word': cfile, 'action__path': os.path.abspath(cfile)}] if checkhost(cfile): return [{'word': cfile, 'action__path': cfile}] result = parse_jump_line( self.vim.call('getcwd'), context['__line']) return [{ 'word': '{0}: {1}{2}: {3}'.format( result[0], result[1], (':' + result[2] if result[2] != '0' else ''), result[3]), 'action__path': result[0], 'action__line': result[1], 'action__col': result[2], }] if result and os.path.isfile(result[0]) else []
def gather_candidates(self, context): result = parse_jump_line( self.vim.call('getcwd'), context['__line']) if result and os.path.isfile(result[0]): return [{ 'word': '{0}: {1}{2}: {3}'.format( result[0], result[1], (':' + result[2] if result[2] != '0' else ''), result[3]), 'action__path': result[0], 'action__line': result[1], 'action__col': result[2], }] cfile = context['__cfile'] if cfile == '.' or cfile == '..': return [] if os.path.exists(cfile): return [{'word': cfile, 'action__path': os.path.abspath(cfile)}] if _checkhost(cfile): return [{'word': cfile, 'action__path': cfile}] return []
def _async_gather_candidates(self, context: UserContext, timeout: float) -> Candidates: outs, errs = context['__proc'].communicate(timeout=timeout) if errs: self.error_message(context, errs) context['is_async'] = ( context['__proc'] and not context['__proc'].eof()) if context['__proc'] and context['__proc'].eof(): context['__proc'] = None candidates = [] for line in outs: result = util.parse_jump_line(context['path'], line) if not result: continue path = (str(Path(result[0]).relative_to(context['path'])) if result[0] != context['path'] and result[0].startswith(context['path'] + sep) else context['path']) truncated = truncate(self.vim, path, self.vars['max_path_length']) candidates.append(_candidate(result, truncated)) return candidates
def gather_candidates(self, context): result = parse_jump_line(self.vim.call('getcwd'), context['__line']) if result and os.path.isfile(result[0]): return [{ 'word': '{}: {}{}: {}'.format( result[0], result[1], (':' + result[2] if result[2] != '0' else ''), result[3]), 'action__path': result[0], 'action__line': result[1], 'action__col': result[2], }] cfile = context['__cfile'] if match('[./]+$', cfile): return [] if os.path.exists(cfile): return [{'word': cfile, 'action__path': abspath(self.vim, cfile)}] if _checkhost(cfile): return [{'word': cfile, 'action__path': cfile}] return []