@@ -10,8 +10,10 @@ import { Extension } from './extension'
10
10
*
11
11
* This models the state of editor-like tools that display documents, allow selections and scrolling in documents,
12
12
* and support extension configuration.
13
+ *
14
+ * @template X extension type, to support storing additional properties on extensions
13
15
*/
14
- export interface Environment {
16
+ export interface Environment < X extends Extension = Extension > {
15
17
/**
16
18
* The root URI of the environment, or null if there is none (which means the extension is unable to access any
17
19
* documents in the environment).
@@ -26,11 +28,11 @@ export interface Environment {
26
28
readonly component : Component | null
27
29
28
30
/** The active extensions, or null if there are none. */
29
- readonly extensions : Extension [ ] | null
31
+ readonly extensions : X [ ] | null
30
32
}
31
33
32
34
/** An empty CXP environment. */
33
- export const EMPTY_ENVIRONMENT : Environment = { root : null , component : null , extensions : null }
35
+ export const EMPTY_ENVIRONMENT : Environment < any > = { root : null , component : null , extensions : null }
34
36
35
37
/** An application component that displays a [TextDocument](#TextDocument). */
36
38
export interface Component {
@@ -52,9 +54,9 @@ export interface Component {
52
54
*
53
55
* Includes derived observables for convenience.
54
56
*/
55
- export interface ObservableEnvironment {
57
+ export interface ObservableEnvironment < X extends Extension = Extension > {
56
58
/** The environment (and changes to it). */
57
- readonly environment : Observable < Environment > & { readonly value : Environment }
59
+ readonly environment : Observable < Environment < X > > & { readonly value : Environment < X > }
58
60
59
61
/** The environment's root URI (and changes to it). */
60
62
readonly root : Observable < URI | null >
@@ -67,16 +69,16 @@ export interface ObservableEnvironment {
67
69
}
68
70
69
71
/** An ObservableEnvironment that always represents the empty environment and never emits changes. */
70
- export const EMPTY_OBSERVABLE_ENVIRONMENT : ObservableEnvironment = {
72
+ export const EMPTY_OBSERVABLE_ENVIRONMENT : ObservableEnvironment < any > = {
71
73
environment : { ...of ( EMPTY_ENVIRONMENT ) , value : EMPTY_ENVIRONMENT } as ObservableEnvironment [ 'environment' ] ,
72
74
root : of ( null ) ,
73
75
component : of ( null ) ,
74
76
textDocument : of ( null ) ,
75
77
}
76
78
77
- export function createObservableEnvironment (
78
- environment : Observable < Environment > & { readonly value : Environment }
79
- ) : ObservableEnvironment {
79
+ export function createObservableEnvironment < X extends Extension > (
80
+ environment : Observable < Environment < X > > & { readonly value : Environment < X > }
81
+ ) : ObservableEnvironment < X > {
80
82
const component = environment . pipe (
81
83
map ( ( { component } ) => component ) ,
82
84
distinctUntilChanged ( ( a , b ) => isEqual ( a , b ) )
0 commit comments