Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Fix folding and make some performance improvements (Editor) #21669

Merged
merged 33 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3aa18cf
Mixins: Fix header comments so they appear in Spyder's outline
ccordoba12 Jan 29, 2023
ae2c4f4
Mixins: Rewrite get_text_region to be thread safe
ccordoba12 Jan 29, 2023
32beb40
Editor: Completely update folding info on a thread
ccordoba12 Jan 29, 2023
20eea96
Editor: Improve how we manage errors that appear while handling LSP r…
ccordoba12 Nov 6, 2022
112de64
Scrollflag: Update flags shown in ScrollFlagArea using a thread
ccordoba12 Jan 30, 2023
c264c06
Scrollflag: Add logging message when updating scroll area flags
ccordoba12 Jan 30, 2023
c73deb9
Code snippets: Delay calling cursor_changed a bit
ccordoba12 Feb 1, 2023
83971de
Code snippets: Only call code that involves _find_node_by_position if…
ccordoba12 Feb 1, 2023
dc4b2e0
Editor: Extract folding ranges info directly on it
ccordoba12 Feb 8, 2023
33e6630
Editor: Remove unnecesary log message
ccordoba12 Feb 11, 2023
87492b8
Folding: Move init to be at the beginning
ccordoba12 Feb 13, 2023
f32fc9c
Folding: Fix removing folded regions
ccordoba12 Feb 13, 2023
df623ce
Folding: Update block decorations when removing or replacing text
ccordoba12 Feb 16, 2023
ccdc5d6
Folding: Paint decorations for folded regions on top of the current line
ccordoba12 Feb 16, 2023
73b2378
Decorations: Allow to add/remove single decorations by key
ccordoba12 Feb 16, 2023
fa8b4ca
Folding: Clear block decorations when new info arrives from the LSP
ccordoba12 Feb 16, 2023
6a5bcc1
Folding: Don't paint decorations for folded regions on its paintEvent
ccordoba12 Feb 18, 2023
0b05a2b
Folding: Highlight folded regions on the editor's visible buffer
ccordoba12 Feb 18, 2023
7dfa160
Folding: Check if blocks are folded by UI inspection
ccordoba12 Feb 18, 2023
79a96e4
Folding: Remove code to use native icons
ccordoba12 Feb 19, 2023
0f6a280
Folding: Simplify the way we paint collapsed/uncollapsed icons
ccordoba12 Feb 19, 2023
c9bd2a0
Folding: Use chevron icons for folding
ccordoba12 Feb 20, 2023
5c50c2b
Folding: A couple of style improvements
ccordoba12 Feb 25, 2023
9b43b71
Scrollflag: Delay updating it while users are moving the cursor
ccordoba12 Feb 25, 2023
fb3f111
Folding: Pass ranges that come from the LSP directly to merge_folding
ccordoba12 Mar 6, 2023
6d625eb
Testing: Expand editor folding tests
ccordoba12 Dec 29, 2023
66ad46d
Editor: Use an attribute in CodeEditor for the folding panel
ccordoba12 Jan 2, 2024
1c5bace
Editor: Restore Spyder 5 order of left side panels
ccordoba12 Jan 2, 2024
1a0153a
Testing: Fix failing tests
ccordoba12 Jan 3, 2024
cc5a0aa
Suggestions from code review
ccordoba12 Feb 4, 2024
a408d3f
Decorations: Remove unneeded check for default key value in add/remove
ccordoba12 Feb 4, 2024
b19adfe
Folding: Prevent Tab/Shift+Tab to modify the contents of folded lines
ccordoba12 Feb 6, 2024
ed35459
Folding: Prevent typing in folded lines to change them
ccordoba12 Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,10 @@ def folding_range_request(self, params):

@handles(CompletionRequestTypes.DOCUMENT_FOLDING_RANGE)
def process_folding_range(self, result, req_id):
results = []
for folding_range in result:
start_line = folding_range['startLine']
end_line = folding_range['endLine']
results.append((start_line, end_line))
if req_id in self.req_reply:
self.req_reply[req_id](
CompletionRequestTypes.DOCUMENT_FOLDING_RANGE,
{'params': results})
{'params': result})

