@@ -164,7 +164,7 @@ export class TextDocuments {
164
164
// Connect the logger to the connection
165
165
this . logger . connect ( connection . console ) ;
166
166
167
- connection . onDidOpenTextDocument ( event => {
167
+ connection . onDidOpenTextDocument ( event => this . logErrors ( ( ) => {
168
168
// An interersting text document was opened in the client. Inform TypeScirpt's project services about it.
169
169
const file = uriToFileName ( event . textDocument . uri ) ;
170
170
if ( file ) {
@@ -175,16 +175,16 @@ export class TextDocuments {
175
175
}
176
176
this . languageIds . set ( event . textDocument . uri , event . textDocument . languageId ) ;
177
177
}
178
- } ) ;
178
+ } ) ) ;
179
179
180
- connection . onDidCloseTextDocument ( event => {
180
+ connection . onDidCloseTextDocument ( event => this . logErrors ( ( ) => {
181
181
const file = uriToFileName ( event . textDocument . uri ) ;
182
182
if ( file ) {
183
183
this . projectService . closeClientFile ( file ) ;
184
184
}
185
- } ) ;
185
+ } ) ) ;
186
186
187
- connection . onDidChangeTextDocument ( event => {
187
+ connection . onDidChangeTextDocument ( event => this . logErrors ( ( ) => {
188
188
const file = uriToFileName ( event . textDocument . uri ) ;
189
189
if ( file ) {
190
190
const positions = this . projectService . lineOffsetsToPositions ( file ,
@@ -207,9 +207,9 @@ export class TextDocuments {
207
207
this . changeNumber ++ ;
208
208
}
209
209
}
210
- } ) ;
210
+ } ) ) ;
211
211
212
- connection . onDidSaveTextDocument ( event => {
212
+ connection . onDidSaveTextDocument ( event => this . logErrors ( ( ) => {
213
213
// If the file is saved, force the content to be reloaded from disk as the content might have changed on save.
214
214
this . changeNumber ++ ;
215
215
const file = uriToFileName ( event . textDocument . uri ) ;
@@ -219,7 +219,7 @@ export class TextDocuments {
219
219
this . projectService . openClientFile ( file , savedContent ) ;
220
220
this . changeNumber ++ ;
221
221
}
222
- } ) ;
222
+ } ) ) ;
223
223
}
224
224
225
225
public offsetsToPositions ( document : TextDocumentIdentifier , offsets : number [ ] ) : Position [ ] {
@@ -273,6 +273,15 @@ export class TextDocuments {
273
273
} ;
274
274
}
275
275
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
+
276
285
private handleProjectEvent ( event : ProjectServiceEvent ) {
277
286
if ( this . event ) {
278
287
switch ( event . eventName ) {
0 commit comments