-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,427 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,49 @@ | ||
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", | ||
"content": "content", | ||
} | ||
|
||
|
||
@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"}, | ||
"visualization_type": visualization_types, | ||
}, | ||
) | ||
|
||
|
||
app.register("ready", on_ready) |
This file contains 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 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 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 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", | ||
}, | ||
}, | ||
}; |
52 changes: 52 additions & 0 deletions
52
packages/cursorless-vscode-e2e/src/suite/scopeVisualizer/injectFakes.ts
This file contains 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,52 @@ | ||
import { VscodeApi, getCursorlessApi } from "@cursorless/vscode-common"; | ||
import * as sinon from "sinon"; | ||
import { DecorationRenderOptions, WorkspaceConfiguration } from "vscode"; | ||
import { COLOR_CONFIG } from "./colorConfig"; | ||
import { | ||
Fakes, | ||
MockDecorationType, | ||
SetDecorationsParameters, | ||
} from "./scopeVisualizerTest.types"; | ||
|
||
export async function injectFakes(): Promise<Fakes> { | ||
const { vscodeApi } = (await getCursorlessApi()).testHelpers!; | ||
|
||
const dispose = sinon.fake<[number], void>(); | ||
|
||
let decorationIndex = 0; | ||
const createTextEditorDecorationType = sinon.fake< | ||
Parameters<VscodeApi["window"]["createTextEditorDecorationType"]>, | ||
MockDecorationType | ||
>((_options: DecorationRenderOptions) => { | ||
const id = decorationIndex++; | ||
return { | ||
dispose() { | ||
dispose(id); | ||
}, | ||
id, | ||
}; | ||
}); | ||
|
||
const setDecorations = sinon.fake< | ||
SetDecorationsParameters, | ||
ReturnType<VscodeApi["editor"]["setDecorations"]> | ||
>(); | ||
|
||
const getConfigurationValue = sinon.fake.returns(COLOR_CONFIG); | ||
|
||
sinon.replace( | ||
vscodeApi.window, | ||
"createTextEditorDecorationType", | ||
createTextEditorDecorationType as any, | ||
); | ||
sinon.replace(vscodeApi.editor, "setDecorations", setDecorations as any); | ||
sinon.replace( | ||
vscodeApi.workspace, | ||
"getConfiguration", | ||
sinon.fake.returns({ | ||
get: getConfigurationValue, | ||
} as unknown as WorkspaceConfiguration), | ||
); | ||
|
||
return { setDecorations, createTextEditorDecorationType, dispose }; | ||
} |
Binary file added
BIN
+35.5 KB
...ursorless-vscode-e2e/src/suite/scopeVisualizer/runBasicMultilineContentTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions
84
packages/cursorless-vscode-e2e/src/suite/scopeVisualizer/runBasicMultilineContentTest.ts
This file contains 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,84 @@ | ||
import { openNewEditor } from "@cursorless/vscode-common"; | ||
import * as vscode from "vscode"; | ||
import { checkAndResetFakes } from "./checkAndResetFakes"; | ||
import { injectFakes } from "./injectFakes"; | ||
import { ExpectedArgs } from "./scopeVisualizerTest.types"; | ||
|
||
/** | ||
* Tests that the scope visualizer works with multiline content, by | ||
* ensuring that the correct decorations are applied so that it looks | ||
* like `./runBasicMultilineContentTest.png`. | ||
*/ | ||
export async function runBasicMultilineContentTest() { | ||
await openNewEditor(contents, { | ||
languageId: "typescript", | ||
}); | ||
|
||
const fakes = await injectFakes(); | ||
|
||
await vscode.commands.executeCommand( | ||
"cursorless.showScopeVisualizer", | ||
{ | ||
type: "namedFunction", | ||
}, | ||
"content", | ||
); | ||
|
||
checkAndResetFakes(fakes, expectedArgs); | ||
} | ||
|
||
const contents = ` | ||
function helloWorld() { | ||
} | ||
`; | ||
|
||
const expectedArgs: ExpectedArgs = { | ||
decorationRenderOptions: [ | ||
{ | ||
backgroundColor: "#000001c0", | ||
borderColor: "#010002c0 #010001c0 #010001c0 #010002c0", | ||
borderStyle: "solid dashed dashed solid", | ||
borderRadius: "2px 0px 0px 0px", | ||
isWholeLine: false, | ||
id: 0, | ||
}, | ||
{ | ||
backgroundColor: "#000001c0", | ||
borderColor: "#010001c0 #010001c0 #010001c0 #010001c0", | ||
borderStyle: "none dashed none dashed", | ||
borderRadius: "0px 0px 0px 0px", | ||
isWholeLine: false, | ||
id: 1, | ||
}, | ||
{ | ||
backgroundColor: "#000001c0", | ||
borderColor: "#010001c0 #010002c0 #010002c0 #010001c0", | ||
borderStyle: "dashed solid solid dashed", | ||
borderRadius: "0px 0px 2px 0px", | ||
isWholeLine: false, | ||
id: 2, | ||
}, | ||
], | ||
decorationRanges: [ | ||
{ | ||
decorationId: 0, | ||
ranges: [ | ||
{ start: { line: 1, character: 0 }, end: { line: 1, character: 23 } }, | ||
], | ||
}, | ||
{ | ||
decorationId: 1, | ||
ranges: [ | ||
{ start: { line: 2, character: 0 }, end: { line: 2, character: 0 } }, | ||
], | ||
}, | ||
{ | ||
decorationId: 2, | ||
ranges: [ | ||
{ start: { line: 3, character: 0 }, end: { line: 3, character: 1 } }, | ||
], | ||
}, | ||
], | ||
disposedDecorationIds: [], | ||
}; |
Binary file added
BIN
+11.6 KB
packages/cursorless-vscode-e2e/src/suite/scopeVisualizer/runBasicRemovalTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.