-
-
Notifications
You must be signed in to change notification settings - Fork 88
Add the scope visualizer #1653
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
Merged
Merged
Add the scope visualizer #1653
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3d9018
Add the scope visualizer
pokey 863083d
Update cheatsheet
pokey 91a25ae
Add docs
pokey f6aa1ee
Empty commit
pokey e2d608b
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] fa8431c
Add images to docs
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
cursorless-talon/src/cheatsheet/sections/get_scope_visualizer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from ..get_list import get_list, get_raw_list, make_readable | ||
|
||
|
||
def get_scope_visualizer(): | ||
show_scope_visualizer = list(get_raw_list("show_scope_visualizer").keys())[0] | ||
visualization_types = get_raw_list("visualization_type") | ||
|
||
return [ | ||
*get_list("hide_scope_visualizer", "command"), | ||
{ | ||
"id": "show_scope_visualizer", | ||
"type": "command", | ||
"variations": [ | ||
{ | ||
"spokenForm": f"{show_scope_visualizer} <scope>", | ||
"description": "Visualize <scope>", | ||
}, | ||
*[ | ||
{ | ||
"spokenForm": f"{show_scope_visualizer} <scope> {spoken_form}", | ||
"description": f"Visualize <scope> {make_readable(id).lower()} range", | ||
} | ||
for spoken_form, id in visualization_types.items() | ||
], | ||
], | ||
}, | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from talon import Module, app | ||
|
||
from .csv_overrides import init_csv_and_watch_changes | ||
from .cursorless_command_server import run_rpc_command_no_wait | ||
|
||
mod = Module() | ||
mod.list("cursorless_show_scope_visualizer", desc="Show scope visualizer") | ||
mod.list("cursorless_hide_scope_visualizer", desc="Hide scope visualizer") | ||
mod.list( | ||
"cursorless_visualization_type", | ||
desc='Cursorless visualization type, e.g. "removal" or "iteration"', | ||
) | ||
|
||
# NOTE: Please do not change these dicts. Use the CSVs for customization. | ||
# See https://www.cursorless.org/docs/user/customization/ | ||
visualization_types = { | ||
"removal": "removal", | ||
"iteration": "iteration", | ||
} | ||
|
||
|
||
@mod.action_class | ||
class Actions: | ||
def private_cursorless_show_scope_visualizer( | ||
scope_type: dict, visualization_type: str | ||
): | ||
"""Shows scope visualizer""" | ||
run_rpc_command_no_wait( | ||
"cursorless.showScopeVisualizer", scope_type, visualization_type | ||
) | ||
|
||
def private_cursorless_hide_scope_visualizer(): | ||
"""Hides scope visualizer""" | ||
run_rpc_command_no_wait("cursorless.hideScopeVisualizer") | ||
|
||
|
||
def on_ready(): | ||
init_csv_and_watch_changes( | ||
"scope_visualizer", | ||
{ | ||
"show_scope_visualizer": {"visualize": "showScopeVisualizer"}, | ||
"hide_scope_visualizer": {"visualize nothing": "hideScopeVisualizer"}, | ||
pokey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"visualization_type": visualization_types, | ||
}, | ||
) | ||
|
||
|
||
app.register("ready", on_ready) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Scope visualizer | ||
|
||
The scope visualizer allows you to visualize Cursorless scopes on your code in real time. It is useful to understand how Cursorless scopes work, and is also useful for Cursorless contributors as they develop new scopes. | ||
|
||
## Usage | ||
|
||
To start the scope visualizer, say `"visualize <scope>"`, where `<scope>` is the name of the scope you want to visualize. For example, `"visualize funk"`. To stop the scope visualizer, say `"visualize nothing"`. | ||
|
||
You can also visualize removal and iteration ranges for scopes by saying `"visualize <scope> removal"` and `"visualize <scope> iteration"`, respectively. | ||
|
||
## Examples | ||
|
||
### `"visualize funk"` | ||
|
||
 | ||
|
||
### `"visualize token"` | ||
|
||
 | ||
|
||
### `"visualize block removal"` | ||
|
||
 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/cursorless-vscode-e2e/src/suite/scopeVisualizer/checkAndResetFakes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { assert } from "chai"; | ||
import * as sinon from "sinon"; | ||
import { | ||
createDecorationTypeCallToPlainObject, | ||
setDecorationsCallToPlainObject, | ||
} from "./spyCallsToPlainObject"; | ||
import { Fakes, ExpectedArgs } from "./scopeVisualizerTest.types"; | ||
|
||
export function checkAndResetFakes(fakes: Fakes, expected: ExpectedArgs) { | ||
const actual = getSpyCallsAndResetFakes(fakes); | ||
assert.deepStrictEqual(actual, expected, JSON.stringify(actual)); | ||
} | ||
|
||
function getSpyCallsAndResetFakes({ | ||
createTextEditorDecorationType, | ||
setDecorations, | ||
dispose, | ||
}: Fakes) { | ||
return { | ||
decorationRenderOptions: getAndResetFake( | ||
createTextEditorDecorationType, | ||
createDecorationTypeCallToPlainObject, | ||
), | ||
decorationRanges: getAndResetFake( | ||
setDecorations, | ||
setDecorationsCallToPlainObject, | ||
), | ||
disposedDecorationIds: getAndResetFake(dispose, ({ args: [id] }) => id), | ||
}; | ||
} | ||
|
||
function getAndResetFake<ArgList extends any[], Return, Expected>( | ||
spy: sinon.SinonSpy<ArgList, Return>, | ||
transform: (call: sinon.SinonSpyCall<ArgList, Return>) => Expected, | ||
) { | ||
const actual = spy.getCalls().map(transform); | ||
spy.resetHistory(); | ||
return actual; | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/cursorless-vscode-e2e/src/suite/scopeVisualizer/colorConfig.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ScopeVisualizerColorConfig } from "@cursorless/vscode-common"; | ||
|
||
/** | ||
* Fake color config to use for testing. We use an alpha of 50% and try to use | ||
* different rgb channels where possible to make it easier to see what happens | ||
* when we blend colors. | ||
*/ | ||
export const COLOR_CONFIG: ScopeVisualizerColorConfig = { | ||
dark: { | ||
content: { | ||
background: "#00000180", | ||
borderPorous: "#00000280", | ||
borderSolid: "#00000380", | ||
}, | ||
domain: { | ||
background: "#01000080", | ||
borderPorous: "#02000080", | ||
borderSolid: "#03000080", | ||
}, | ||
iteration: { | ||
background: "#00000480", | ||
borderPorous: "#00000580", | ||
borderSolid: "#00000680", | ||
}, | ||
removal: { | ||
background: "#00010080", | ||
borderPorous: "#00020080", | ||
borderSolid: "#00030080", | ||
}, | ||
}, | ||
light: { | ||
content: { | ||
background: "#00000180", | ||
borderPorous: "#00000280", | ||
borderSolid: "#00000380", | ||
}, | ||
domain: { | ||
background: "#01000080", | ||
borderPorous: "#02000080", | ||
borderSolid: "#03000080", | ||
}, | ||
iteration: { | ||
background: "#00000480", | ||
borderPorous: "#00000580", | ||
borderSolid: "#00000680", | ||
}, | ||
removal: { | ||
background: "#00010080", | ||
borderPorous: "#00020080", | ||
borderSolid: "#00030080", | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.