Skip to content

Commit

Permalink
Revert "* Set single timeout for syncing symbols and folding"
Browse files Browse the repository at this point in the history
This reverts commit ab9bd39.
  • Loading branch information
mrclary committed Sep 28, 2021
1 parent 4719770 commit 410ef6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
35 changes: 30 additions & 5 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,14 @@ class CodeEditor(TextEditBaseWidget):
UPDATE_DECORATIONS_TIMEOUT = 500 # milliseconds

# Timeouts (in milliseconds) to sychronize symbols and folding after
# linting results arrive
SYNC_SYMBOLS_AND_FOLDING_TIMEOUT = 500 # milliseconds
# linting results arrive, according to the number of lines in the file.
SYNC_SYMBOLS_AND_FOLDING_TIMEOUTS = {
# Lines: Timeout
500: 350,
1500: 800,
2500: 1200,
6500: 1800
}

# Custom signal to be emitted upon completion of the editor's paintEvent
painted = Signal(QPaintEvent)
Expand Down Expand Up @@ -304,10 +310,10 @@ def __init__(self, parent=None):
# See: process_diagnostics
self._timer_sync_symbols_and_folding = QTimer(self)
self._timer_sync_symbols_and_folding.setSingleShot(True)
self._timer_sync_symbols_and_folding.setInterval(
self.SYNC_SYMBOLS_AND_FOLDING_TIMEOUT)
self._timer_sync_symbols_and_folding.timeout.connect(
self.sync_symbols_and_folding)
self.blockCountChanged.connect(
self.set_sync_symbols_and_folding_timeout)

# Goto uri
self._last_hover_pattern_key = None
Expand Down Expand Up @@ -1176,6 +1182,25 @@ def process_diagnostics(self, params):
# Process results (runs in a thread)
self.process_code_analysis(params['params'])

def set_sync_symbols_and_folding_timeout(self):
"""
Set timeout to sync symbols and folding according to the file
size.
"""
current_lines = self.get_line_count()
timeout = None

for lines in self.SYNC_SYMBOLS_AND_FOLDING_TIMEOUTS.keys():
if (current_lines // lines) == 0:
timeout = self.SYNC_SYMBOLS_AND_FOLDING_TIMEOUTS[lines]
break

if not timeout:
timeouts = self.SYNC_SYMBOLS_AND_FOLDING_TIMEOUTS.values()
timeout = list(timeouts)[-1]

self._timer_sync_symbols_and_folding.setInterval(timeout)

def sync_symbols_and_folding(self):
"""
Synchronize symbols and folding after linting results arrive.
Expand Down Expand Up @@ -2855,7 +2880,7 @@ def paste(self):
if indentations:
max_dedent = min(indentations)
lines_adjustment = max(lines_adjustment, -max_dedent)

# Get new text
remaining_lines = [
self.adjust_indentation(line, lines_adjustment)
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/editor/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,7 @@ def load(self, filename, set_current=True, add_where='end',
self.set_os_eol_chars(index)
self.is_analysis_done = False
self.analyze_script(index)
finfo.editor.set_sync_symbols_and_folding_timeout()
return finfo

def set_os_eol_chars(self, index=None, osname=None):
Expand Down

0 comments on commit 410ef6c

Please sign in to comment.