Skip to content

Commit 4af3d41

Browse files
Add the scope visualizer (#1653)
- Depends on #1651 - Depends on #1652 - Depends on #1649 - Depends on #1644 ## Checklist - [x] Add image to doc page - [x] File issue to migrate all our vscode references to use new thin wrapper - [x] File issue about reworking removal highlight range to return generalised range, and not using line range for line target content range - [x] Investigate cheatsheet performance issue - [x] Migrate todos from #1523 - [x] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] I have not broken the cheatsheet - [x] Compute border colors from background color? --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent d3d52bf commit 4af3d41

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

src/cheatsheet/cheat_sheet.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .get_list import get_list, get_lists
88
from .sections.actions import get_actions
99
from .sections.compound_targets import get_compound_targets
10+
from .sections.get_scope_visualizer import get_scope_visualizer
1011
from .sections.modifiers import get_modifiers
1112
from .sections.scopes import get_scopes
1213
from .sections.special_marks import get_special_marks
@@ -102,6 +103,11 @@ def cursorless_cheat_sheet_get_json():
102103
"id": "scopes",
103104
"items": get_scopes(),
104105
},
106+
{
107+
"name": "Scope visualizer",
108+
"id": "scopeVisualizer",
109+
"items": get_scope_visualizer(),
110+
},
105111
{
106112
"name": "Modifiers",
107113
"id": "modifiers",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from ..get_list import get_list, get_raw_list, make_readable
2+
3+
4+
def get_scope_visualizer():
5+
show_scope_visualizer = list(get_raw_list("show_scope_visualizer").keys())[0]
6+
visualization_types = get_raw_list("visualization_type")
7+
8+
return [
9+
*get_list("hide_scope_visualizer", "command"),
10+
{
11+
"id": "show_scope_visualizer",
12+
"type": "command",
13+
"variations": [
14+
{
15+
"spokenForm": f"{show_scope_visualizer} <scope>",
16+
"description": "Visualize <scope>",
17+
},
18+
*[
19+
{
20+
"spokenForm": f"{show_scope_visualizer} <scope> {spoken_form}",
21+
"description": f"Visualize <scope> {make_readable(id).lower()} range",
22+
}
23+
for spoken_form, id in visualization_types.items()
24+
],
25+
],
26+
},
27+
]

src/cursorless.talon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ tag: user.cursorless
2020
user.cursorless_wrap(cursorless_wrap_action, cursorless_target, cursorless_wrapper)
2121

2222
{user.cursorless_homophone} settings: user.cursorless_show_settings_in_ide()
23+
24+
{user.cursorless_show_scope_visualizer} <user.cursorless_scope_type> [{user.cursorless_visualization_type}]:
25+
user.private_cursorless_show_scope_visualizer(cursorless_scope_type, cursorless_visualization_type or "content")
26+
{user.cursorless_hide_scope_visualizer}:
27+
user.private_cursorless_hide_scope_visualizer()

src/scope_visualizer.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from talon import Module, app
2+
3+
from .csv_overrides import init_csv_and_watch_changes
4+
from .cursorless_command_server import run_rpc_command_no_wait
5+
6+
mod = Module()
7+
mod.list("cursorless_show_scope_visualizer", desc="Show scope visualizer")
8+
mod.list("cursorless_hide_scope_visualizer", desc="Hide scope visualizer")
9+
mod.list(
10+
"cursorless_visualization_type",
11+
desc='Cursorless visualization type, e.g. "removal" or "iteration"',
12+
)
13+
14+
# NOTE: Please do not change these dicts. Use the CSVs for customization.
15+
# See https://www.cursorless.org/docs/user/customization/
16+
visualization_types = {
17+
"removal": "removal",
18+
"iteration": "iteration",
19+
}
20+
21+
22+
@mod.action_class
23+
class Actions:
24+
def private_cursorless_show_scope_visualizer(
25+
scope_type: dict, visualization_type: str
26+
):
27+
"""Shows scope visualizer"""
28+
run_rpc_command_no_wait(
29+
"cursorless.showScopeVisualizer", scope_type, visualization_type
30+
)
31+
32+
def private_cursorless_hide_scope_visualizer():
33+
"""Hides scope visualizer"""
34+
run_rpc_command_no_wait("cursorless.hideScopeVisualizer")
35+
36+
37+
def on_ready():
38+
init_csv_and_watch_changes(
39+
"scope_visualizer",
40+
{
41+
"show_scope_visualizer": {"visualize": "showScopeVisualizer"},
42+
"hide_scope_visualizer": {"visualize nothing": "hideScopeVisualizer"},
43+
"visualization_type": visualization_types,
44+
},
45+
)
46+
47+
48+
app.register("ready", on_ready)

0 commit comments

Comments
 (0)