From 8200b6bf7d1275202218cd0bfbacdbce4cbb9241 Mon Sep 17 00:00:00 2001 From: fengidri Date: Tue, 4 Feb 2020 16:12:32 +0800 Subject: [PATCH] fix bug for ctags bytes vs str --- exts/goany/__init__.py | 2 +- exts/goany/filter_file.py | 2 ++ exts/goany/tags.py | 40 ++++++++++++++++++++++++--------------- exts/web/__init__.py | 2 -- wind/pyvim/cmd.py | 1 - 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/exts/goany/__init__.py b/exts/goany/__init__.py index 61a0332..6b6ee70 100644 --- a/exts/goany/__init__.py +++ b/exts/goany/__init__.py @@ -7,7 +7,7 @@ import filter_tag import filter_file import all_tag -#import tags +import tags import pyvim diff --git a/exts/goany/filter_file.py b/exts/goany/filter_file.py index 5350801..51cfc03 100644 --- a/exts/goany/filter_file.py +++ b/exts/goany/filter_file.py @@ -62,6 +62,8 @@ def __init__(self, path): def quit(self, win, index): file_filter.INSTANCE = None + if not index: + return if index > -1: path = os.path.join(self.path, self.fs[index]) diff --git a/exts/goany/tags.py b/exts/goany/tags.py index 3f4fb70..115651c 100644 --- a/exts/goany/tags.py +++ b/exts/goany/tags.py @@ -22,6 +22,9 @@ def encode(cmd): def goto(path, prefix, pos): + + logging.error('goto path: %s, %s, %s' %(path, prefix, pos)) + if path != vim.current.buffer.name: vim.command('update') @@ -37,9 +40,9 @@ def goto(path, prefix, pos): tagname = prefix[1] line_nu = None - if isinstance(line, basestring): + if isinstance(line, str): for i, l in enumerate(vim.current.buffer): - if l.startswith(line): + if l.startswith(line[2:-1]): line_nu = i else: line_nu = line @@ -79,22 +82,27 @@ def goto(self): class Tag(object): def __init__(self, root, entry): - self.tag = entry["name"] - self.file_path = os.path.join(root, entry["file"]) + self.tag = entry[b"name"] + + root = bytes(root, encoding="utf-8") - line = entry["pattern"] + self.file_path = os.path.join(root, entry[b"file"]) + + line = entry[b"pattern"] if line.isdigit(): self.line = int(line) - 1 else: - patten = line.replace(r'\/','/') + line = str(line) + patten = line.replace(r'\/', '/') patten = patten.replace(r'\r','') self.line = encode(patten[2:-2]) - self.line_num = entry["lineNumber"] - self.kind = entry["kind"] + self.line_num = entry[b"lineNumber"] + self.kind = entry[b"kind"] def goto(self): - goto(self.file_path, (self.line, self.tag), None) + goto(self.file_path.decode('utf8'), + (self.line, self.tag.decode('utf8')), None) @@ -119,7 +127,7 @@ def open(self): self.funs = None self.tagsfile = tags; - self.tagfile = ctags.CTags(self.tagsfile) + self.tagfile = ctags.CTags(bytes(self.tagsfile, encoding='utf-8')) self.entry = ctags.TagEntry() return True @@ -163,7 +171,7 @@ def out_list(self, tag, MODE=ctags.TAG_FULLMATCH): return None list_tags = [] - status = self.tagfile.find(self.entry, tag, MODE ) + status = self.tagfile.find(self.entry, bytes(tag, encoding='utf-8'), MODE ) if not status: return None @@ -248,10 +256,12 @@ def jump_tag(self): return 0 #echo - vim.command("echo '%s %s %s/%s'" % ( - frame.tagname, - frame.taglist[frame.index].kind, - frame.index, frame.num)) + #cmd = "echo '%s %s %s/%s'" % ( frame.tagname, + # frame.taglist[frame.index].kind, + # frame.index, frame.num) + + #print(cmd) + #vim.command(cmd) self.goto(frame) diff --git a/exts/web/__init__.py b/exts/web/__init__.py index 852655f..6cbc878 100644 --- a/exts/web/__init__.py +++ b/exts/web/__init__.py @@ -14,8 +14,6 @@ def start(): curfile = os.path.realpath(__file__) curdir = os.path.dirname(curfile) fwebdir = os.path.join(curdir, 'fweb') - subprocess.call(['bash', '-c', - 'cd %s; python2 fweb.py >/dev/null 2>&1' % fwebdir]) start() diff --git a/wind/pyvim/cmd.py b/wind/pyvim/cmd.py index 65d6856..dfd76db 100644 --- a/wind/pyvim/cmd.py +++ b/wind/pyvim/cmd.py @@ -57,7 +57,6 @@ def __command(vimcmd, fun, complete): index=len(CMDS)) CMDS.append(fun) - logging.debug(c) vim.command(c)