Skip to content

Expose shape enablement #287

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

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 10 additions & 1 deletion src/core/Decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DEFAULT_HAT_HEIGHT_EM,
DEFAULT_VERTICAL_OFFSET_EM,
} from "./shapeAdjustments";
import { CommandServerApi } from "../util/getExtensionApi";

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

constructor(
fontMeasurements: FontMeasurements,
private extensionPath: string
private extensionPath: string,
private commandServerApi: CommandServerApi | null
) {
this.constructDecorations(fontMeasurements);
}
Expand Down Expand Up @@ -154,6 +156,13 @@ export default class Decorations {
(shape) => shapeEnablement[shape]
);

if (this.commandServerApi != null) {
this.commandServerApi.globalState.update("cursorless.hatEnablement", {
colors: activeHatColors.filter((color) => color !== "default"),
shapes: activeNonDefaultHatShapes,
});
}

this.hatStyleMap = {
...Object.fromEntries(
activeHatColors.map((color) => [color, { color, shape: "default" }])
Expand Down
13 changes: 9 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ import { logBranchTypes } from "./util/debug";
import { TestCase } from "./testUtil/TestCase";
import { ThatMark } from "./core/ThatMark";
import { TestCaseRecorder } from "./testUtil/TestCaseRecorder";
import { getParseTreeApi } from "./util/getExtensionApi";
import { getCommandServerApi, getParseTreeApi } from "./util/getExtensionApi";
import { canonicalizeAndValidateCommand } from "./util/canonicalizeAndValidateCommand";
import canonicalizeActionName from "./util/canonicalizeActionName";

export async function activate(context: vscode.ExtensionContext) {
const { getNodeAtLocation } = await getParseTreeApi();
const commandServerApi = await getCommandServerApi();

const fontMeasurements = new FontMeasurements(context);
await fontMeasurements.calculate();
const decorations = new Decorations(fontMeasurements, context.extensionPath);

const { getNodeAtLocation } = await getParseTreeApi();
const decorations = new Decorations(
fontMeasurements,
context.extensionPath,
commandServerApi
);

var isActive = vscode.workspace
.getConfiguration("cursorless")
Expand Down
22 changes: 20 additions & 2 deletions src/util/getExtensionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ export interface ParseTreeApi {
loadLanguage: (languageId: string) => Promise<boolean>;
}

export interface CommandServerApi {
globalState: vscode.Memento;
workspaceState: vscode.Memento;
}

export async function getExtensionApi<T>(extensionId: string) {
const extension = vscode.extensions.getExtension(extensionId);

return extension == null ? null : ((await extension.activate()) as T);
}

export async function getExtensionApiStrict<T>(extensionId: string) {
const extension = vscode.extensions.getExtension(extensionId);

if (extension == null) {
throw new Error(`Could not get ${extensionId} extension`);
}
Expand All @@ -26,7 +37,14 @@ export async function getExtensionApi<T>(extensionId: string) {
}

export const getCursorlessApi = () =>
getExtensionApi<CursorlessApi>("pokey.cursorless");
getExtensionApiStrict<CursorlessApi>("pokey.cursorless");

export const getParseTreeApi = () =>
getExtensionApi<ParseTreeApi>("pokey.parse-tree");
getExtensionApiStrict<ParseTreeApi>("pokey.parse-tree");

/**
*
* @returns Command server API or null if not installed
*/
export const getCommandServerApi = () =>
getExtensionApi<CommandServerApi>("pokey.command-server");