Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jul 11, 2024
1 parent 0a70357 commit 8ff20e5
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 13 deletions.
14 changes: 8 additions & 6 deletions packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
FileSystem,
Hats,
IDE,
ensureCommandShape,
ScopeProvider,
ensureCommandShape,
} from "@cursorless/common";
import { KeyboardTargetUpdater } from "./KeyboardTargetUpdater";
import {
CommandRunnerDecorator,
CursorlessEngine,
Expand All @@ -18,7 +19,6 @@ import { StoredTargetMap } from "./core/StoredTargets";
import { RangeUpdater } from "./core/updateSelections/RangeUpdater";
import { CustomSpokenFormGeneratorImpl } from "./generateSpokenForm/CustomSpokenFormGeneratorImpl";
import { LanguageDefinitions } from "./languages/LanguageDefinitions";
import { TalonSpokenFormsJsonReader } from "./nodeCommon/TalonSpokenFormsJsonReader";
import { ModifierStageFactoryImpl } from "./processTargets/ModifierStageFactoryImpl";
import { ScopeHandlerFactoryImpl } from "./processTargets/modifiers/scopeHandlers";
import { runCommand } from "./runCommand";
Expand All @@ -28,16 +28,20 @@ import { ScopeRangeProvider } from "./scopeProviders/ScopeRangeProvider";
import { ScopeRangeWatcher } from "./scopeProviders/ScopeRangeWatcher";
import { ScopeSupportChecker } from "./scopeProviders/ScopeSupportChecker";
import { ScopeSupportWatcher } from "./scopeProviders/ScopeSupportWatcher";
import {
DisabledTalonSpokenForms,
type TalonSpokenForms,
} from "./scopeProviders/TalonSpokenForms";
import { injectIde } from "./singletons/ide.singleton";
import { TreeSitter } from "./typings/TreeSitter";
import { KeyboardTargetUpdater } from "./KeyboardTargetUpdater";

export async function createCursorlessEngine(
treeSitter: TreeSitter,
ide: IDE,
hats: Hats,
commandServerApi: CommandServerApi | null,
fileSystem: FileSystem,
talonSpokenForms: TalonSpokenForms | undefined,
): Promise<CursorlessEngine> {
injectIde(ide);

Expand All @@ -63,10 +67,8 @@ export async function createCursorlessEngine(
const languageDefinitions = new LanguageDefinitions(fileSystem, treeSitter);
await languageDefinitions.init();

const talonSpokenForms = new TalonSpokenFormsJsonReader(fileSystem);

const customSpokenFormGenerator = new CustomSpokenFormGeneratorImpl(
talonSpokenForms,
talonSpokenForms ?? new DisabledTalonSpokenForms(),
);

ide.disposeOnExit(
Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from "./CommandHistory";
export * from "./CommandHistoryAnalyzer";
export * from "./util/grammarHelpers";
export * from "./ScopeTestRecorder";
export * from "./scopeProviders/TalonSpokenForms";
3 changes: 0 additions & 3 deletions packages/cursorless-engine/src/nodeCommon/README.md

This file was deleted.

10 changes: 10 additions & 0 deletions packages/cursorless-engine/src/scopeProviders/TalonSpokenForms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ export interface TalonSpokenForms {
onDidChange: Notifier["registerListener"];
}

export class DisabledTalonSpokenForms implements TalonSpokenForms {
getSpokenFormEntries() {
return Promise.resolve([]);
}

onDidChange() {
return { dispose: () => {} };
}
}

/**
* The types of entries for which we currently support getting custom spoken
* forms from Talon.
Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@
"dependencies": {
"@cursorless/common": "workspace:*",
"@cursorless/cursorless-engine": "workspace:*",
"@cursorless/node-common": "workspace:*",
"@cursorless/vscode-common": "workspace:*",
"immer": "^10.0.4",
"itertools": "^2.2.5",
Expand Down
3 changes: 3 additions & 0 deletions packages/cursorless-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
import { StatusBarItem } from "./StatusBarItem";
import { storedTargetHighlighter } from "./storedTargetHighlighter";
import { vscodeApi } from "./vscodeApi";
import { TalonSpokenFormsJsonReader } from "@cursorless/node-common";

/**
* Extension entrypoint called by VSCode on Cursorless startup.
Expand Down Expand Up @@ -82,6 +83,7 @@ export async function activate(
: await getCommandServerApi();

const treeSitter: TreeSitter = createTreeSitter(parseTreeApi);
const talonSpokenForms = new TalonSpokenFormsJsonReader(fileSystem);

const {
commandApi,
Expand All @@ -99,6 +101,7 @@ export async function activate(
hats,
commandServerApi,
fileSystem,
talonSpokenForms,
);

addCommandRunnerDecorator(
Expand Down
3 changes: 3 additions & 0 deletions packages/cursorless-vscode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{
"path": "../cursorless-engine"
},
{
"path": "../node-common"
},
{
"path": "../vscode-common"
}
Expand Down
30 changes: 30 additions & 0 deletions packages/node-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@cursorless/node-common",
"version": "1.0.0",
"description": "Cursorless common utilities for node",
"main": "./out/index.js",
"scripts": {
"compile:tsc": "tsc --build",
"compile:esbuild": "esbuild ./src/index.ts --sourcemap --format=esm --bundle --packages=external --outfile=./out/index.js",
"compile": "pnpm compile:tsc && pnpm compile:esbuild",
"watch:tsc": "pnpm compile:tsc --watch",
"watch:esbuild": "pnpm compile:esbuild --watch",
"watch": "pnpm run --filter @cursorless/node-common --parallel '/^watch:.*/'",
"clean": "rm -rf ./out tsconfig.tsbuildinfo ./dist ./build"
},
"keywords": [],
"author": "",
"license": "MIT",
"type": "module",
"types": "./out/index.d.ts",
"exports": {
".": {
"cursorless:bundler": "./src/index.ts",
"default": "./out/index.js"
}
},
"dependencies": {
"@cursorless/common": "workspace:*",
"@cursorless/cursorless-engine": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Disposable, FileSystem, Notifier } from "@cursorless/common";
import {
Disposable,
FileSystem,
Notifier,
type Listener,
} from "@cursorless/common";
import { readFile } from "fs/promises";

import * as path from "path";
import {
NeedsInitialTalonUpdateError,
SpokenFormEntry,
TalonSpokenForms,
} from "../scopeProviders/TalonSpokenForms";
} from "@cursorless/cursorless-engine";
import * as path from "path";

interface TalonSpokenFormsPayload {
version: number;
Expand All @@ -31,7 +36,9 @@ export class TalonSpokenFormsJsonReader implements TalonSpokenForms {
* @param callback The callback to run when the scope ranges change
* @returns A {@link Disposable} which will stop the callback from running
*/
onDidChange = this.notifier.registerListener;
onDidChange(listener: Listener) {
return this.notifier.registerListener(listener);
}

async getSpokenFormEntries(): Promise<SpokenFormEntry[]> {
let payload: TalonSpokenFormsPayload;
Expand Down
1 change: 1 addition & 0 deletions packages/node-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./TalonSpokenFormsJsonReader";
17 changes: 17 additions & 0 deletions packages/node-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "es2020",
"rootDir": "src",
"outDir": "out"
},
"references": [
{
"path": "../common"
},
{
"path": "../cursorless-engine"
}
],
"include": ["src/**/*.ts", "src/**/*.json", "../../typings/**/*.d.ts"]
}
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
{
"path": "./packages/meta-updater"
},
{
"path": "./packages/node-common"
},
{
"path": "./packages/test-harness"
},
Expand Down

0 comments on commit 8ff20e5

Please sign in to comment.