@send_notification(method=CompletionRequestTypes.DOCUMENT_WILL_SAVE)
def document_will_save_notification(self, params):
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/debugger/utils/breakpointsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, editor):
# Debugger panel (Breakpoints)
self.debugger_panel = DebuggerPanel(self)
editor.panels.register(self.debugger_panel)
self.debugger_panel.order_in_zone = -1
self.debugger_panel.order_in_zone = 1
self.update_panel_visibility()

# Load breakpoints
Expand Down
7 changes: 4 additions & 3 deletions spyder/plugins/editor/api/decoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
QTextCharFormat)

# Local imports
from spyder.utils.palette import QStylePalette, SpyderPalette
from spyder.utils.palette import SpyderPalette


# DRAW_ORDERS are used for make some decorations appear in top of others,
Expand All @@ -37,9 +37,10 @@

DRAW_ORDERS = {'on_bottom': 0,
'current_cell': 1,
'codefolding': 2,
'folding_areas': 2,
'current_line': 3,
'on_top': 4}
'folded_regions': 4,
'on_top': 5}


class TextDecoration(QTextEdit.ExtraSelection):
Expand Down
8 changes: 0 additions & 8 deletions spyder/plugins/editor/api/editorextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
<https://github.com/pyQode/pyqode.core/blob/master/pyqode/core/api/mode.py>
"""

import logging


logger = logging.getLogger(__name__)


class EditorExtension(object):
"""
Expand Down Expand Up @@ -87,9 +82,6 @@ def __init__(self):
self._editor = None
self._on_close = False

def __del__(self):
logger.debug('%s.__del__', type(self))

def on_install(self, editor):
"""
Installs the extension on the editor.
Expand Down
31 changes: 18 additions & 13 deletions spyder/plugins/editor/extensions/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import functools

# Third party imports
from qtpy.QtGui import QTextCursor, QColor
from qtpy.QtCore import Qt, QMutex, QMutexLocker
from diff_match_patch import diff_match_patch
from qtpy.QtCore import QMutex, QMutexLocker, Qt
from qtpy.QtGui import QTextCursor, QColor
from superqt.utils import qdebounced

try:
from rtree import index
Expand Down Expand Up @@ -89,7 +90,6 @@ def __init__(self):
self.starting_position = None
self.modification_lock = QMutex()
self.event_lock = QMutex()
self.update_lock = QMutex()
self.node_position = {}
self.snippets_map = {}
self.undo_stack = []
Expand All @@ -98,7 +98,7 @@ def __init__(self):
self.index = index.Index()

def on_state_changed(self, state):
"""Connect/disconnect sig_key_pressed signal."""
"""Connect/disconnect editor signals."""
if state:
self.editor.sig_key_pressed.connect(self._on_key_pressed)
self.editor.sig_insert_completion.connect(self.insert_snippet)
Expand Down Expand Up @@ -589,7 +589,8 @@ def _find_lowest_common_ancestor(self, start_node, end_node):

@lock
def remove_selection(self, selection_start, selection_end):
self._remove_selection(selection_start, selection_end)
if self.is_snippet_active:
self._remove_selection(selection_start, selection_end)

def _remove_selection(self, selection_start, selection_end):
start_node, _, _ = self._find_node_by_position(*selection_start)
Expand Down Expand Up @@ -712,8 +713,10 @@ def _find_node_by_position(self, line, col):
text_ids = set([id(token) for token in nearest_text.tokens])
if node_id not in text_ids:
current_node = nearest_text.tokens[-1]

return current_node, nearest_snippet, nearest_text

@qdebounced(timeout=20)
def cursor_changed(self, line, col):
if not rtree_available:
return
Expand All @@ -722,14 +725,16 @@ def cursor_changed(self, line, col):
self.inserting_snippet = False
return

node, nearest_snippet, _ = self._find_node_by_position(line, col)
if node is None:
ignore = self.editor.is_undoing or self.editor.is_redoing
if not ignore:
self.reset()
else:
if nearest_snippet is not None:
self.active_snippet = nearest_snippet.number
if self.is_snippet_active:
node, nearest_snippet, _ = self._find_node_by_position(line, col)

if node is None:
ignore = self.editor.is_undoing or self.editor.is_redoing
if not ignore:
self.reset()
else:
if nearest_snippet is not None:
self.active_snippet = nearest_snippet.number

def reset(self, partial_reset=False):
self.node_number = 0
Expand Down
Loading
Loading