@@ -12,6 +12,7 @@ import {
1212 CompletionRequest ,
1313 ConfigurationItem ,
1414 DiagnosticSeverity ,
15+ DidChangeTextDocumentNotification ,
1516 DocumentOnTypeFormattingRequest ,
1617 InitializedNotification ,
1718 InitializeRequest ,
@@ -191,11 +192,19 @@ describe(`Basic language server tests`, () => {
191192 const fileUri = marker . fileUri ;
192193 const text = info . testData . files . find ( ( d ) => d . fileName === marker . fileName ) ! . content ;
193194 const parseResult = getParseResults ( text ) ;
195+ const position = convertOffsetToPosition ( marker . position , parseResult . tokenizerOutput . lines ) ;
196+ // need to send this notification first before onTypeFormatting.
197+ // see https://github.com/microsoft/language-server-protocol/issues/1053#issuecomment-725468469
198+ await info . connection . sendNotification ( DidChangeTextDocumentNotification . type , {
199+ textDocument : { uri : fileUri . toString ( ) , version : 2 } ,
200+ contentChanges : [ { range : { start : position , end : position } , text : '{}' } ] ,
201+ } ) ;
194202 const onTypeFormattingRequest = await info . connection . sendRequest (
195203 DocumentOnTypeFormattingRequest . type ,
196204 {
197205 textDocument : { uri : fileUri . toString ( ) } ,
198- position : convertOffsetToPosition ( marker . position , parseResult . tokenizerOutput . lines ) ,
206+ // need to add 1 to the position because it's inserting a character (i think)
207+ position : { line : position . line , character : position . character + 1 } ,
199208 ch : '{' ,
200209 options : { insertSpaces : true , tabSize : 4 } ,
201210 } ,
0 commit comments