Skip to content

Commit b9590b4

Browse files
AndreasArvidssonpre-commit-ci-lite[bot]pokey
authored
Move node dependencies out of commons and engine (#2500)
This is all about getting node out of commons. A lot of our file system interaction had to do with running tests and reading/writing test fixtures so I created a separate node test package. To avoid circular dependencies I had to move a bunch of types from the engine to commons. This make it so we now have changes in imports in a bunch of different files. Most of the changes are quite mechanical or boilerplate. The only actual new code is the two storage providers to `ScopeTestRecorder` and `TestCaseRecorder`. The latter one is quite lacking in implementation. This is just about unblocking cursorless everywhere. A better abstraction is something we can workshop together. And before you ask: no I can't split this into smaller pr. It feels like a small miracle that I could solve all of the circular dependency problems I had already :) I wonder if we in a follow up want to move everything test related to the test package? Generally I prefer to have test as close to the source code as possible but in this case it's getting problematic to keeping track of all the dependencies. If we had a test package we could make sure that a lot of the dependencies only existed in that package and we could add lint rules preventing them in the other packages. ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Pokey Rule <[email protected]>
1 parent b708cc4 commit b9590b4

File tree

99 files changed

+449
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+449
-367
lines changed

packages/common/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@
1717
"license": "MIT",
1818
"dependencies": {
1919
"lodash-es": "^4.17.21",
20-
"pathe": "^1.1.2",
2120
"vscode-uri": "^3.0.8"
2221
},
2322
"devDependencies": {
24-
"@types/chai": "^4.3.14",
2523
"@types/js-yaml": "^4.0.9",
2624
"@types/lodash-es": "4.17.0",
2725
"@types/mocha": "^10.0.6",
28-
"@types/sinon": "^17.0.3",
29-
"chai": "^5.1.0",
3026
"cross-spawn": "7.0.3",
3127
"fast-check": "3.17.0",
3228
"js-yaml": "^4.1.0",
33-
"mocha": "^10.3.0",
34-
"sinon": "^17.0.1"
29+
"mocha": "^10.3.0"
3530
},
3631
"types": "./out/index.d.ts",
3732
"exports": {

packages/common/src/ide/normalized/NormalizedIDE.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getFixturePath } from "../../index";
21
import { GeneralizedRange } from "../../types/GeneralizedRange";
32
import { TextEditor } from "../../types/TextEditor";
43
import FakeConfiguration from "../fake/FakeConfiguration";
@@ -17,6 +16,7 @@ export class NormalizedIDE extends PassthroughIDEBase {
1716
original: IDE,
1817
public fakeIde: FakeIDE,
1918
private isSilent: boolean,
19+
private cursorlessSnippetsDir: string,
2020
) {
2121
super(original);
2222

@@ -46,7 +46,7 @@ export class NormalizedIDE extends PassthroughIDEBase {
4646
hatStability: this.configuration.getOwnConfiguration(
4747
"experimental.hatStability",
4848
),
49-
snippetsDir: getFixturePath("cursorless-snippets"),
49+
snippetsDir: this.cursorlessSnippetsDir,
5050
keyboardTargetFollowsSelection: false,
5151
});
5252
}

