@@ -101,7 +101,8 @@ export interface RuntimeEnvironment {
101101}
102102
103103export interface TelemetryService {
104- send ( arg : { name : string ; properties ?: unknown } ) ;
104+ send ( arg : { name : string ; properties ?: unknown } ) : Promise < void > ;
105+ sendStartupEvent ( ) : Promise < void > ;
105106}
106107
107108export function startClient (
@@ -148,62 +149,67 @@ export function startClient(
148149 ) ;
149150
150151 findConflicts ( ) ;
151- client . onReady ( ) . then ( ( ) => {
152- // Send a notification to the server with any YAML schema associations in all extensions
153- client . sendNotification ( SchemaAssociationNotification . type , getSchemaAssociations ( ) ) ;
154-
155- // If the extensions change, fire this notification again to pick up on any association changes
156- extensions . onDidChange ( ( ) => {
152+ client
153+ . onReady ( )
154+ . then ( ( ) => {
155+ // Send a notification to the server with any YAML schema associations in all extensions
157156 client . sendNotification ( SchemaAssociationNotification . type , getSchemaAssociations ( ) ) ;
158- findConflicts ( ) ;
159- } ) ;
160- // Tell the server that the client is ready to provide custom schema content
161- client . sendNotification ( DynamicCustomSchemaRequestRegistration . type ) ;
162- // Tell the server that the client supports schema requests sent directly to it
163- client . sendNotification ( VSCodeContentRequestRegistration . type ) ;
164- // Tell the server that the client supports schema selection requests
165- client . sendNotification ( SchemaSelectionRequests . type ) ;
166- // If the server asks for custom schema content, get it and send it back
167- client . onRequest ( CUSTOM_SCHEMA_REQUEST , ( resource : string ) => {
168- return schemaExtensionAPI . requestCustomSchema ( resource ) ;
169- } ) ;
170- client . onRequest ( CUSTOM_CONTENT_REQUEST , ( uri : string ) => {
171- return schemaExtensionAPI . requestCustomSchemaContent ( uri ) ;
172- } ) ;
173- client . onRequest ( VSCodeContentRequest . type , ( uri : string ) => {
174- return getJsonSchemaContent ( uri , runtime . schemaCache ) ;
175- } ) ;
176- client . onRequest ( FSReadFile . type , ( fsPath : string ) => {
177- return workspace . fs . readFile ( Uri . file ( fsPath ) ) . then ( ( uint8array ) => new TextDecoder ( ) . decode ( uint8array ) ) ;
178- } ) ;
179157
180- runtime . telemetry . send ( { name : 'yaml.server.initialized' } ) ;
181- // Adapted from:
182- // https://github.com/microsoft/vscode/blob/94c9ea46838a9a619aeafb7e8afd1170c967bb55/extensions/json-language-features/client/src/jsonClient.ts#L305-L318
183- client . onNotification ( ResultLimitReachedNotification . type , async ( message ) => {
184- const shouldPrompt = context . globalState . get < boolean > ( StorageIds . maxItemsExceededInformation ) !== false ;
185- if ( shouldPrompt ) {
186- const ok = 'Ok' ;
187- const openSettings = 'Open Settings' ;
188- const neverAgain = "Don't Show Again" ;
189- const pick = await window . showInformationMessage (
190- `${ message } \nUse setting '${ SettingIds . maxItemsComputed } ' to configure the limit.` ,
191- ok ,
192- openSettings ,
193- neverAgain
194- ) ;
195- if ( pick === neverAgain ) {
196- await context . globalState . update ( StorageIds . maxItemsExceededInformation , false ) ;
197- } else if ( pick === openSettings ) {
198- await commands . executeCommand ( 'workbench.action.openSettings' , SettingIds . maxItemsComputed ) ;
158+ // If the extensions change, fire this notification again to pick up on any association changes
159+ extensions . onDidChange ( ( ) => {
160+ client . sendNotification ( SchemaAssociationNotification . type , getSchemaAssociations ( ) ) ;
161+ findConflicts ( ) ;
162+ } ) ;
163+ // Tell the server that the client is ready to provide custom schema content
164+ client . sendNotification ( DynamicCustomSchemaRequestRegistration . type ) ;
165+ // Tell the server that the client supports schema requests sent directly to it
166+ client . sendNotification ( VSCodeContentRequestRegistration . type ) ;
167+ // Tell the server that the client supports schema selection requests
168+ client . sendNotification ( SchemaSelectionRequests . type ) ;
169+ // If the server asks for custom schema content, get it and send it back
170+ client . onRequest ( CUSTOM_SCHEMA_REQUEST , ( resource : string ) => {
171+ return schemaExtensionAPI . requestCustomSchema ( resource ) ;
172+ } ) ;
173+ client . onRequest ( CUSTOM_CONTENT_REQUEST , ( uri : string ) => {
174+ return schemaExtensionAPI . requestCustomSchemaContent ( uri ) ;
175+ } ) ;
176+ client . onRequest ( VSCodeContentRequest . type , ( uri : string ) => {
177+ return getJsonSchemaContent ( uri , runtime . schemaCache ) ;
178+ } ) ;
179+ client . onRequest ( FSReadFile . type , ( fsPath : string ) => {
180+ return workspace . fs . readFile ( Uri . file ( fsPath ) ) . then ( ( uint8array ) => new TextDecoder ( ) . decode ( uint8array ) ) ;
181+ } ) ;
182+
183+ sendStartupTelemetryEvent ( runtime . telemetry , true ) ;
184+ // Adapted from:
185+ // https://github.com/microsoft/vscode/blob/94c9ea46838a9a619aeafb7e8afd1170c967bb55/extensions/json-language-features/client/src/jsonClient.ts#L305-L318
186+ client . onNotification ( ResultLimitReachedNotification . type , async ( message ) => {
187+ const shouldPrompt = context . globalState . get < boolean > ( StorageIds . maxItemsExceededInformation ) !== false ;
188+ if ( shouldPrompt ) {
189+ const ok = 'Ok' ;
190+ const openSettings = 'Open Settings' ;
191+ const neverAgain = "Don't Show Again" ;
192+ const pick = await window . showInformationMessage (
193+ `${ message } \nUse setting '${ SettingIds . maxItemsComputed } ' to configure the limit.` ,
194+ ok ,
195+ openSettings ,
196+ neverAgain
197+ ) ;
198+ if ( pick === neverAgain ) {
199+ await context . globalState . update ( StorageIds . maxItemsExceededInformation , false ) ;
200+ } else if ( pick === openSettings ) {
201+ await commands . executeCommand ( 'workbench.action.openSettings' , SettingIds . maxItemsComputed ) ;
202+ }
199203 }
200- }
201- } ) ;
204+ } ) ;
202205
203- client . onNotification ( SchemaSelectionRequests . schemaStoreInitialized , ( ) => {
204- createJSONSchemaStatusBarItem ( context , client ) ;
206+ client . onNotification ( SchemaSelectionRequests . schemaStoreInitialized , ( ) => {
207+ createJSONSchemaStatusBarItem ( context , client ) ;
208+ } ) ;
209+ } )
210+ . catch ( ( err ) => {
211+ sendStartupTelemetryEvent ( runtime . telemetry , false , err ) ;
205212 } ) ;
206- } ) ;
207213
208214 return schemaExtensionAPI ;
209215}
@@ -257,6 +263,19 @@ function getSchemaAssociations(): ISchemaAssociation[] {
257263 return associations ;
258264}
259265
266+ async function sendStartupTelemetryEvent ( telemetry : TelemetryService , initialized : boolean , err ?: Error ) : Promise < void > {
267+ const startUpEvent = {
268+ name : 'startup' ,
269+ properties : {
270+ 'yaml.server.initialized' : initialized ,
271+ } ,
272+ } ;
273+ if ( err ?. message ) {
274+ startUpEvent . properties [ 'error' ] = err . message ;
275+ }
276+ await telemetry . send ( startUpEvent ) ;
277+ }
278+
260279export function logToExtensionOutputChannel ( message : string ) : void {
261280 client . outputChannel . appendLine ( message ) ;
262281}
0 commit comments