Skip to content
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

Move node dependencies out of commons and engine #2500

Merged
merged 28 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
62ce2d8
refactor
AndreasArvidsson Jul 12, 2024
08de803
test case provider
AndreasArvidsson Jul 12, 2024
824800f
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jul 12, 2024
c4181e9
rename
AndreasArvidsson Jul 12, 2024
13cd65b
rename
AndreasArvidsson Jul 12, 2024
71ce24c
fix import
AndreasArvidsson Jul 12, 2024
035375d
Added dock string
AndreasArvidsson Jul 12, 2024
65d54a2
Fix import
AndreasArvidsson Jul 12, 2024
52da088
clean up
AndreasArvidsson Jul 12, 2024
700ad47
fix import
AndreasArvidsson Jul 12, 2024
2794e79
Added the wait
AndreasArvidsson Jul 12, 2024
d018fd1
Remove unused import
AndreasArvidsson Jul 12, 2024
5aeea77
Remove imports
AndreasArvidsson Jul 12, 2024
7acf1b1
refactor
AndreasArvidsson Jul 12, 2024
19b24fc
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jul 12, 2024
ec6c48b
fix import
AndreasArvidsson Jul 13, 2024
bf96dca
Remove imports
AndreasArvidsson Jul 13, 2024
54ce838
restore comment
AndreasArvidsson Jul 13, 2024
b51f3c3
Fix import#
AndreasArvidsson Jul 13, 2024
80224b0
Fix import
AndreasArvidsson Jul 13, 2024
b72c485
restructure
AndreasArvidsson Jul 13, 2024
eb41192
move regex
AndreasArvidsson Jul 13, 2024
23817e7
Merge branch 'main' into testRecorderProvider
AndreasArvidsson Jul 13, 2024
1229e4b
Move scope test recorder into test package
AndreasArvidsson Jul 13, 2024
f21dc26
assert filename
AndreasArvidsson Jul 13, 2024
cd71783
Cleanup
AndreasArvidsson Jul 13, 2024
15d0850
test for relative in engine
pokey Jul 13, 2024
73a2f35
rename
pokey Jul 13, 2024
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
4 changes: 2 additions & 2 deletions packages/common/src/ide/normalized/NormalizedIDE.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getFixturePath } from "../../index";
import { GeneralizedRange } from "../../types/GeneralizedRange";
import { TextEditor } from "../../types/TextEditor";
import FakeConfiguration from "../fake/FakeConfiguration";
Expand All @@ -17,6 +16,7 @@ export class NormalizedIDE extends PassthroughIDEBase {
original: IDE,
public fakeIde: FakeIDE,
private isSilent: boolean,
private cursorlessSnippetsDir: string,
) {
super(original);

Expand Down Expand Up @@ -46,7 +46,7 @@ export class NormalizedIDE extends PassthroughIDEBase {
hatStability: this.configuration.getOwnConfiguration(
"experimental.hatStability",
),
snippetsDir: getFixturePath("cursorless-snippets"),
snippetsDir: this.cursorlessSnippetsDir,
keyboardTargetFollowsSelection: false,
Copy link
Member Author

@AndreasArvidsson AndreasArvidsson Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation I'm not quite happy with. The problem is that normalized ide is used in the extension bundle and uses a environment fixture path. I will happily take any suggestions here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean NormalizedIDE is really test / dev code, so probalby shouldn't be in engine / common. But I'm ok with this for now

});
}
Expand Down
11 changes: 11 additions & 0 deletions packages/common/src/ide/types/RecordedTestStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { RecordTestCaseCommandOptions } from "../../testUtil/RecordTestCaseCommandOptions";

