Skip to content

Thenable => Promise; tweak clipboard mock #1322

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 3 commits into from
Mar 21, 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: 1 addition & 1 deletion packages/common/ide/fake/FakeGlobalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class FakeGlobalState implements State {
return this.data[key];
}

set<K extends StateKey>(key: K, value: StateData[K]): Thenable<void> {
set<K extends StateKey>(key: K, value: StateData[K]): Promise<void> {
this.data[key] = value;
return Promise.resolve();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/common/ide/types/Clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
export interface Clipboard {
/**
* Read the current clipboard contents as text.
* @returns A thenable that resolves to a string.
* @returns A promise that resolves to a string.
*/
readText(): Thenable<string>;
readText(): Promise<string>;

/**
* Writes text into the clipboard.
* @returns A thenable that resolves when writing happened.
* @returns A promise that resolves when writing happened.
*/
writeText(value: string): Thenable<void>;
writeText(value: string): Promise<void>;
}
2 changes: 1 addition & 1 deletion packages/common/ide/types/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export interface State {
* @param key A string.
* @param value A value. MUST not contain cyclic references.
*/
set<K extends StateKey>(key: K, value: StateData[K]): Thenable<void>;
set<K extends StateKey>(key: K, value: StateData[K]): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function selectionInfosToSelections(
*/
export async function callFunctionAndUpdateSelections(
rangeUpdater: RangeUpdater,
func: () => Thenable<void>,
func: () => Promise<void>,
document: TextDocument,
selectionMatrix: (readonly Selection[])[],
): Promise<Selection[][]> {
Expand All @@ -165,7 +165,7 @@ export async function callFunctionAndUpdateSelections(

export async function callFunctionAndUpdateRanges(
rangeUpdater: RangeUpdater,
func: () => Thenable<void>,
func: () => Promise<void>,
document: TextDocument,
rangeMatrix: (readonly Range[])[],
): Promise<Range[][]> {
Expand All @@ -190,7 +190,7 @@ export async function callFunctionAndUpdateRanges(
*/
export async function callFunctionAndUpdateSelectionInfos(
rangeUpdater: RangeUpdater,
func: () => Thenable<void>,
func: () => Promise<void>,
document: TextDocument,
selectionInfoMatrix: FullSelectionInfo[][],
) {
Expand All @@ -217,7 +217,7 @@ export async function callFunctionAndUpdateSelectionInfos(
*/
export function callFunctionAndUpdateSelectionsWithBehavior(
rangeUpdater: RangeUpdater,
func: () => Thenable<void>,
func: () => Promise<void>,
document: TextDocument,
originalSelections: SelectionsWithBehavior[],
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as vscode from "vscode";
import { Clipboard } from "@cursorless/common";

export default class VscodeClipboard implements Clipboard {
readText(): Thenable<string> {
return vscode.env.clipboard.readText();
async readText(): Promise<string> {
return await vscode.env.clipboard.readText();
}

writeText(value: string): Thenable<void> {
return vscode.env.clipboard.writeText(value);
async writeText(value: string): Promise<void> {
return await vscode.env.clipboard.writeText(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class VscodeGlobalState implements State {
return this.extensionContext.globalState.get(key, STATE_DEFAULTS[key]);
}

set<K extends StateKey>(key: K, value: StateData[K]): Thenable<void> {
return this.extensionContext.globalState.update(key, value);
async set<K extends StateKey>(key: K, value: StateData[K]): Promise<void> {
return await this.extensionContext.globalState.update(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export default async function vscodeOpenLink(
return true;
}

function getLinksForEditor(editor: vscode.TextEditor) {
return vscode.commands.executeCommand(
async function getLinksForEditor(
editor: vscode.TextEditor,
): Promise<vscode.DocumentLink[]> {
return (await vscode.commands.executeCommand(
"vscode.executeLinkProvider",
editor.document.uri,
) as Thenable<vscode.DocumentLink[]>;
))!;
}

function openLink(link: vscode.DocumentLink) {
Expand Down
4 changes: 1 addition & 3 deletions packages/cursorless-vscode-e2e/suite/recorded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ async function runTest(file: string, spyIde: SpyIDE) {
spyIde.activeTextEditor!,
spyIde,
marks,
undefined,
undefined,
// FIXME: Stop overriding the clipboard once we have #559
vscode.env.clipboard,
true,
);

const rawSpyIdeValues = spyIde.getSpyValues(fixture.ide?.flashes != null);
Expand Down
13 changes: 5 additions & 8 deletions packages/cursorless-vscode/constructTestHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
CommandServerApi,
ExcludableSnapshotField,
ExtraContext,
ExtraSnapshotField,
IDE,
NormalizedIDE,
Expand Down Expand Up @@ -43,10 +42,8 @@ export function constructTestHelpers(
extraFields: ExtraSnapshotField[],
editor: TextEditor,
ide: IDE,
marks?: SerializedMarks,
extraContext?: ExtraContext,
metadata?: unknown,
clipboard?: vscode.Clipboard,
marks: SerializedMarks | undefined,
forceRealClipboard: boolean,
): Promise<TestCaseSnapshot> {
return takeSnapshot(
thatMark,
Expand All @@ -56,9 +53,9 @@ export function constructTestHelpers(
editor,
ide,
marks,
extraContext,
metadata,
clipboard,
undefined,
undefined,
forceRealClipboard ? vscodeIDE.clipboard : undefined,
);
},

Expand Down
7 changes: 2 additions & 5 deletions packages/vscode-common/getExtensionApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
CommandServerApi,
ExcludableSnapshotField,
ExtraContext,
ExtraSnapshotField,
HatTokenMap,
IDE,
Expand Down Expand Up @@ -41,10 +40,8 @@ export interface TestHelpers {
extraFields: ExtraSnapshotField[],
editor: TextEditor,
ide: IDE,
marks?: SerializedMarks,
extraContext?: ExtraContext,
metadata?: unknown,
clipboard?: vscode.Clipboard,
marks: SerializedMarks | undefined,
forceRealClipboard: boolean,
): Promise<TestCaseSnapshot>;
}

Expand Down