File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
19
19
DEFAULT_HAT_HEIGHT_EM ,
20
20
DEFAULT_VERTICAL_OFFSET_EM ,
21
21
} from "./shapeMeasurements" ;
22
+ import { CommandServerApi } from "../util/getExtensionApi" ;
22
23
23
24
export type DecorationMap = {
24
25
[ k in HatStyleName ] ?: vscode . TextEditorDecorationType ;
@@ -37,7 +38,8 @@ export default class Decorations {
37
38
38
39
constructor (
39
40
fontMeasurements : FontMeasurements ,
40
- private extensionPath : string
41
+ private extensionPath : string ,
42
+ private commandServerApi : CommandServerApi | null
41
43
) {
42
44
this . constructDecorations ( fontMeasurements ) ;
43
45
}
@@ -154,6 +156,13 @@ export default class Decorations {
154
156
( shape ) => shapeEnablement [ shape ]
155
157
) ;
156
158
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
+
157
166
this . hatStyleMap = {
158
167
...Object . fromEntries (
159
168
activeHatColors . map ( ( color ) => [ color , { color, shape : "default" } ] )
Original file line number Diff line number Diff line change @@ -16,16 +16,21 @@ import { logBranchTypes } from "./util/debug";
16
16
import { TestCase } from "./testUtil/TestCase" ;
17
17
import { ThatMark } from "./core/ThatMark" ;
18
18
import { TestCaseRecorder } from "./testUtil/TestCaseRecorder" ;
19
- import { getParseTreeApi } from "./util/getExtensionApi" ;
19
+ import { getCommandServerApi , getParseTreeApi } from "./util/getExtensionApi" ;
20
20
import { canonicalizeAndValidateCommand } from "./canonicalizeAndValidateCommand" ;
21
21
import canonicalizeActionName from "./canonicalizeActionName" ;
22
22
23
23
export async function activate ( context : vscode . ExtensionContext ) {
24
+ const { getNodeAtLocation } = await getParseTreeApi ( ) ;
25
+ const commandServerApi = await getCommandServerApi ( ) ;
26
+
24
27
const fontMeasurements = new FontMeasurements ( context ) ;
25
28
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
+ ) ;
29
34
30
35
var isActive = vscode . workspace
31
36
. getConfiguration ( "cursorless" )
Original file line number Diff line number Diff line change @@ -15,9 +15,20 @@ export interface ParseTreeApi {
15
15
loadLanguage : ( languageId : string ) => Promise < boolean > ;
16
16
}
17
17
18
+ export interface CommandServerApi {
19
+ globalState : vscode . Memento ;
20
+ workspaceState : vscode . Memento ;
21
+ }
22
+
18
23
export async function getExtensionApi < T > ( extensionId : string ) {
19
24
const extension = vscode . extensions . getExtension ( extensionId ) ;
20
25
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
+
21
32
if ( extension == null ) {
22
33
throw new Error ( `Could not get ${ extensionId } extension` ) ;
23
34
}
@@ -26,7 +37,14 @@ export async function getExtensionApi<T>(extensionId: string) {
26
37
}
27
38
28
39
export const getCursorlessApi = ( ) =>
29
- getExtensionApi < CursorlessApi > ( "pokey.cursorless" ) ;
40
+ getExtensionApiStrict < CursorlessApi > ( "pokey.cursorless" ) ;
30
41
31
42
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" ) ;
You can’t perform that action at this time.
0 commit comments