File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 DEFAULT_HAT_HEIGHT_EM ,
2020 DEFAULT_VERTICAL_OFFSET_EM ,
2121} from "./shapeAdjustments" ;
22+ import { CommandServerApi } from "../util/getExtensionApi" ;
2223
2324export 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" } ] )
Original file line number Diff line number Diff line change @@ -17,16 +17,21 @@ import { logBranchTypes } from "./util/debug";
1717import { TestCase } from "./testUtil/TestCase" ;
1818import { ThatMark } from "./core/ThatMark" ;
1919import { TestCaseRecorder } from "./testUtil/TestCaseRecorder" ;
20- import { getParseTreeApi } from "./util/getExtensionApi" ;
20+ import { getCommandServerApi , getParseTreeApi } from "./util/getExtensionApi" ;
2121import { canonicalizeAndValidateCommand } from "./util/canonicalizeAndValidateCommand" ;
2222import canonicalizeActionName from "./util/canonicalizeActionName" ;
2323
2424export async function activate ( context : vscode . ExtensionContext ) {
25+ const { getNodeAtLocation } = await getParseTreeApi ( ) ;
26+ const commandServerApi = await getCommandServerApi ( ) ;
27+
2528 const fontMeasurements = new FontMeasurements ( context ) ;
2629 await fontMeasurements . calculate ( ) ;
27- const decorations = new Decorations ( fontMeasurements , context . extensionPath ) ;
28-
29- const { getNodeAtLocation } = await getParseTreeApi ( ) ;
30+ const decorations = new Decorations (
31+ fontMeasurements ,
32+ context . extensionPath ,
33+ commandServerApi
34+ ) ;
3035
3136 var isActive = vscode . workspace
3237 . getConfiguration ( "cursorless" )
Original file line number Diff line number Diff 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+
1823export 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
2839export const getCursorlessApi = ( ) =>
29- getExtensionApi < CursorlessApi > ( "pokey.cursorless" ) ;
40+ getExtensionApiStrict < CursorlessApi > ( "pokey.cursorless" ) ;
3041
3142export 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" ) ;
You can’t perform that action at this time.
0 commit comments