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 1 commit
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
Prev Previous commit
Next Next commit
Testing: Fix failing tests
Also, make others run on Windows
  • Loading branch information
ccordoba12 committed Feb 6, 2024
commit 1a0153aa8af41c7f4e79d65e635d01b6ee9cb4ba
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ def test_update_decorations_when_scrolling(qtbot):

# Only one call to _update should be done, after releasing the key.
qtbot.wait(editor.UPDATE_DECORATIONS_TIMEOUT + 100)
assert _update.call_count == 4
assert _update.call_count == 5

# Simulate continuously pressing the up arrow key.
for __ in range(200):
qtbot.keyPress(editor, Qt.Key_Up)

# Only one call to _update should be done, after releasing the key.
qtbot.wait(editor.UPDATE_DECORATIONS_TIMEOUT + 100)
assert _update.call_count == 5
assert _update.call_count == 6


if __name__ == "__main__":
Expand Down
18 changes: 12 additions & 6 deletions spyder/plugins/editor/widgets/codeeditor/tests/test_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""Tests for the folding features."""

# Standard library imports
import os
import sys

# Third party imports
from flaky import flaky
Expand All @@ -16,6 +16,9 @@
from qtpy.QtCore import Qt
from qtpy.QtGui import QTextCursor

# Local imports
from spyder.config.base import running_in_ci


# ---- Code to test
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -85,7 +88,6 @@ def test_folding(completions_codeeditor, qtbot):

@pytest.mark.order(2)
@flaky(max_runs=5)
@pytest.mark.skipif(os.name == 'nt', reason="Hangs on Windows")
def test_unfold_when_searching(search_codeeditor, qtbot):
editor, finder = search_codeeditor
editor.toggle_code_folding(True)
Expand Down Expand Up @@ -114,7 +116,6 @@ def test_unfold_when_searching(search_codeeditor, qtbot):

@pytest.mark.order(2)
@flaky(max_runs=5)
@pytest.mark.skipif(os.name == 'nt', reason="Hangs on Windows")
def test_unfold_goto(completions_codeeditor, qtbot):
editor, __ = completions_codeeditor
editor.toggle_code_folding(True)
Expand All @@ -140,7 +141,10 @@ def test_unfold_goto(completions_codeeditor, qtbot):

@flaky(max_runs=5)
@pytest.mark.order(2)
@pytest.mark.skipif(os.name == 'nt', reason="Hangs on Windows")
@pytest.mark.skipif(
running_in_ci() and sys.platform.startswith("linux"),
reason="Fails on Linux and CIs"
)
def test_delete_folded_line(completions_codeeditor, qtbot):
editor, __ = completions_codeeditor
editor.toggle_code_folding(True)
Expand Down Expand Up @@ -209,7 +213,10 @@ def fold_and_delete_region(key):

@flaky(max_runs=5)
@pytest.mark.order(2)
@pytest.mark.skipif(os.name == 'nt', reason="Hangs on Windows")
@pytest.mark.skipif(
running_in_ci() and sys.platform.startswith("linux"),
reason="Fails on Linux and CIs"
)
def test_delete_selections_with_folded_lines(completions_codeeditor, qtbot):
editor, __ = completions_codeeditor
editor.toggle_code_folding(True)
Expand Down Expand Up @@ -292,7 +299,6 @@ def restore_initial_state():

@flaky(max_runs=5)
@pytest.mark.order(2)
@pytest.mark.skipif(os.name == 'nt', reason="Hangs on Windows")
def test_preserve_folded_regions_after_paste(completions_codeeditor, qtbot):
editor, __ = completions_codeeditor
editor.toggle_code_folding(True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pytest

# Local imports
from spyder.config.base import running_in_ci
from spyder.config.base import running_in_ci, running_in_ci_with_conda
from spyder.plugins.editor.extensions.closebrackets import (
CloseBracketsExtension
)
Expand Down Expand Up @@ -211,7 +211,15 @@ def test_get_hints_not_triggered(qtbot, completions_codeeditor, text):


@pytest.mark.order(2)
@pytest.mark.skipif(sys.platform == 'darwin', reason='Fails on Mac')
@pytest.mark.skipif(
(
sys.platform == "darwin"
or (
sys.platform.startswith("linux") and not running_in_ci_with_conda()
)
),
reason="Fails on Linux with pip packages and Mac",
)
@pytest.mark.parametrize(
"params",
[
Expand Down Expand Up @@ -266,7 +274,15 @@ def test_get_hints_for_builtins(qtbot, completions_codeeditor, params):


@pytest.mark.order(2)
@pytest.mark.skipif(sys.platform == 'darwin', reason='Fails on Mac')
@pytest.mark.skipif(
(
sys.platform == "darwin"
or (
sys.platform.startswith("linux") and not running_in_ci_with_conda()
)
),
reason="Fails on Linux with pip packages and Mac",
)
@pytest.mark.parametrize(
"params",
[
Expand Down
17 changes: 12 additions & 5 deletions spyder/plugins/editor/widgets/editorstack/tests/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def test_save_as_lsp_calls(completions_editor, mocker, qtbot, tmpdir):
"""
Test that EditorStack.save_as() sends the expected LSP requests.

Regression test for spyder-ide/spyder#13085 and spyder-ide/spyder#20047
Regression test for spyder-ide/spyder#13085 and spyder-ide/spyder#20047.
"""
file_path, editorstack, code_editor, completion_plugin = completions_editor

Expand Down Expand Up @@ -572,8 +572,9 @@ def foo(x):
qtbot.waitUntil(symbols_and_folding_processed, timeout=5000)

# Check response by LSP
assert code_editor.handle_folding_range.call_args == \
mocker.call({'params': [(1, 3)]})
assert code_editor.handle_folding_range.call_args == mocker.call(
{"params": [{"startLine": 1, "endLine": 3}]}
)

symbols = [
{
Expand Down Expand Up @@ -664,8 +665,14 @@ def bar():
# responded to the requests).

# Check that LSP responded with updated folding and symbols information
assert code_editor.handle_folding_range.call_args == \
mocker.call({'params': [(1, 5), (7, 9)]})
assert code_editor.handle_folding_range.call_args == mocker.call(
{
"params": [
{"startLine": 1, "endLine": 5},
{"startLine": 7, "endLine": 9},
]
}
)

# There must be 7 symbols (2 functions and 5 variables)
assert len(code_editor.process_symbols.call_args.args[0]['params']) == 7
Expand Down