Skip to content

Commit 32a2a98

Browse files
committed
bugfix for path cmp error
1 parent e8f0296 commit 32a2a98

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

pythonx/EasyCompleteUtil/util.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@
1010
ALWAYS = 'always'
1111
NEVER = 'never'
1212

13+
1314
def listdir(path):
14-
return os.listdir(path)
15+
ret = []
16+
try:
17+
ret = os.listdir(path)
18+
except FileNotFoundError:
19+
ret = []
20+
return ret
21+
1522

1623
def get_sha256(str):
1724
s = hashlib.sha256()
1825
s.update(str.encode("utf8"))
19-
sha_str= s.hexdigest()
26+
sha_str = s.hexdigest()
2027
return sha_str
2128

29+
2230
# Normal sort
2331
def _get_key(el):
2432
if len(el["abbr"]) != 0:
@@ -27,12 +35,15 @@ def _get_key(el):
2735
k1 = el["word"]
2836
return k1
2937

38+
3039
def getkey_by_alphabet(el):
31-
return _get_key(el).lower().rjust(5,"a")
40+
return _get_key(el).lower().rjust(5, "a")
41+
3242

3343
def getkey_by_length(el):
3444
return len(_get_key(el))
3545

46+
3647
def json_parse_bool2str(obj):
3748
if obj is None:
3849
return ""
@@ -41,22 +52,25 @@ def json_parse_bool2str(obj):
4152
if isinstance(obj, (list, tuple)):
4253
return [json_parse_bool2str(item) for item in obj]
4354
if isinstance(obj, dict):
44-
return {json_parse_bool2str(key):json_parse_bool2str(value) for key, value in obj.items()}
55+
its = obj.items()
56+
return {json_parse_bool2str(k): json_parse_bool2str(v) for k, v in its}
4557
return obj
4658

59+
4760
def normalize_sort(items):
4861
# 先按照长度排序
4962
items.sort(key=getkey_by_length)
5063
# 再按照字母表排序
5164
items.sort(key=getkey_by_alphabet)
5265
return json.dumps(json_parse_bool2str(items), ensure_ascii=False)
5366

67+
5468
# Fuzzy search
5569
def fuzzy_search(needle, haystack):
5670
"""
5771
判断是否符合模糊匹配的规则,实测性能不如 viml 的实现
5872
"""
59-
flag = 1
73+
# flag = 1
6074
tlen = len(haystack)
6175
qlen = len(needle)
6276
if qlen > tlen:
@@ -85,9 +99,11 @@ def fuzzy_search(needle, haystack):
8599
return 0
86100
return 1
87101

102+
88103
def log(msg):
89104
print(msg)
90105

106+
91107
# py vs vim,vim 性能极好
92108
# 27 次调用,py 用时 0.012392
93109
# 27 次调用,vim 用时0.002804
@@ -105,7 +121,8 @@ def snippets_code_info(filename, line_number):
105121

106122
cursor_line = line_number
107123
while cursor_line + 1 < len(snip_ctx):
108-
if re.compile(r"^(snippet|endsnippet)").match(snip_ctx[cursor_line + 1]):
124+
new_ln = cursor_line + 1
125+
if re.compile(r"^(snippet|endsnippet)").match(snip_ctx[new_ln]):
109126
break
110127
else:
111128
cursor_line += 1
@@ -114,21 +131,26 @@ def snippets_code_info(filename, line_number):
114131
end_line_index = cursor_line
115132

116133
code_original_info = snip_ctx[start_line_index:end_line_index + 1]
117-
ret_array = list(map(lambda line: re.sub(r"\n$", "", line), code_original_info))
134+
lam = map(lambda line: re.sub(r"\n$", "", line), code_original_info)
135+
ret_array = list(lam)
118136
# vim.command("echom %s"% json.dumps(ret_array))
119137
return json.dumps(ret_array, ensure_ascii=False)
120138

139+
121140
def complete_menu_filter(all_menu, word, maxlength):
122141
return json.dumps(all_menu, ensure_ascii=False)
123142

143+
124144
"""
125145
Helper utilities to format javascript snippets.
126146
"""
127147
# {{{
128148

149+
129150
def get_option(snip, option, default=None):
130151
return snip.opt('g:ultisnips_javascript["{}"]'.format(option), default)
131152

153+
132154
def semi(snip):
133155
option = get_option(snip, 'semi', ALWAYS)
134156

0 commit comments

Comments
 (0)