@@ -98,6 +98,7 @@ export class DefaultLanguageServer implements LanguageServer {
9898 }
9999
100100 protected buildInitializeResult ( _params : InitializeParams ) : InitializeResult {
101+ const documentUpdateHandler = this . services . lsp . DocumentUpdateHandler ;
101102 const fileOperationOptions = this . services . lsp . FileOperationHandler ?. fileOperationOptions ;
102103 const allServices : readonly LangiumCoreAndPartialLSPServices [ ] = this . services . ServiceRegistry . all ;
103104 const hasFormattingService = this . hasService ( e => e . lsp ?. Formatter ) ;
@@ -136,7 +137,13 @@ export class DefaultLanguageServer implements LanguageServer {
136137 executeCommandProvider : commandNames && {
137138 commands : commandNames
138139 } ,
139- textDocumentSync : TextDocumentSyncKind . Incremental ,
140+ textDocumentSync : {
141+ change : TextDocumentSyncKind . Incremental ,
142+ openClose : true ,
143+ save : Boolean ( documentUpdateHandler . didSaveDocument ) ,
144+ willSave : Boolean ( documentUpdateHandler . willSaveDocument ) ,
145+ willSaveWaitUntil : Boolean ( documentUpdateHandler . willSaveDocumentWaitUntil )
146+ } ,
140147 completionProvider : hasCompletionProvider ? completionOptions : undefined ,
141148 referencesProvider : hasReferencesProvider ,
142149 documentSymbolProvider : hasDocumentSymbolProvider ,
@@ -267,8 +274,27 @@ export function startLanguageServer(services: LangiumSharedServices): void {
267274export function addDocumentUpdateHandler ( connection : Connection , services : LangiumSharedServices ) : void {
268275 const handler = services . lsp . DocumentUpdateHandler ;
269276 const documents = services . workspace . TextDocuments ;
270- documents . onDidChangeContent ( change => handler . didChangeContent ( change ) ) ;
271- connection . onDidChangeWatchedFiles ( params => handler . didChangeWatchedFiles ( params ) ) ;
277+ if ( handler . didOpenDocument ) {
278+ documents . onDidOpen ( change => handler . didOpenDocument ! ( change ) ) ;
279+ }
280+ if ( handler . didChangeContent ) {
281+ documents . onDidChangeContent ( change => handler . didChangeContent ! ( change ) ) ;
282+ }
283+ if ( handler . didCloseDocument ) {
284+ documents . onDidClose ( change => handler . didCloseDocument ! ( change ) ) ;
285+ }
286+ if ( handler . didSaveDocument ) {
287+ documents . onDidSave ( change => handler . didSaveDocument ! ( change ) ) ;
288+ }
289+ if ( handler . willSaveDocument ) {
290+ documents . onWillSave ( event => handler . willSaveDocument ! ( event ) ) ;
291+ }
292+ if ( handler . willSaveDocumentWaitUntil ) {
293+ documents . onWillSaveWaitUntil ( event => handler . willSaveDocumentWaitUntil ! ( event ) ) ;
294+ }
295+ if ( handler . didChangeWatchedFiles ) {
296+ connection . onDidChangeWatchedFiles ( params => handler . didChangeWatchedFiles ! ( params ) ) ;
297+ }
272298}
273299
274300export function addFileOperationHandler ( connection : Connection , services : LangiumSharedServices ) : void {
0 commit comments