@@ -992,6 +992,42 @@ public async Task ParseAndAnalysisDiagnostics() {
992992 ) ;
993993 }
994994
995+ [ TestMethod , Priority ( 0 ) ]
996+ public async Task OnTypeFormatting ( ) {
997+ using ( var s = await CreateServer ( ) ) {
998+ var uri = await AddModule ( s , "def foo ( ) :\n x = a + b\n x+= 1" ) ;
999+
1000+ // Extended tests for line formatting are in LineFormatterTests.
1001+ // These just verify that the language server formats and returns something correct.
1002+ var edits = await s . SendDocumentOnTypeFormatting ( uri , new SourceLocation ( 2 , 1 ) , "\n " ) ;
1003+ edits . Should ( ) . OnlyContain ( new TextEdit {
1004+ newText = "def foo():" ,
1005+ range = new Range {
1006+ start = new SourceLocation ( 1 , 1 ) ,
1007+ end = new SourceLocation ( 1 , 15 )
1008+ }
1009+ } ) ;
1010+
1011+ edits = await s . SendDocumentOnTypeFormatting ( uri , new SourceLocation ( 3 , 1 ) , "\n " ) ;
1012+ edits . Should ( ) . OnlyContain ( new TextEdit {
1013+ newText = "x = a + b" ,
1014+ range = new Range {
1015+ start = new SourceLocation ( 2 , 5 ) ,
1016+ end = new SourceLocation ( 2 , 14 )
1017+ }
1018+ } ) ;
1019+
1020+ edits = await s . SendDocumentOnTypeFormatting ( uri , new SourceLocation ( 4 , 1 ) , "\n " ) ;
1021+ edits . Should ( ) . OnlyContain ( new TextEdit {
1022+ newText = "x += 1" ,
1023+ range = new Range {
1024+ start = new SourceLocation ( 3 , 5 ) ,
1025+ end = new SourceLocation ( 3 , 10 )
1026+ }
1027+ } ) ;
1028+ }
1029+ }
1030+
9951031 class GetAllExtensionProvider : ILanguageServerExtensionProvider {
9961032 public Task < ILanguageServerExtension > CreateAsync ( IPythonLanguageServer server , IReadOnlyDictionary < string , object > properties , CancellationToken cancellationToken ) {
9971033 return Task . FromResult < ILanguageServerExtension > ( new GetAllExtension ( ( Server ) server , properties ) ) ;
0 commit comments