Skip to content

Commit

Permalink
Fix update error for breakpoint sings
Browse files Browse the repository at this point in the history
  • Loading branch information
JeunghunKim committed Nov 11, 2022
1 parent 6529626 commit 4cd33b9
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions rplugin/python3/vim_pudb.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def cbname(self):
def __init__(self, nvim=None):
# set our nvim hook first...
self.nvim = nvim
self.nvim.command(":sign define {} text={} texthl={}".format(
self.sgnname(), self.bpsymbol(), self.hlgroup()))
self._toggle_status = {}
self._bps_placed = {} # type: Dict[str,List]
self._cond_dict = {} # type: Dict[str,List]
Expand All @@ -120,7 +122,7 @@ def clear_all_bps(self, buffname=None):
if not buffname:
buffname = self.cbname()
self.test_buffer(buffname)
for num_line in self._bps_placed[buffname]:
for num_line in self._toggle_status[buffname][:]:
self.remove_sign(buffname, num_line)
self._bps_placed[buffname] = []
self.save_bp_file()
Expand All @@ -130,20 +132,10 @@ def remove_bp_file(self):
os.remove(self._bp_file)
self.blank_file()

@neovim.command("PUDBToggleAllSigns", sync=False)
def toggle_signs(self, buffname=None):
if not buffname:
buffname = self.cbname()
if not self._toggle_status[buffname]:
self.sings_on(buffname)
else:
self.signs_off(buffname)

@neovim.command("PUDBOnAllSigns", sync=False)
def sings_on(self, buffname=None):
def signs_on(self, buffname=None):
if not buffname:
buffname = self.cbname()
self._toggle_status[buffname] = True
self.test_buffer(buffname)
for num_line in self._bps_placed[buffname]:
self.place_sign(buffname, num_line)
Expand All @@ -152,9 +144,8 @@ def sings_on(self, buffname=None):
def signs_off(self, buffname=None):
if not buffname:
buffname = self.cbname()
self._toggle_status[buffname] = False
self.test_buffer(buffname)
for num_line in self._bps_placed[buffname]:
for num_line in self._toggle_status[buffname][:]:
self.remove_sign(buffname, num_line)

@neovim.command("PUDBLaunchDebuggerTab", sync=True)
Expand All @@ -168,9 +159,8 @@ def launchdebugtab(self):
def pudb_status(self):
status_info = {}
for buffname in self._bps_placed:
status_info[buffname] = [
[num_line for num_line in self._bps_placed[buffname]],
self._toggle_status[buffname]]
status_info[buffname] = [self._bps_placed[buffname],
bool(self._toggle_status[buffname])]
self.print_feature(status_info)

@neovim.command("PUDBToggleBreakPoint", sync=False)
Expand All @@ -184,7 +174,10 @@ def toggle_bp(self, buffname=None):
self._bps_placed[buffname].sort()
else:
self._bps_placed[buffname].remove(num_line)
self.update_sign(buffname)
if num_line in self._toggle_status[buffname]:
self.remove_sign(buffname, num_line)
else:
self.place_sign(buffname, num_line)
self.save_bp_file()

@neovim.command("PUDBSetEntrypoint", sync=False)
Expand All @@ -199,7 +192,7 @@ def update_sign(self, buffname=None):
buffname = self.cbname()
if self._toggle_status[buffname]:
self.signs_off(buffname)
self.sings_on(buffname)
self.signs_on(buffname)

# set sync so that the current buffer can't change until we are done
@neovim.autocmd('BufRead', pattern='*.py', sync=True)
Expand Down Expand Up @@ -227,17 +220,14 @@ def update_buffer(self):
buffname = self.cbname()
if buffname[:7] == 'term://':
return
self.nvim.command(":sign define {} text={} texthl={}".format(
self.sgnname(), self.bpsymbol(), self.hlgroup()))
self.load_bp_file()
if self._toggle_status[buffname]:
self.update_sign()
self.update_sign(buffname)

def test_buffer(self, buffname):
if buffname not in self._bps_placed:
self._bps_placed[buffname] = []
if buffname not in self._toggle_status:
self._toggle_status[buffname] = False
self._toggle_status[buffname] = []

def load_bp_file(self):
self.make_links()
Expand All @@ -263,10 +253,9 @@ def load_bp_file(self):
self._bps_placed[buffname] = list(set(self._bps_placed[buffname]))
self._bps_placed[buffname].sort()

if buffname not in self._toggle_status:
self._toggle_status[buffname] = False

self.test_buffer(self.cbname())
buffname = self.cbname()
self.test_buffer(buffname)
self.signs_on(buffname)

def save_bp_file(self):
self.make_links()
Expand Down Expand Up @@ -321,23 +310,26 @@ def find_bp_files(self):
files.append(entry)
return sorted(list(set(files)))

def place_sign(self, buffname, lineno):
def place_sign(self, buffname, num_line):
signcmd = "sign place {} line={} name={} file={}".format(
lineno * 10, lineno, self.sgnname(), buffname)
num_line * 10, num_line, self.sgnname(), buffname)
self.nvim.command(signcmd)
if num_line not in self._toggle_status[buffname]:
self._toggle_status[buffname].append(num_line)
self._toggle_status[buffname].sort()

def remove_sign(self, buffname, lineno):
signcmd = 'sign unplace {} file={}'.format(
lineno, buffname)
def remove_sign(self, buffname, num_line):
signcmd = 'sign unplace {} file={}'.format(num_line * 10, buffname)
self.nvim.command(signcmd)
if num_line in self._toggle_status[buffname]:
self._toggle_status[buffname].remove(num_line)

def has_breakpoint(self, buffname, lineno):
def has_breakpoint(self, buffname, num_line):
self.test_buffer(buffname)
if lineno in self._bps_placed[buffname]:
if num_line in self._bps_placed[buffname]:
return True
return False

def print_feature(self, print_input):
print_feature = 'echo "{}"'.format(pprint.pformat(print_input))
self.nvim.command(print_feature)

0 comments on commit 4cd33b9

Please sign in to comment.