@@ -17,8 +17,8 @@ import fs = require('fs');
1717import URI from 'vscode-uri' ;
1818import * as URL from 'url' ;
1919import Strings = require( './utils/strings' ) ;
20- import { formatError , runSafe } from './utils/errors' ;
21- import { JSONDocument , JSONSchema , LanguageSettings , getLanguageService , DocumentLanguageSettings } from 'vscode-json-languageservice' ;
20+ import { formatError , runSafe , runSafeAsync } from './utils/errors' ;
21+ import { JSONDocument , JSONSchema , getLanguageService , DocumentLanguageSettings , SchemaConfiguration } from 'vscode-json-languageservice' ;
2222import { getLanguageModelCache } from './languageModelCache' ;
2323
2424interface ISchemaAssociations {
@@ -40,7 +40,7 @@ namespace SchemaContentChangeNotification {
4040// Create a connection for the server
4141let connection : IConnection = createConnection ( ) ;
4242
43- process . on ( 'unhandledRejection' , e => {
43+ process . on ( 'unhandledRejection' , ( e : any ) => {
4444 connection . console . error ( formatError ( `Unhandled exception` , e ) ) ;
4545} ) ;
4646
@@ -62,7 +62,7 @@ let clientDynamicRegisterSupport = false;
6262connection . onInitialize ( ( params : InitializeParams ) : InitializeResult => {
6363
6464 function hasClientCapability ( ...keys : string [ ] ) {
65- let c = params . capabilities ;
65+ let c = params . capabilities as any ;
6666 for ( let i = 0 ; c && i < keys . length ; i ++ ) {
6767 c = c [ keys [ i ] ] ;
6868 }
@@ -146,9 +146,9 @@ interface JSONSchemaSettings {
146146 schema ?: JSONSchema ;
147147}
148148
149- let jsonConfigurationSettings : JSONSchemaSettings [ ] = void 0 ;
150- let schemaAssociations : ISchemaAssociations = void 0 ;
151- let formatterRegistration : Thenable < Disposable > = null ;
149+ let jsonConfigurationSettings : JSONSchemaSettings [ ] | undefined = void 0 ;
150+ let schemaAssociations : ISchemaAssociations | undefined = void 0 ;
151+ let formatterRegistration : Thenable < Disposable > | null = null ;
152152
153153// The settings have changed. Is send on server activation as well.
154154connection . onDidChangeConfiguration ( ( change ) => {
@@ -184,10 +184,10 @@ connection.onNotification(SchemaContentChangeNotification.type, uri => {
184184} ) ;
185185
186186function updateConfiguration ( ) {
187- let languageSettings : LanguageSettings = {
187+ let languageSettings = {
188188 validate : true ,
189189 allowComments : true ,
190- schemas : [ ]
190+ schemas : new Array < SchemaConfiguration > ( )
191191 } ;
192192 if ( schemaAssociations ) {
193193 for ( var pattern in schemaAssociations ) {
@@ -292,21 +292,21 @@ function getJSONDocument(document: TextDocument): JSONDocument {
292292}
293293
294294connection . onCompletion ( textDocumentPosition => {
295- return runSafe ( ( ) => {
295+ return runSafeAsync ( ( ) => {
296296 let document = documents . get ( textDocumentPosition . textDocument . uri ) ;
297297 let jsonDocument = getJSONDocument ( document ) ;
298298 return languageService . doComplete ( document , textDocumentPosition . position , jsonDocument ) ;
299299 } , null , `Error while computing completions for ${ textDocumentPosition . textDocument . uri } ` ) ;
300300} ) ;
301301
302302connection . onCompletionResolve ( completionItem => {
303- return runSafe ( ( ) => {
303+ return runSafeAsync ( ( ) => {
304304 return languageService . doResolve ( completionItem ) ;
305- } , null , `Error while resolving completion proposal` ) ;
305+ } , completionItem , `Error while resolving completion proposal` ) ;
306306} ) ;
307307
308308connection . onHover ( textDocumentPositionParams => {
309- return runSafe ( ( ) => {
309+ return runSafeAsync ( ( ) => {
310310 let document = documents . get ( textDocumentPositionParams . textDocument . uri ) ;
311311 let jsonDocument = getJSONDocument ( document ) ;
312312 return languageService . doHover ( document , textDocumentPositionParams . position , jsonDocument ) ;
@@ -329,13 +329,13 @@ connection.onDocumentRangeFormatting(formatParams => {
329329} ) ;
330330
331331connection . onRequest ( DocumentColorRequest . type , params => {
332- return runSafe ( ( ) => {
332+ return runSafeAsync ( ( ) => {
333333 let document = documents . get ( params . textDocument . uri ) ;
334334 if ( document ) {
335335 let jsonDocument = getJSONDocument ( document ) ;
336336 return languageService . findDocumentColors ( document , jsonDocument ) ;
337337 }
338- return [ ] ;
338+ return Promise . resolve ( [ ] ) ;
339339 } , [ ] , `Error while computing document colors for ${ params . textDocument . uri } ` ) ;
340340} ) ;
341341
0 commit comments