@@ -164,7 +164,7 @@ export class TextDocuments {
164164 // Connect the logger to the connection
165165 this . logger . connect ( connection . console ) ;
166166
167- connection . onDidOpenTextDocument ( event => {
167+ connection . onDidOpenTextDocument ( event => this . logErrors ( ( ) => {
168168 // An interersting text document was opened in the client. Inform TypeScirpt's project services about it.
169169 const file = uriToFileName ( event . textDocument . uri ) ;
170170 if ( file ) {
@@ -175,16 +175,16 @@ export class TextDocuments {
175175 }
176176 this . languageIds . set ( event . textDocument . uri , event . textDocument . languageId ) ;
177177 }
178- } ) ;
178+ } ) ) ;
179179
180- connection . onDidCloseTextDocument ( event => {
180+ connection . onDidCloseTextDocument ( event => this . logErrors ( ( ) => {
181181 const file = uriToFileName ( event . textDocument . uri ) ;
182182 if ( file ) {
183183 this . projectService . closeClientFile ( file ) ;
184184 }
185- } ) ;
185+ } ) ) ;
186186
187- connection . onDidChangeTextDocument ( event => {
187+ connection . onDidChangeTextDocument ( event => this . logErrors ( ( ) => {
188188 const file = uriToFileName ( event . textDocument . uri ) ;
189189 if ( file ) {
190190 const positions = this . projectService . lineOffsetsToPositions ( file ,
@@ -207,9 +207,9 @@ export class TextDocuments {
207207 this . changeNumber ++ ;
208208 }
209209 }
210- } ) ;
210+ } ) ) ;
211211
212- connection . onDidSaveTextDocument ( event => {
212+ connection . onDidSaveTextDocument ( event => this . logErrors ( ( ) => {
213213 // If the file is saved, force the content to be reloaded from disk as the content might have changed on save.
214214 this . changeNumber ++ ;
215215 const file = uriToFileName ( event . textDocument . uri ) ;
@@ -219,7 +219,7 @@ export class TextDocuments {
219219 this . projectService . openClientFile ( file , savedContent ) ;
220220 this . changeNumber ++ ;
221221 }
222- } ) ;
222+ } ) ) ;
223223 }
224224
225225 public offsetsToPositions ( document : TextDocumentIdentifier , offsets : number [ ] ) : Position [ ] {
@@ -273,6 +273,15 @@ export class TextDocuments {
273273 } ;
274274 }
275275
276+ private logErrors ( f : ( ) => void ) {
277+ try {
278+ f ( ) ;
279+ } catch ( e ) {
280+ if ( e . message && e . stack ) this . logger . msg ( `SERVER ERROR: ${ e . message } \n${ e . stack } ` ) ;
281+ throw e ;
282+ }
283+ }
284+
276285 private handleProjectEvent ( event : ProjectServiceEvent ) {
277286 if ( this . event ) {
278287 switch ( event . eventName ) {
0 commit comments