@@ -11,7 +11,6 @@ import {
1111 closeAllEditorsAsync ,
1212 openFileInWorkspaceAsync ,
1313 revertActiveFile ,
14- sleep ,
1514 waitForExpectedResult ,
1615} from './integrationHelpers' ;
1716import { describe , beforeAll , beforeEach , afterAll , test , expect , afterEach } from '@jest/globals' ;
@@ -36,7 +35,6 @@ describe(`OnAutoInsert Tests`, () => {
3635 } ) ;
3736
3837 test ( 'Triple slash inserts doc comment snippet' , async ( ) => {
39- await sleep ( 1 ) ;
4038 await vscode . window . activeTextEditor ! . edit ( ( editBuilder ) => {
4139 editBuilder . insert ( new vscode . Position ( 2 , 6 ) , '/' ) ;
4240 } ) ;
@@ -110,6 +108,65 @@ describe(`OnAutoInsert Tests`, () => {
110108 }
111109 ) ;
112110 } ) ;
111+
112+ test ( 'Enter inside braces respects language-specific tabSize' , async ( ) => {
113+ // Set global tabSize to 2 and C# tabSize to 4
114+ const globalConfig = vscode . workspace . getConfiguration ( 'editor' ) ;
115+ const csharpConfig = vscode . workspace . getConfiguration ( 'editor' , {
116+ languageId : 'csharp' ,
117+ uri : vscode . window . activeTextEditor ! . document . uri ,
118+ } ) ;
119+
120+ const originalGlobalTabSize = globalConfig . get ( 'tabSize' ) ;
121+ const originalCsharpTabSize = csharpConfig . get ( 'tabSize' ) ;
122+
123+ try {
124+ // Turn off detect indentation to ensure it consistently uses the settings.
125+ await globalConfig . update ( 'detectIndentation' , false , vscode . ConfigurationTarget . Global ) ;
126+
127+ // Customize tab sizes
128+ await globalConfig . update ( 'tabSize' , 4 , vscode . ConfigurationTarget . Global ) ;
129+ await csharpConfig . update ( 'tabSize' , 2 , vscode . ConfigurationTarget . Global ) ;
130+
131+ await vscode . window . activeTextEditor ! . edit ( ( editBuilder ) => {
132+ editBuilder . insert ( new vscode . Position ( 11 , 15 ) , '\n' ) ;
133+ } ) ;
134+
135+ const expectedLines = [
136+ 'class DocComments' ,
137+ '{' ,
138+ ' //' ,
139+ ' string M(int param1, string param2)' ,
140+ ' {' ,
141+ ' return null;' ,
142+ ' }' ,
143+ '' ,
144+ ' /// <summary>' ,
145+ '' ,
146+ ' /// </summary>' ,
147+ ' void M2()' ,
148+ ' {' ,
149+ ' ' , // Should be 2 spaces (C# setting), not 4 (global setting)
150+ ' }' ,
151+ '}' ,
152+ '' ,
153+ ] ;
154+
155+ await waitForExpectedResult < string | undefined > (
156+ async ( ) => vscode . window . activeTextEditor ?. document . getText ( ) ,
157+ 10000 ,
158+ 100 ,
159+ ( input ) => {
160+ expect ( input ) . toBe ( expectedLines . join ( EOL ) ) ;
161+ }
162+ ) ;
163+ } finally {
164+ // Restore original settings
165+ await globalConfig . update ( 'detectIndentation' , true , vscode . ConfigurationTarget . Global ) ;
166+ await globalConfig . update ( 'tabSize' , originalGlobalTabSize , vscode . ConfigurationTarget . Global ) ;
167+ await csharpConfig . update ( 'tabSize' , originalCsharpTabSize , vscode . ConfigurationTarget . Global ) ;
168+ }
169+ } ) ;
113170} ) ;
114171
115172function normalizeNewlines ( text : string | undefined ) : string | undefined {
0 commit comments