packages/common/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export * from "./util";
1010
export * from "./ide/util/messages";
1111
export { getKey, splitKey } from "./util/splitKey";
1212
export { hrtimeBigintToSeconds } from "./util/timeUtils";
13-
export * from "./util/walkSync";
14-
export * from "./util/walkAsync";
1513
export * from "./util/disposableFrom";
1614
export * from "./util/camelCaseToAllDown";
1715
export { Notifier } from "./util/Notifier";
@@ -47,11 +45,16 @@ export * from "./types/TextEditorEdit";
4745
export * from "./types/TextEditorOptions";
4846
export * from "./types/TextLine";
4947
export * from "./types/Token";
48+
export * from "./types/SpokenFormType";
5049
export * from "./types/HatTokenMap";
5150
export * from "./types/ScopeProvider";
5251
export * from "./types/SpokenForm";
5352
export * from "./types/commandHistory";
53+
export * from "./types/TalonSpokenForms";
54+
export * from "./types/TestHelpers";
55+
export * from "./types/TreeSitter";
5456
export * from "./util/textFormatters";
57+
export * from "./util/regex";
5558
export * from "./util/serializedMarksToTokenHats";
5659
export * from "./types/snippet.types";
5760
export * from "./testUtil/fromPlainObject";
@@ -61,18 +64,15 @@ export * from "./types/GeneralizedRange";
6164
export * from "./types/RangeOffsets";
6265
export * from "./util/omitByDeep";
6366
export * from "./util/range";
67+
export * from "./util/object";
6468
export * from "./util/uniqWithHash";
6569
export * from "./testUtil/testConstants";
66-
export * from "./testUtil/getFixturePaths";
67-
export * from "./testUtil/getCursorlessRepoRoot";
68-
export * from "./testUtil/runRecordedTest";
6970
export * from "./testUtil/serialize";
7071
export * from "./testUtil/shouldUpdateFixtures";
7172
export * from "./testUtil/TestCaseSnapshot";
7273
export * from "./testUtil/serializeTestFixture";
7374
export * from "./testUtil/getSnapshotForComparison";
7475
export * from "./testUtil/asyncSafety";
75-
export * from "./testUtil/getScopeTestPathsRecursively";
7676
export * from "./util/typeUtils";
7777
export * from "./ide/types/hatStyles.types";
7878
export * from "./errors";

packages/common/src/testUtil/getSnapshotForComparison.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { storedTargetKeys } from "../StoredTargetKey";
22
import SpyIDE from "../ide/spy/SpyIDE";
33
import { ReadOnlyHatMap } from "../types/HatTokenMap";
4+
import type { TestHelpers } from "../types/TestHelpers";
45
import { marksToPlainObject } from "../util/toPlainObject";
56
import { ExcludableSnapshotField, TestCaseSnapshot } from "./TestCaseSnapshot";
67
import { extractTargetedMarks } from "./extractTargetedMarks";
7-
import { TestHelpers } from "./runRecordedTest";
88

99
/**
1010
* Get the state of the editor to compare with the expected state of a test case

packages/cursorless-engine/src/scopeProviders/TalonSpokenForms.ts renamed to packages/common/src/types/TalonSpokenForms.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Notifier } from "@cursorless/common";
2-
import {
3-
SpokenFormMapKeyTypes,
4-
SpokenFormType,
5-
} from "../spokenForms/SpokenFormType";
2+
import { SpokenFormMapKeyTypes, SpokenFormType } from "./SpokenFormType";
63

74
/**
85
* Interface representing a communication mechanism whereby Talon can provide
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { FakeCommandServerApi } from "../FakeCommandServerApi";
2+
import type { IDE } from "../ide/types/ide.types";
3+
import type {
4+
ExcludableSnapshotField,
5+
ExtraSnapshotField,
6+
TestCaseSnapshot,
7+
} from "../testUtil/TestCaseSnapshot";
8+
import type { SerializedMarks, TargetPlainObject } from "../util/toPlainObject";
9+
import type { HatTokenMap } from "./HatTokenMap";
10+
import type { TextEditor } from "./TextEditor";
11+
12+
export interface TestHelpers {
13+
hatTokenMap: HatTokenMap;
14+
15+
// FIXME: Remove this once we have a better way to get this function
16+
// accessible from our tests
17+
takeSnapshot(
18+
excludeFields: ExcludableSnapshotField[],
19+
extraFields: ExtraSnapshotField[],
20+
editor: TextEditor,
21+
ide: IDE,
22+
marks: SerializedMarks | undefined,
23+
): Promise<TestCaseSnapshot>;
24+
25+
setStoredTarget(
26+
editor: TextEditor,
27+
key: string,
28+
targets: TargetPlainObject[] | undefined,
29+
): void;
30+
31+
commandServerApi: FakeCommandServerApi;
32+
}

packages/common/src/types/TextDocument.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export interface TextDocument {
1010
*/
1111
readonly uri: URI;
1212

13+
/**
14+
* The last portion of the uri.path.
15+
*/
16+
readonly filename: string;
17+
1318
/**
1419
* The identifier of the language associated with this document.
1520
*/

0 commit comments

Comments
 (0)