Skip to content

Commit a09d865

Browse files
committed
Initial work
1 parent 335fef1 commit a09d865

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/core/Decorations.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
DEFAULT_HAT_HEIGHT_EM,
2020
DEFAULT_VERTICAL_OFFSET_EM,
2121
} from "./shapeMeasurements";
22+
import { CommandServerApi } from "../util/getExtensionApi";
2223

2324
export type DecorationMap = {
2425
[k in HatStyleName]?: vscode.TextEditorDecorationType;
@@ -37,7 +38,8 @@ export default class Decorations {
3738

3839
constructor(
3940
fontMeasurements: FontMeasurements,
40-
private extensionPath: string
41+
private extensionPath: string,
42+
private commandServerApi: CommandServerApi | null
4143
) {
4244
this.constructDecorations(fontMeasurements);
4345
}
@@ -154,6 +156,13 @@ export default class Decorations {
154156
(shape) => shapeEnablement[shape]
155157
);
156158

159+
if (this.commandServerApi != null) {
160+
this.commandServerApi.globalState.update("cursorless.hatEnablement", {
161+
colors: activeHatColors.filter((color) => color !== "default"),
162+
shapes: activeNonDefaultHatShapes,
163+
});
164+
}
165+
157166
this.hatStyleMap = {
158167
...Object.fromEntries(
159168
activeHatColors.map((color) => [color, { color, shape: "default" }])

src/extension.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ import { logBranchTypes } from "./util/debug";
1616
import { TestCase } from "./testUtil/TestCase";
1717
import { ThatMark } from "./core/ThatMark";
1818
import { TestCaseRecorder } from "./testUtil/TestCaseRecorder";
19-
import { getParseTreeApi } from "./util/getExtensionApi";
19+
import { getCommandServerApi, getParseTreeApi } from "./util/getExtensionApi";
2020
import { canonicalizeAndValidateCommand } from "./canonicalizeAndValidateCommand";
2121
import canonicalizeActionName from "./canonicalizeActionName";
2222

2323
export async function activate(context: vscode.ExtensionContext) {
24+
const { getNodeAtLocation } = await getParseTreeApi();
25+
const commandServerApi = await getCommandServerApi();
26+
2427
const fontMeasurements = new FontMeasurements(context);
2528
await fontMeasurements.calculate();
26-
const decorations = new Decorations(fontMeasurements, context.extensionPath);
27-
28-
const { getNodeAtLocation } = await getParseTreeApi();
29+
const decorations = new Decorations(
30+
fontMeasurements,
31+
context.extensionPath,
32+
commandServerApi
33+
);
2934

3035
var isActive = vscode.workspace
3136
.getConfiguration("cursorless")

src/util/getExtensionApi.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ export interface ParseTreeApi {
1515
loadLanguage: (languageId: string) => Promise<boolean>;
1616
}
1717

18+
export interface CommandServerApi {
19+
globalState: vscode.Memento;
20+
workspaceState: vscode.Memento;
21+
}
22+
1823
export async function getExtensionApi<T>(extensionId: string) {
1924
const extension = vscode.extensions.getExtension(extensionId);
2025

26+
return extension == null ? null : ((await extension.activate()) as T);
27+
}
28+
29+
export async function getExtensionApiStrict<T>(extensionId: string) {
30+
const extension = vscode.extensions.getExtension(extensionId);
31+
2132
if (extension == null) {
2233
throw new Error(`Could not get ${extensionId} extension`);
2334
}
@@ -26,7 +37,14 @@ export async function getExtensionApi<T>(extensionId: string) {
2637
}
2738

2839
export const getCursorlessApi = () =>
29-
getExtensionApi<CursorlessApi>("pokey.cursorless");
40+
getExtensionApiStrict<CursorlessApi>("pokey.cursorless");
3041

3142
export const getParseTreeApi = () =>
32-
getExtensionApi<ParseTreeApi>("pokey.parse-tree");
43+
getExtensionApiStrict<ParseTreeApi>("pokey.parse-tree");
44+
45+
/**
46+
*
47+
* @returns Command server API or null if not installed
48+
*/
49+
export const getCommandServerApi = () =>
50+
getExtensionApi<CommandServerApi>("pokey.command-server");

0 commit comments

Comments
 (0)