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 class/function selector for split editors (Editor) #20961

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions spyder/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ def main_window(request, tmpdir, qtbot):
preload_complex_project = request.node.get_closest_marker(
'preload_complex_project')
if preload_complex_project:
CONF.set('editor', 'show_class_func_dropdown', True)
create_complex_project(tmpdir)
else:
CONF.set('editor', 'show_class_func_dropdown', False)
if not preload_project:
CONF.set('project_explorer', 'current_project_path', None)

Expand Down
33 changes: 33 additions & 0 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4227,6 +4227,39 @@ def editors_with_info(treewidget):
root_1 = treewidget.editor_items[treewidget.current_editor.get_id()]
assert root_1.node.childCount() == 2

# Check that class/function selector of cloned editor is populated
editorstack_1.set_stack_index(idx)
editor_1 = editorstack_1.get_current_editor()
editor_2 = editorstack_2.get_current_editor()
assert editor_2.is_cloned
# one class + "<None>" entry
assert editor_2.classfuncdropdown.class_cb.count() == 2
# one function + two methods + "<None>" entry
assert editor_2.classfuncdropdown.method_cb.count() == 4
assert editor_1.classfuncdropdown._data == editor_2.classfuncdropdown._data

def get_cb_list(cb):
rear1019 marked this conversation as resolved.
Show resolved Hide resolved
return [cb.itemText(i) for i in range(cb.count())]
assert get_cb_list(editor_1.classfuncdropdown.class_cb) == \
get_cb_list(editor_2.classfuncdropdown.class_cb)
assert get_cb_list(editor_1.classfuncdropdown.method_cb) == \
get_cb_list(editor_2.classfuncdropdown.method_cb)

# Check that class/function selector of cloned editor is updated
with qtbot.waitSignal(editor_2.oe_proxy.sig_outline_explorer_data_changed,
timeout=5000):
editor_2.set_text('def baz(x):\n return x')
assert editor_2.is_cloned
# "<None>" entry
assert editor_2.classfuncdropdown.class_cb.count() == 1
# one function + "<None>" entry
assert editor_2.classfuncdropdown.method_cb.count() == 2
assert editor_1.classfuncdropdown._data == editor_2.classfuncdropdown._data
assert get_cb_list(editor_1.classfuncdropdown.class_cb) == \
get_cb_list(editor_2.classfuncdropdown.class_cb)
assert get_cb_list(editor_1.classfuncdropdown.method_cb) == \
get_cb_list(editor_2.classfuncdropdown.method_cb)

# Hide outline from view
outline_explorer.toggle_view_action.setChecked(False)

Expand Down
16 changes: 10 additions & 6 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,12 +1228,7 @@ def process_symbols(self, params):
"""Handle symbols response."""
try:
symbols = params['params']
symbols = [] if symbols is None else symbols

if self.classfuncdropdown.isVisible():
self.classfuncdropdown.update_data(symbols)
else:
self.classfuncdropdown.set_data(symbols)
self._update_classfuncdropdown(symbols)

if self.oe_proxy is not None:
self.oe_proxy.update_outline_info(symbols)
Expand All @@ -1246,6 +1241,15 @@ def process_symbols(self, params):
finally:
self.symbols_in_sync = True

def _update_classfuncdropdown(self, symbols):
"""Update class/function dropdown."""
symbols = [] if symbols is None else symbols

if self.classfuncdropdown.isVisible():
self.classfuncdropdown.update_data(symbols)
else:
self.classfuncdropdown.set_data(symbols)

# ---- LSP: Linting and didChange
# -------------------------------------------------------------------------
def _schedule_document_did_change(self):
Expand Down
2 changes: 2 additions & 0 deletions spyder/plugins/editor/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,8 @@ def perform_completion_request(lang, method, params):
# symbols for the clon are updated as expected.
cloned_from.oe_proxy.sig_outline_explorer_data_changed.connect(
editor.oe_proxy.update_outline_info)
cloned_from.oe_proxy.sig_outline_explorer_data_changed.connect(
editor._update_classfuncdropdown)
cloned_from.oe_proxy.sig_start_outline_spinner.connect(
editor.oe_proxy.emit_request_in_progress)

Expand Down