def on_init(self, context): vars = context['vars'] self.gocode_binary = \ expand(vars.get('deoplete#sources#go#gocode_binary', '')) self.package_dot = \ vars.get('deoplete#sources#go#package_dot', False) self.sort_class = \ vars.get('deoplete#sources#go#sort_class', []) self.pointer = \ vars.get('deoplete#sources#go#pointer', False) self.auto_goos = \ vars.get('deoplete#sources#go#auto_goos', False) self.goos = \ vars.get('deoplete#sources#go#goos', '') self.goarch = \ vars.get('deoplete#sources#go#goarch', '') self.sock = \ vars.get('deoplete#sources#go#gocode_sock', '') self.use_cache = \ vars.get('deoplete#sources#go#use_cache', False) self.json_directory = \ expand(vars.get('deoplete#sources#go#json_directory', '')) self.cgo = \ vars.get('deoplete#sources#go#cgo', False) self.loaded_gocode_binary = False self.complete_pos = re.compile(r'\w*$|(?<=")[./\-\w]*$') if self.pointer: self.complete_pos = re.compile(self.complete_pos.pattern + r'|\*$') self.input_pattern += r'|\*' if self.cgo: load_external_module(__file__, 'clang') import clang.cindex as clang self.libclang_path = \ vars.get('deoplete#sources#go#cgo#libclang_path', '') if self.libclang_path == '': return self.cgo_options = { 'std': vars.get('deoplete#sources#go#cgo#std', 'c11'), 'sort_algo': vars.get('deoplete#sources#cgo#sort_algo', None) } if not clang.Config.loaded and \ clang.Config.library_path != self.libclang_path: clang.Config.set_library_file(self.libclang_path) clang.Config.set_compatibility_check(False) # Set 'C.' complete pattern self.cgo_complete_pattern = re.compile(r'[^\W\d]*C\.') # Create clang.cindex.Index database self.index = clang.Index.create(0) # initialize in-memory cache self.cgo_cache, self.cgo_inline_source = dict(), None
def on_init(self, context): vars = context['vars'] self.encoding = self.vim.eval('&encoding') self.workspace_cache = {} self.command = expand(vars.get('deoplete#sources#solargraph#command', 'solargraph')) self.args = vars.get('deoplete#sources#solargraph#args', ['--port', '0'])
def gather_candidates(self, context: UserContext) -> Candidates: if not self._isfname: self.on_event(context) input_str = (context['input'] if context['input'].rfind('/') >= 0 else './') p = self._longest_path_that_exists(context, input_str) slash_completion = bool(self.get_var('enable_slash_completion')) if not p or re.search('//+$', p) or (p == '/' and not slash_completion): return [] complete_str = self._substitute_path(context, expand(p) + '/') if not Path(complete_str).is_dir(): return [] hidden = context['complete_str'].find('.') == 0 contents: typing.List[typing.Any] = [[], []] try: for item in sorted( [str(x.name) for x in Path(complete_str).iterdir()], key=str.lower): if not hidden and item[0] == '.': continue contents[not Path(complete_str + item).is_dir()].append(item) except PermissionError: pass dirs, files = contents return [{ 'word': x, 'abbr': x + '/' } for x in dirs] + [{ 'word': x } for x in files]
def on_init(self, context): ### input pattern dotHints = [r"(\(|<|[a-zA-Z]|\"|\[)*(?<=(\)|>|[a-zA-Z0-9]|\"|\]))\."] oneWordHints = [ r"^[a-zA-Z]$", "\s*[a-zA-Z]$", "typeof\<[a-zA-Z]$", "(\(\))[a-zA-Z]$", "(\<|\>)[a-zA-Z]$", "(\[|\])[a-zA-Z]$" ] attributeHints = [r"\[<[a-zA-Z]*"] self.input_pattern = '|'.join(dotHints + oneWordHints + attributeHints) ### initialize of deopletefs self.standby = False self.filePath = expand( self.vim.eval("substitute( expand('%:p') , '\#', '\\#' , 'g' )")) fsc_path = expand( re.split('rplugin', __file__)[0] + expand('bin/deopletefs.exe')) post_data = { "Row": -9999 # dummy row , "Col": 1, "Line": '', "FilePath": self.filePath, "Source": '\n'.join(getlines(self.vim)), "Init": 'true' } self.util = Util(fsc_path, 20) self.util.send(json.dumps(post_data)) start = time.time() self.vim.command("echo '*** deopletefs initializing... ***'") if str(self.util.read()) != '': self.standby = True elapsed_time = time.time() - start self.vim.command("echo '*** finish initialize! *** ( time : " + str(round(elapsed_time, 6)) + " s )'") else: elapsed_time = time.time() - start self.vim.command( "echo '*** Sorry! Please Re-open file! *** ( time : " + str(round(elapsed_time, 6)) + " s )'")
def _find_alias_files(self): self._alias_files = set() for dir in self._find_mutt_dirs(): for file in glob.glob(expand(dir + '/aliases')): if path.isdir(file): continue with open(file) as f: if any(line.lstrip().startswith('alias') for line in f): self._alias_files.add(file)
def __substitute_path(self, context, path): m = re.match(r'(\.{1,2})/+', path) if m: if self.__buffer_path and context['bufpath']: base = context['bufpath'] else: base = os.path.join(context['cwd'], 'x') for _ in m.group(1): base = dirname(base) return os.path.abspath(os.path.join(base, path[len(m.group(0)):])) return expand(path)
def _substitute_path(self, context: UserContext, path: str) -> str: m = re.match(r'(\.{1,2})/+', path) if m: if self.get_var('enable_buffer_path') and context['bufpath']: base = context['bufpath'] else: base = context['cwd'] if m.group(1) == '..': base = str(Path(base).parent) return str(Path(base).joinpath(path[len(m.group(0)):])) + '/' return expand(path)
def __substitute_path(self, context, path): m = re.match(r'(\.{1,2})/+', path) if m: if self.__buffer_path and context['bufname']: base = context['bufname'] else: base = os.path.join(context['cwd'], 'x') for _ in m.group(1): base = dirname(base) return os.path.abspath(os.path.join(base, path[len(m.group(0)):])) return expand(path)
def _substitute_path(self, context: UserContext, path: str) -> str: m = re.match(r'(\.{1,2})/+', path) if m: if self.get_var('enable_buffer_path') and context['bufpath']: base = context['bufpath'] else: base = os.path.join(context['cwd'], 'x') for _ in m.group(1): base = dirname(base) return os.path.abspath(os.path.join(base, path[len(m.group(0)):])) + '/' return expand(path)
def _get_dictionaries(self, context): dict_opt = self.get_buf_option('dictionary') if not dict_opt: return [] dicts = [] for d in [expand(x) for x in dict_opt.split(',') if exists(x)]: if isdir(d): with scandir(d) as it: dicts += [x.path for x in it if x.is_file()] else: dicts.append(d) return dicts
def _get_dictionaries(self, context): dict_opt = self.vim.options['dictionary'] if 'dictionary' in self.vim.current.buffer.options: dict_opt = self.vim.current.buffer.options['dictionary'] if not dict_opt: return [] dicts = [] for d in [expand(x) for x in dict_opt.split(',') if exists(x)]: if isdir(d): with scandir(d) as it: dicts += [x.path for x in it if x.is_file()] else: dicts.append(d) return dicts
def on_init(self, context): self.filePath = expand( self.vim.eval( "substitute( expand('%:p:r') . '_deoplete-fsharp_temporary_file.fsx' , '\#', '\\#' , 'g' )" )) fsc_path = expand( re.split('rplugin', __file__)[0] + expand('ftplugin/bin_deopletefs/deopletefs.exe')) post_data = { "Row": -9999 # dummy row , "Col": -9999 # dummy col , "Line": '' # dummy line , "FilePath": self.filePath, "Source": '\n'.join(getlines(self.vim)), "Init": 'dummy_init' } self.util = Util(fsc_path, 20, json.dumps(post_data)) self.util.start()
def gather_candidates(self, context: UserContext) -> Candidates: if not self._isfname: self.on_event(context) input_str = (context['input'] if context['input'].rfind('/') >= 0 else './') # Note: context['bufpath'] will be empty if not exists file bufname = context['bufname'] bufpath = (bufname if Path(bufname).is_absolute() else str(Path(context['cwd']).joinpath(bufname))) buftype = self.vim.call('getbufvar', '%', '&buftype') if not bufname or 'nofile' in buftype or not self.get_var( 'enable_buffer_path'): bufpath = '' p = self._longest_path_that_exists(context, input_str, bufpath) slash_completion = bool(self.get_var('enable_slash_completion')) if not p or re.search('//+$', p) or ( p == '/' and not slash_completion): return [] p = expand(p) if p[-1] != '/': p += '/' complete_str = self._substitute_path(context, p, bufpath) if not Path(complete_str).is_dir(): return [] hidden = context['complete_str'].find('.') == 0 contents: typing.List[typing.Any] = [[], []] try: for item in sorted([str(x.name) for x in Path(complete_str).iterdir()], key=str.lower): if not hidden and item[0] == '.': continue is_dir = not Path(complete_str + '/' + item).is_dir() contents[is_dir].append(item) except PermissionError: pass dirs, files = contents return [{'word': x, 'abbr': x + '/'} for x in dirs ] + [{'word': x} for x in files]
def _substitute_path(self, context: UserContext, path: str, bufpath: str) -> str: m = re.match(r'(\.{1,2})/+', path) if not m: return expand(path) if bufpath: base = str(Path(bufpath).parent) else: base = context['cwd'] if m.group(1) == '..': base = str(Path(base).parent) rest = path[len(m.group(0)):] if rest: return str(Path(base).joinpath(rest)) + '/' else: return base
def on_init(self, context): vars = context['vars'] self.gocode_binary = \ expand(vars.get('deoplete#sources#go#gocode_binary', '')) self.package_dot = \ vars.get('deoplete#sources#go#package_dot', False) self.sort_class = \ vars.get('deoplete#sources#go#sort_class', []) self.pointer = \ vars.get('deoplete#sources#go#pointer', False) self.auto_goos = \ vars.get('deoplete#sources#go#auto_goos', False) self.goos = \ vars.get('deoplete#sources#go#goos', '') self.goarch = \ vars.get('deoplete#sources#go#goarch', '') self.sock = \ vars.get('deoplete#sources#go#gocode_sock', '') self.use_cache = \ vars.get('deoplete#sources#go#use_cache', False) self.json_directory = \ expand(vars.get('deoplete#sources#go#json_directory', '')) self.use_on_event = \ vars.get('deoplete#sources#go#on_event', False) self.cgo = \ vars.get('deoplete#sources#go#cgo', False) self.loaded_gocode_binary = False self.complete_pos = re.compile(r'\w*$|(?<=")[./\-\w]*$') if self.pointer: self.complete_pos = re.compile(self.complete_pos.pattern + r'|\*$') if self.cgo: load_external_module(__file__, 'clang') import clang.cindex as clang self.libclang_path = \ vars.get('deoplete#sources#go#cgo#libclang_path', '') if self.libclang_path == '': return self.cgo_options = { 'std': vars.get('deoplete#sources#go#cgo#std', 'c11'), 'sort_algo': vars.get('deoplete#sources#cgo#sort_algo', None) } if not clang.Config.loaded and \ clang.Config.library_path != self.libclang_path: clang.Config.set_library_file(self.libclang_path) clang.Config.set_compatibility_check(False) # Set 'C.' complete pattern self.cgo_complete_pattern = re.compile(r'[^\W\d]*C\.') # Create clang.cindex.Index database self.index = clang.Index.create(0) # initialize in-memory cache self.cgo_cache, self.cgo_inline_source = dict(), None # Dummy execute the gocode for gocode's in-memory cache try: context['complete_position'] = \ self.vim.current.window.cursor[1] self.get_complete_result(self.buffer, context, kill=True) self.debug('called on_init') except Exception: # Ignore the error pass
def on_init(self, context): vars = context["vars"] self.gocode_binary = "" if "deoplete#sources#go#gocode_binary" in vars: self.gocode_binary = expand( vars["deoplete#sources#go#gocode_binary"]) self.package_dot = False if "deoplete#sources#go#package_dot" in vars: self.package_dot = vars["deoplete#sources#go#package_dot"] self.sort_class = [] if "deoplete#sources#go#package_dot" in vars: self.sort_class = vars["deoplete#sources#go#sort_class"] self.pointer = False if "deoplete#sources#go#pointer" in vars: self.pointer = vars["deoplete#sources#go#pointer"] self.auto_goos = False if "deoplete#sources#go#auto_goos" in vars: self.auto_goos = vars["deoplete#sources#go#auto_goos"] self.goos = "" if "deoplete#sources#go#goos" in vars: self.goos = vars["deoplete#sources#go#goos"] self.goarch = "" if "deoplete#sources#go#goarch" in vars: self.goarch = vars["deoplete#sources#go#goarch"] self.sock = "" if "deoplete#sources#go#sock" in vars: self.sock = vars["deoplete#sources#go#sock"] self.cgo = False if "deoplete#sources#go#cgo" in vars: self.cgo = vars["deoplete#sources#go#cgo"] self.cgo_only = False if "deoplete#sources#go#cgo_only" in vars: self.cgo_only = vars["deoplete#sources#go#cgo_only"] self.source_importer = False if "deoplete#sources#go#source_importer" in vars: self.source_importer = vars["deoplete#sources#go#source_importer"] self.builtin_objects = False if "deoplete#sources#go#builtin_objects" in vars: self.builtin_objects = vars["deoplete#sources#go#builtin_objects"] self.unimported_packages = False if "deoplete#sources#go#unimported_packages" in vars: self.unimported_packages = vars[ "deoplete#sources#go#unimported_packages"] self.fallback_to_source = False if "deoplete#sources#go#fallback_to_source" in vars: self.fallback_to_source = vars[ "deoplete#sources#go#fallback_to_source"] self.loaded_gocode_binary = False self.complete_pos = re.compile(r'\w*$|(?<=")[./\-\w]*$') if self.pointer: self.complete_pos = re.compile(self.complete_pos.pattern + r"|\*$") self.input_pattern += r"|\*" if self.cgo: load_external_module(__file__, "clang") import clang.cindex as clang self.libclang_path = vars.get( "deoplete#sources#go#cgo#libclang_path", "") if self.libclang_path == "": return self.cgo_options = { "std": vars.get("deoplete#sources#go#cgo#std", "c11"), "sort_algo": vars.get("deoplete#sources#cgo#sort_algo", None), } if (not clang.Config.loaded and clang.Config.library_path != self.libclang_path): clang.Config.set_library_file(self.libclang_path) clang.Config.set_compatibility_check(False) # Set 'C.' complete pattern self.cgo_complete_pattern = re.compile(r"[^\W\d]*C\.") # Create clang.cindex.Index database self.index = clang.Index.create(0) # initialize in-memory cache self.cgo_cache, self.cgo_inline_source = dict(), None
def _find_mutt_dirs(self): return [ expand(location) for location in POSSIBLE_MUTT_DIRS if path.isdir(expand(location)) ]