export interface RecordedTestStorage {
getFixtureRoot(): string | null;
saveTestCase(path: string, fixture: string): Promise<void>;
removeTestCase(filePath: string): Promise<void>;
hasAccess(path: string): Promise<boolean>;
walkDir(dir: string): Promise<string[]>;
calculateFilePath(dir: string, filename: string): Promise<string>;
getCommandOptions(filePath: string): Promise<RecordTestCaseCommandOptions>;
}
8 changes: 8 additions & 0 deletions packages/common/src/ide/types/ScopeTestRecorderStorage.ts
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface ScopeTestRecorderStorage {
getTestedScopeFacets(languageId: string): Set<string>;
saveScopeFacetTest(
languageId: string,
facet: string,
content: string,
): Promise<void>;
}
11 changes: 5 additions & 6 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export * from "./util";
export * from "./ide/util/messages";
export { getKey, splitKey } from "./util/splitKey";
export { hrtimeBigintToSeconds } from "./util/timeUtils";
export * from "./util/walkSync";
export * from "./util/walkAsync";
export * from "./util/disposableFrom";
export * from "./util/camelCaseToAllDown";
export { Notifier } from "./util/Notifier";
Expand All @@ -33,6 +31,8 @@ export * from "./ide/types/Paths";
export * from "./ide/types/CommandHistoryStorage";
export * from "./ide/types/RawTreeSitterQueryProvider";
export * from "./ide/types/FileSystem.types";
export * from "./ide/types/ScopeTestRecorderStorage";
export * from "./ide/types/RecordedTestStorage";
export * from "./types/RangeExpansionBehavior";
export * from "./types/InputBoxOptions";
export * from "./types/Position";
Expand All @@ -51,6 +51,8 @@ export * from "./types/HatTokenMap";
export * from "./types/ScopeProvider";
export * from "./types/SpokenForm";
export * from "./types/commandHistory";
export * from "./types/TalonSpokenForms";
export * from "./types/TestHelpers";
export * from "./util/textFormatters";
export * from "./util/serializedMarksToTokenHats";
export * from "./types/snippet.types";
Expand All @@ -63,16 +65,13 @@ export * from "./util/omitByDeep";
export * from "./util/range";
export * from "./util/uniqWithHash";
export * from "./testUtil/testConstants";
export * from "./testUtil/getFixturePaths";
export * from "./testUtil/getCursorlessRepoRoot";
export * from "./testUtil/runRecordedTest";
export * from "./testUtil/serialize";
export * from "./testUtil/shouldUpdateFixtures";
export * from "./testUtil/TestCaseSnapshot";
export * from "./testUtil/serializeTestFixture";
export * from "./testUtil/getSnapshotForComparison";
export * from "./testUtil/asyncSafety";
export * from "./testUtil/getScopeTestPathsRecursively";
export * from "./testUtil/RecordTestCaseCommandOptions";
export * from "./util/typeUtils";
export * from "./ide/types/hatStyles.types";
export * from "./errors";
Expand Down
52 changes: 52 additions & 0 deletions packages/common/src/testUtil/RecordTestCaseCommandOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ExtraSnapshotField } from "@cursorless/common";

/**
* This is the type of the `recordTestCase` command's argument. It is used to
* specify the options for recording a test case.
*/
export interface RecordTestCaseCommandOptions {
/**
* If this is set to `true`, then for each test case that we record, we expect
* that the user will issue a second command in each phrase, which refers to a
* decorated mark whose range we'd like to check that it got updated properly
* during the previous command. We use this functionality in order to check
* that the token range update works properly. For example, you might say
* `"chuck second car ox air take air"` to check that removing a character
* from a token properly updates the token.
*/
isHatTokenMapTest?: boolean;

/** If true decorations will be added to the test fixture */
isDecorationsTest?: boolean;

/**
* The directory in which to store the test cases that we record. If left out
* the user will be prompted to select a directory within the default recorded
* test case directory.
*/
directory?: string;

/**
* If `true`, don't show a little pop up each time to indicate we've recorded a
* test case
*/
isSilent?: boolean;

extraSnapshotFields?: ExtraSnapshotField[];

/**
* Whether to flash a background for calibrating a video recording
*/
showCalibrationDisplay?: boolean;

/**
* Whether we should record a tests which yield errors in addition to tests
* which do not error.
*/
recordErrors?: boolean;

/**
* Whether to capture the `that` mark returned by the action.
*/
captureFinalThatMark?: boolean;
}
2 changes: 1 addition & 1 deletion packages/common/src/testUtil/getSnapshotForComparison.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { storedTargetKeys } from "../StoredTargetKey";
import SpyIDE from "../ide/spy/SpyIDE";
import { ReadOnlyHatMap } from "../types/HatTokenMap";
import type { TestHelpers } from "../types/TestHelpers";
import { marksToPlainObject } from "../util/toPlainObject";
import { ExcludableSnapshotField, TestCaseSnapshot } from "./TestCaseSnapshot";
import { extractTargetedMarks } from "./extractTargetedMarks";
import { TestHelpers } from "./runRecordedTest";

