Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ export class LanguageDefinitionsImpl implements LanguageDefinitions {
private treeSitter: TreeSitter,
private treeSitterQueryProvider: RawTreeSitterQueryProvider,
) {
const isTesting = ide.runMode === "test";

this.disposables.push(
ide.onDidOpenTextDocument((document) => {
// During testing we open untitled documents that all have the same uri and version which breaks our cache
if (isTesting) {
treeSitterQueryCache.clear();
}
this.loadLanguage(document.languageId).catch((err) => {
void showError(
this.ide.messages,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CURSORLESS_COMMAND_ID } from "@cursorless/common";
import { getCursorlessApi, openNewEditor } from "@cursorless/vscode-common";
import { getCursorlessApi, getReusableEditor } from "@cursorless/vscode-common";
import * as assert from "assert";
import * as vscode from "vscode";
import { endToEndTestSetup } from "../endToEndTestSetup";
Expand All @@ -13,7 +13,7 @@ suite("Backward compatibility", async function () {
async function runTest() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor("");
const editor = await getReusableEditor("");

editor.selections = [new vscode.Selection(0, 0, 0, 0)];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LATEST_VERSION } from "@cursorless/common";
import {
getCursorlessApi,
openNewEditor,
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as assert from "assert";
Expand All @@ -27,7 +27,7 @@ suite("breakpoints", async function () {

async function breakpointAdd() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
await openNewEditor(" hello");
await getReusableEditor(" hello");
await hatTokenMap.allocateHats();
await toggleBreakpoint();

Expand All @@ -40,7 +40,7 @@ async function breakpointAdd() {

async function breakpointTokenAdd() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
await openNewEditor(" hello");
await getReusableEditor(" hello");
await hatTokenMap.allocateHats();
await toggleTokenBreakpoint();

Expand All @@ -53,7 +53,7 @@ async function breakpointTokenAdd() {

async function breakpointRemove() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
const editor = await openNewEditor(" hello");
const editor = await getReusableEditor(" hello");
await hatTokenMap.allocateHats();

vscode.debug.addBreakpoints([
Expand All @@ -71,7 +71,7 @@ async function breakpointRemove() {

async function breakpointTokenRemove() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
const editor = await openNewEditor(" hello");
const editor = await getReusableEditor(" hello");
await hatTokenMap.allocateHats();

vscode.debug.addBreakpoints([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LATEST_VERSION } from "@cursorless/common";
import {
getCursorlessApi,
openNewEditor,
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import { assert } from "chai";
Expand All @@ -19,7 +19,7 @@ suite("Take token twice", async function () {

async function runTest() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
const editor = await openNewEditor("a)");
const editor = await getReusableEditor("a)");
await hatTokenMap.allocateHats();

for (let i = 0; i < 2; ++i) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LATEST_VERSION } from "@cursorless/common";
import {
getCursorlessApi,
openNewEditor,
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as assert from "assert";
Expand All @@ -16,7 +16,7 @@ suite("Explicit mark", async function () {

async function explicitMark() {
const { ide } = (await getCursorlessApi()).testHelpers!;
const editor = await openNewEditor("foo bar baz");
const editor = await getReusableEditor("foo bar baz");
const editorId = ide.visibleTextEditors[0].id;

await runCursorlessCommand({
Expand Down
19 changes: 12 additions & 7 deletions packages/cursorless-vscode-e2e/src/suite/fold.vscode.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { LATEST_VERSION } from "@cursorless/common";
import { openNewEditor, runCursorlessCommand } from "@cursorless/vscode-common";
import {
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as assert from "node:assert";
import * as vscode from "vscode";
import { endToEndTestSetup } from "../endToEndTestSetup";
Expand All @@ -12,9 +15,10 @@ suite("fold", async function () {
});

async function foldMade() {
const editor = await openNewEditor("function myFunk() {\n\n}", {
languageId: "typescript",
});
const editor = await getReusableEditor(
"function myFunk() {\n\n}",
"typescript",
);

await runCursorlessCommand({
version: LATEST_VERSION,
Expand All @@ -38,9 +42,10 @@ async function foldMade() {
}

async function unfoldMade() {
const editor = await openNewEditor("function myFunk() {\n\n}", {
languageId: "typescript",
});
const editor = await getReusableEditor(
"function myFunk() {\n\n}",
"typescript",
);
await vscode.commands.executeCommand("editor.fold", {
selectionLines: [0],
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { LATEST_VERSION } from "@cursorless/common";
import { getFixturePath, isWindows } from "@cursorless/node-common";
import { openNewEditor, runCursorlessCommand } from "@cursorless/vscode-common";
import {
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as assert from "assert";
import * as vscode from "vscode";
import { endToEndTestSetup } from "../endToEndTestSetup";
import { LATEST_VERSION } from "@cursorless/common";

suite("followLink", async function () {
endToEndTestSetup(this);
Expand All @@ -13,9 +16,10 @@ suite("followLink", async function () {
});

async function followDefinition() {
const editor = await openNewEditor("const foo = 'hello';\nconst bar = foo;", {
languageId: "typescript",
});
const editor = await getReusableEditor(
"const foo = 'hello';\nconst bar = foo;",
"typescript",
);
await vscode.commands.executeCommand("revealLine", {
lineNumber: 1,
at: "top",
Expand Down Expand Up @@ -48,7 +52,7 @@ async function followLink() {
const linkTextContent = isWindows()
? `file:///${filename}`
: `file://${filename}`;
await openNewEditor(linkTextContent);
await getReusableEditor(linkTextContent);

await runCursorlessCommand({
version: LATEST_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ async function runTest(
/** The editor containing the "instance" */
const instanceEditor = spyIde.activeTextEditor!;
/** The editor in which "from" is run */
const fromEditor = await openNewEditor(" aaa bbb aaa aaa", {
openBeside: true,
});
const fromEditor = await openNewEditor(" aaa bbb aaa aaa", "plaintext", true);
const { document: fromDocument } = fromEditor;
fromEditor.selections = [new Selection(0, 0, 0, 0)];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getCursorlessApi, openNewEditor } from "@cursorless/vscode-common";
import {
getCursorlessApi,
getReusableEditor,
openNewEditor,
} from "@cursorless/vscode-common";
import { assert } from "chai";
import * as vscode from "vscode";
import { endToEndTestSetup, sleepWithBackoff } from "../../endToEndTestSetup";
Expand Down Expand Up @@ -191,7 +195,7 @@ suite("Basic keyboard test", async function () {

async function checkKeyboardStartup() {
await getCursorlessApi();
const editor = await openNewEditor("");
const editor = await getReusableEditor("");

// Type the letter
await typeText("a");
Expand All @@ -202,9 +206,7 @@ async function checkKeyboardStartup() {
async function basic() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor("function foo() {}\n", {
languageId: "typescript",
});
const editor = await getReusableEditor("function foo() {}\n", "typescript");
await hatTokenMap.allocateHats();

editor.selection = new vscode.Selection(1, 0, 1, 0);
Expand Down Expand Up @@ -232,7 +234,7 @@ async function basic() {
async function noAutomaticTokenExpansion() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor("aaa");
const editor = await getReusableEditor("aaa");
await hatTokenMap.allocateHats();

editor.selection = new vscode.Selection(0, 3, 0, 3);
Expand All @@ -251,9 +253,8 @@ async function noAutomaticTokenExpansion() {
async function sequence(t: TestCase) {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor(t.initialContent, {
languageId: "typescript",
});
// This test fails if we use getReusableEditor()
const editor = await openNewEditor(t.initialContent, "typescript");
await hatTokenMap.allocateHats();
editor.selection = new vscode.Selection(1, 0, 1, 0);
await vscode.commands.executeCommand("cursorless.keyboard.modal.modeOn");
Expand All @@ -264,9 +265,7 @@ async function sequence(t: TestCase) {
async function vscodeCommand() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor("aaa;\nbbb;\nccc;\n", {
languageId: "typescript",
});
const editor = await getReusableEditor("aaa;\nbbb;\nccc;\n", "typescript");
await hatTokenMap.allocateHats();

editor.selection = new vscode.Selection(0, 0, 0, 0);
Expand All @@ -293,7 +292,7 @@ async function vscodeCommand() {
}

async function enterAndLeaveIsNoOp() {
const editor = await openNewEditor("hello");
const editor = await getReusableEditor("hello");

const originalSelection = new vscode.Selection(0, 0, 0, 0);
editor.selection = originalSelection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import type {
SimpleScopeTypeType,
} from "@cursorless/common";
import { asyncSafety } from "@cursorless/common";
import { openNewEditor, runCursorlessAction } from "@cursorless/vscode-common";
import {
getReusableEditor,
runCursorlessAction,
} from "@cursorless/vscode-common";
import assert from "assert";
import * as vscode from "vscode";
import { endToEndTestSetup } from "../endToEndTestSetup";
Expand Down Expand Up @@ -212,7 +215,7 @@ async function testPerformanceCallback(
callback: () => Promise<unknown>,
beforeCallback?: (editor: vscode.TextEditor) => Promise<unknown>,
) {
const editor = await openNewEditor(testData, { languageId: "json" });
const editor = await getReusableEditor(testData, "json");
// This is the position of the last json key in the document
const position = new vscode.Position(editor.document.lineCount - 3, 5);
const selection = new vscode.Selection(position, position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function runTest() {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;

const { document: document1 } = await openNewEditor("hello world");
const { document: document2 } = await openNewEditor("", { openBeside: true });
const { document: document2 } = await openNewEditor("", undefined, true);

await hatTokenMap.allocateHats();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import {
fromVscodeSelection,
getCursorlessApi,
openNewEditor,
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as assert from "assert";
Expand Down Expand Up @@ -52,7 +52,7 @@ async function runTest(
const { hatTokenMap, commandServerApi } = (await getCursorlessApi())
.testHelpers!;

const editor = await openNewEditor("a\n");
const editor = await getReusableEditor("a\n");

editor.selections = [new vscode.Selection(1, 0, 1, 0)];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { getRecordedTestPaths, runRecordedTest } from "@cursorless/node-common";
import {
getCursorlessApi,
openNewEditor,
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as vscode from "vscode";
Expand Down Expand Up @@ -50,15 +50,12 @@ async function openNewTestEditor(
content: string,
languageId: string,
): Promise<TextEditor> {
const { fromVscodeEditor } = (await getCursorlessApi()).testHelpers!;

const editor = await openNewEditor(content, {
languageId,
openBeside: false,
});
const editor = await getReusableEditor(content, languageId);

// Override any user settings and make sure tests run with default tabs.
editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST;

return fromVscodeEditor(editor);
const testHelpers = (await getCursorlessApi()).testHelpers!;

return testHelpers.fromVscodeEditor(editor);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { LATEST_VERSION } from "@cursorless/common";
import { openNewEditor, runCursorlessCommand } from "@cursorless/vscode-common";
import {
getReusableEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import assert from "node:assert";
import * as vscode from "vscode";
import { endToEndTestSetup } from "../endToEndTestSetup";
Expand All @@ -14,7 +17,7 @@ suite("revealRange", async function () {
const content = new Array(100).fill("line").join("\n");

async function preFile() {
const editor = await openNewEditor(content);
const editor = await getReusableEditor(content);
const startLine = editor.document.lineCount - 1;
editor.selections = [new vscode.Selection(startLine, 0, startLine, 0)];
editor.revealRange(new vscode.Range(startLine, 0, startLine, 0));
Expand All @@ -39,7 +42,7 @@ async function preFile() {
}

async function postFile() {
const editor = await openNewEditor(content);
const editor = await getReusableEditor(content);
await vscode.commands.executeCommand("revealLine", {
lineNumber: 1,
at: "top",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ScopeSupportInfo } from "@cursorless/common";
import { ScopeSupport } from "@cursorless/common";
import { getCursorlessApi, openNewEditor } from "@cursorless/vscode-common";
import { getCursorlessApi, getReusableEditor } from "@cursorless/vscode-common";
import * as sinon from "sinon";
import type { TextDocument } from "vscode";
import { Position, Range, commands } from "vscode";
Expand All @@ -21,9 +21,7 @@ export async function runBasicScopeInfoTest() {
try {
await assertCalledWithScopeInfo(fake, unsupported);

const editor = await openNewEditor("", {
languageId: "typescript",
});
const editor = await getReusableEditor("", "typescript");
await assertCalledWithScopeInfo(fake, supported);

await editor.edit((editBuilder) => {
Expand Down
Loading
Loading