diff options
author | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2016-02-18 06:31:42 +0900 |
---|---|---|
committer | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2016-02-18 06:31:42 +0900 |
commit | b8206e908435aa44aa574a226bfe06cef8e9d028 (patch) | |
tree | 94c151789c65d1e26e5842253eb08f18dfc6e75e /rplugin/python3 | |
parent | d1247ab46abb0553a32f04faf730f95822319eb9 (diff) | |
download | deoplete.nvim-b8206e908435aa44aa574a226bfe06cef8e9d028.zip |
Fix #179 dictionary and tag source errors
Diffstat (limited to 'rplugin/python3')
-rw-r--r-- | rplugin/python3/deoplete/sources/dictionary.py | 13 | ||||
-rw-r--r-- | rplugin/python3/deoplete/sources/tag.py | 14 | ||||
-rw-r--r-- | rplugin/python3/deoplete/util.py | 13 |
3 files changed, 18 insertions, 22 deletions
diff --git a/rplugin/python3/deoplete/sources/dictionary.py b/rplugin/python3/deoplete/sources/dictionary.py index 20b519d..a567f42 100644 --- a/rplugin/python3/deoplete/sources/dictionary.py +++ b/rplugin/python3/deoplete/sources/dictionary.py @@ -23,11 +23,9 @@ # }}} # ============================================================================ -import re -import functools -import operator from os.path import getmtime, exists from collections import namedtuple +from deoplete.util import parse_file_pattern from .base import Base DictCacheItem = namedtuple('DictCacheItem', 'mtime candidates') @@ -51,7 +49,7 @@ class Source(Base): if filename not in self.__cache or self.__cache[ filename].mtime != mtime: with open(filename, 'r', errors='replace') as f: - new_candidates = parse_dictionary( + new_candidates = parse_file_pattern( f, context['keyword_patterns']) candidates += new_candidates self.__cache[filename] = DictCacheItem( @@ -61,12 +59,5 @@ class Source(Base): return [{'word': x} for x in candidates] -def parse_dictionary(f, keyword_patterns): - p = re.compile(keyword_patterns) - return list(set(functools.reduce(operator.add, [ - p.findall(x) for x in f.readlines() - ]))) - - def get_dictionaries(vim, filetype): return vim.current.buffer.options.get('dictionary', '').split(',') diff --git a/rplugin/python3/deoplete/sources/tag.py b/rplugin/python3/deoplete/sources/tag.py index c0139a8..081d7df 100644 --- a/rplugin/python3/deoplete/sources/tag.py +++ b/rplugin/python3/deoplete/sources/tag.py @@ -24,11 +24,9 @@ # }}} # ============================================================================ -import re -import functools -import operator from os.path import getmtime, exists, getsize from collections import namedtuple +from deoplete.util import parse_file_pattern from .base import Base TagsCacheItem = namedtuple('TagsCacheItem', 'mtime candidates') @@ -58,7 +56,8 @@ class Source(Base): if filename not in self.__cache or self.__cache[ filename].mtime != mtime: with open(filename, 'r', errors='replace') as f: - new_candidates = parse_tags(f) + new_candidates = parse_file_pattern( + f, '^[a-zA-Z_]\w*(?=\t)') candidates += new_candidates self.__cache[filename] = TagsCacheItem( mtime, new_candidates) @@ -66,10 +65,3 @@ class Source(Base): else: candidates += self.__cache[filename].candidates return [{'word': x} for x in candidates] - - -def parse_tags(f): - p = re.compile('^[a-zA-Z_]\w*(?=\t)') - return list(set(functools.reduce(operator.add, [ - p.findall(x) for x in f.readlines() - ]))) diff --git a/rplugin/python3/deoplete/util.py b/rplugin/python3/deoplete/util.py index c52d273..4aa47a2 100644 --- a/rplugin/python3/deoplete/util.py +++ b/rplugin/python3/deoplete/util.py @@ -23,7 +23,10 @@ # }}} # ============================================================================ +import re import json +import functools +import operator def get_buffer_config(vim, filetype, buffer_var, user_var, default_var): @@ -85,3 +88,13 @@ def get_custom(vim, source_name): def get_syn_name(vim): return vim.call('deoplete#util#get_syn_name') + + +def parse_file_pattern(f, pattern): + lines = f.readlines() + if not lines: + return [] + p = re.compile(pattern) + return list(set(functools.reduce(operator.add, [ + p.findall(x) for x in lines + ]))) |