/**
* Get the state of the editor to compare with the expected state of a test case
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Notifier } from "@cursorless/common";
import {
SpokenFormMapKeyTypes,
SpokenFormType,
} from "../spokenForms/SpokenFormType";
import { SpokenFormMapKeyTypes, SpokenFormType } from "./SpokenFormType";

/**
* Interface representing a communication mechanism whereby Talon can provide
Expand Down
32 changes: 32 additions & 0 deletions packages/common/src/types/TestHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { FakeCommandServerApi } from "../FakeCommandServerApi";
import type { IDE } from "../ide/types/ide.types";
import type {
ExcludableSnapshotField,
ExtraSnapshotField,
TestCaseSnapshot,
} from "../testUtil/TestCaseSnapshot";
import type { SerializedMarks, TargetPlainObject } from "../util/toPlainObject";
import type { HatTokenMap } from "./HatTokenMap";
import type { TextEditor } from "./TextEditor";

export interface TestHelpers {
hatTokenMap: HatTokenMap;

// FIXME: Remove this once we have a better way to get this function
// accessible from our tests
takeSnapshot(
excludeFields: ExcludableSnapshotField[],
extraFields: ExtraSnapshotField[],
editor: TextEditor,
ide: IDE,
marks: SerializedMarks | undefined,
): Promise<TestCaseSnapshot>;

setStoredTarget(
editor: TextEditor,
key: string,
targets: TargetPlainObject[] | undefined,
): void;

commandServerApi: FakeCommandServerApi;
}
1 change: 1 addition & 0 deletions packages/cursorless-cheatsheet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@cursorless/common": "workspace:*",
"@cursorless/node-common": "workspace:*",
"immer": "^10.0.4",
"lodash-es": "^4.17.21",
"node-html-parser": "^6.1.12",
Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-cheatsheet/src/Cheatsheet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCursorlessRepoRoot, type IDE } from "@cursorless/common";
import { type IDE } from "@cursorless/common";
import { getCursorlessRepoRoot } from "@cursorless/node-common";
import { readFile, writeFile } from "node:fs/promises";
import { produce } from "immer";
import { sortBy } from "lodash-es";
Expand Down
3 changes: 3 additions & 0 deletions packages/cursorless-cheatsheet/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"references": [
{
"path": "../common"
},
{
"path": "../node-common"
}
]
}
1 change: 1 addition & 0 deletions packages/cursorless-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"license": "MIT",
"dependencies": {
"@cursorless/common": "workspace:*",
"@cursorless/node-common": "workspace:*",
"glob": "^10.3.10",
"immer": "^10.0.4",
"immutability-helper": "^3.1.1",
Expand Down
35 changes: 8 additions & 27 deletions packages/cursorless-engine/src/ScopeTestRecorder.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import {
ScopeSupportFacetLevel,
getScopeTestPathsRecursively,
getScopeTestsDirPath,
groupBy,
languageScopeSupport,
scopeSupportFacetInfos,
showInfo,
type IDE,
type ScopeSupportFacet,
type ScopeTestRecorderStorage,
} from "@cursorless/common";
import * as fs from "node:fs";
import * as fsPromises from "node:fs/promises";
import * as path from "pathe";

export class ScopeTestRecorder {
constructor(private ide: IDE) {
constructor(
private ide: IDE,
private storage: ScopeTestRecorderStorage,
) {
this.showUnimplementedFacets = this.showUnimplementedFacets.bind(this);
this.saveActiveDocument = this.saveActiveDocument.bind(this);
}
Expand All @@ -27,7 +25,8 @@ export class ScopeTestRecorder {
}

const supportedScopeFacets = getSupportedScopeFacets(languageId);
const existingScopeTestFacets = getExistingScopeFacetTest(languageId);
const existingScopeTestFacets =
this.storage.getTestedScopeFacets(languageId);

const missingScopeFacets = supportedScopeFacets.filter(
(facet) => !existingScopeTestFacets.has(facet),
Expand Down Expand Up @@ -83,20 +82,10 @@ export class ScopeTestRecorder {
facetsToAdd.push({ facet, content });
}

const langDirectory = path.join(getScopeTestsDirPath(), languageId);

await fsPromises.mkdir(langDirectory, { recursive: true });

for (const { facet, content } of facetsToAdd) {
const fullContent = `${content}---\n`;
let filePath = path.join(langDirectory, `${facet}.scope`);
let i = 2;

while (fs.existsSync(filePath)) {
filePath = path.join(langDirectory, `${facet}${i++}.scope`);
}

await fsPromises.writeFile(filePath, fullContent, "utf-8");
this.storage.saveScopeFacetTest(languageId, facet, fullContent);
}

await showInfo(
Expand Down Expand Up @@ -128,11 +117,3 @@ function getSupportedScopeFacets(languageId: string): ScopeSupportFacet[] {
(facet) => scopeSupport[facet] === ScopeSupportFacetLevel.supported,
);
}

function getExistingScopeFacetTest(languageId: string): Set<string> {
const testPaths = getScopeTestPathsRecursively();
const languages = groupBy(testPaths, (test) => test.languageId);
const testPathsForLanguage = languages.get(languageId) ?? [];
const facets = testPathsForLanguage.map((test) => test.facet);
return new Set(facets);
}
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { ScopeRangeProvider } from "./scopeProviders/ScopeRangeProvider";
import { ScopeRangeWatcher } from "./scopeProviders/ScopeRangeWatcher";
import { ScopeSupportChecker } from "./scopeProviders/ScopeSupportChecker";
import { ScopeSupportWatcher } from "./scopeProviders/ScopeSupportWatcher";
import { type TalonSpokenForms } from "./scopeProviders/TalonSpokenForms";
import { type TalonSpokenForms } from "../../common/src/types/TalonSpokenForms";
import { injectIde } from "./singletons/ide.singleton";
import { TreeSitter } from "./typings/TreeSitter";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
SpokenFormEntry,
TalonSpokenForms,
} from "../scopeProviders/TalonSpokenForms";
} from "../../../common/src/types/TalonSpokenForms";

export class DisabledTalonSpokenForms implements TalonSpokenForms {
getSpokenFormEntries(): Promise<SpokenFormEntry[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { SpokenFormGenerator } from "./generateSpokenForm";
import { CustomSpokenFormGenerator } from "../api/CursorlessEngineApi";
import { CustomSpokenForms } from "../spokenForms/CustomSpokenForms";
import { TalonSpokenForms } from "../scopeProviders/TalonSpokenForms";
import { TalonSpokenForms } from "../../../common/src/types/TalonSpokenForms";

/**
* Simple facade that combines the {@link CustomSpokenForms} and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpokenFormMapEntry } from "../spokenForms/SpokenFormMap";
import {
SpokenFormMapKeyTypes,
SpokenFormType,
} from "../spokenForms/SpokenFormType";
} from "../../../common/src/types/SpokenFormType";

/**
* A component of a spoken form used internally during spoken form generation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompositeKeyMap } from "@cursorless/common";
import { SpeakableSurroundingPairName } from "../../spokenForms/SpokenFormType";
import { SpeakableSurroundingPairName } from "../../../../common/src/types/SpokenFormType";
import { SpokenFormComponentMap } from "../getSpokenFormComponentMap";
import { CustomizableSpokenFormComponentForType } from "../SpokenFormComponent";
import { surroundingPairsDelimiters } from "./surroundingPairsDelimiters";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SpeakableSurroundingPairName } from "../../spokenForms/SpokenFormType";
import { SpeakableSurroundingPairName } from "../../../../common/src/types/SpokenFormType";

export const surroundingPairsDelimiters: Record<
SpeakableSurroundingPairName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
TestCaseFixtureLegacy,
getRecordedTestPaths,
serializeTestFixture,
shouldUpdateFixtures,
} from "@cursorless/common";
import { getRecordedTestPaths } from "@cursorless/node-common";
import * as yaml from "js-yaml";
import assert from "node:assert";
import { promises as fsp } from "node:fs";
import { canonicalizeAndValidateCommand } from "../core/commandVersionUpgrades/canonicalizeAndValidateCommand";
import { getHatMapCommand } from "./getHatMapCommand";
import { SpokenFormGenerator } from ".";
import { defaultSpokenFormInfoMap } from "../spokenForms/defaultSpokenFormMap";
import { canonicalizeAndValidateCommand } from "../core/commandVersionUpgrades/canonicalizeAndValidateCommand";
import { SpokenFormMap, mapSpokenForms } from "../spokenForms/SpokenFormMap";
import { defaultSpokenFormInfoMap } from "../spokenForms/defaultSpokenFormMap";
import { getHatMapCommand } from "./getHatMapCommand";

/**
* A spoken form map to use for testing. Just uses default spoken forms, but
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
PartialSpokenFormTypes,
SpokenFormMapKeyTypes,
SpokenFormType,
} from "../spokenForms/SpokenFormType";
} from "../../../common/src/types/SpokenFormType";
import { CustomizableSpokenFormComponentForType } from "./SpokenFormComponent";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/index.ts
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export * from "./CommandHistory";
export * from "./CommandHistoryAnalyzer";
export * from "./util/grammarHelpers";
export * from "./ScopeTestRecorder";
export * from "./scopeProviders/TalonSpokenForms";
export * from "../../common/src/types/TalonSpokenForms";
export * from "./core/Snippets";
export * from "./core/mergeSnippets";
export * from "./util/object";
Loading
Loading