@@ -110,6 +110,71 @@ describe(`OnAutoInsert Tests`, () => {
110110 }
111111 ) ;
112112 } ) ;
113+
114+ test ( 'Enter inside braces respects language-specific tabSize' , async ( ) => {
115+ // Set global tabSize to 2 and C# tabSize to 4
116+ const globalConfig = vscode . workspace . getConfiguration ( 'editor' ) ;
117+ const csharpConfig = vscode . workspace . getConfiguration ( 'editor' , {
118+ languageId : 'csharp' ,
119+ uri : vscode . window . activeTextEditor ! . document . uri ,
120+ } ) ;
121+
122+ const originalGlobalTabSize = globalConfig . get ( 'tabSize' ) ;
123+ const originalCsharpTabSize = csharpConfig . get ( 'tabSize' ) ;
124+
125+ try {
126+ // Configure global tabSize to 2
127+ await globalConfig . update ( 'tabSize' , 2 , vscode . ConfigurationTarget . Global ) ;
128+ // Configure C# tabSize to 4
129+ await vscode . workspace
130+ . getConfiguration ( '[csharp]' , vscode . window . activeTextEditor ! . document . uri )
131+ . update ( 'editor.tabSize' , 4 , vscode . ConfigurationTarget . Global ) ;
132+
133+ // Wait for configuration to propagate
134+ await sleep ( 100 ) ;
135+
136+ await vscode . window . activeTextEditor ! . edit ( ( editBuilder ) => {
137+ editBuilder . insert ( new vscode . Position ( 11 , 15 ) , '\n' ) ;
138+ } ) ;
139+
140+ // OnAutoInsert is triggered by the change event but completes asynchronously, so wait for the buffer to be updated.
141+
142+ const expectedLines = [
143+ 'class DocComments' ,
144+ '{' ,
145+ ' //' ,
146+ ' string M(int param1, string param2)' ,
147+ ' {' ,
148+ ' return null;' ,
149+ ' }' ,
150+ '' ,
151+ ' /// <summary>' ,
152+ '' ,
153+ ' /// </summary>' ,
154+ ' void M2()' ,
155+ ' {' ,
156+ ' ' , // Should be 4 spaces (C# setting), not 2 (global setting)
157+ ' }' ,
158+ '}' ,
159+ '' ,
160+ ] ;
161+
162+ await waitForExpectedResult < string | undefined > (
163+ async ( ) => vscode . window . activeTextEditor ?. document . getText ( ) ,
164+ 10000 ,
165+ 100 ,
166+ ( input ) => {
167+ expect ( input ) . toBe ( expectedLines . join ( EOL ) ) ;
168+ }
169+ ) ;
170+ } finally {
171+ // Restore original settings
172+ await globalConfig . update ( 'tabSize' , originalGlobalTabSize , vscode . ConfigurationTarget . Global ) ;
173+ await vscode . workspace
174+ . getConfiguration ( '[csharp]' , vscode . window . activeTextEditor ! . document . uri )
175+ . update ( 'editor.tabSize' , originalCsharpTabSize , vscode . ConfigurationTarget . Global ) ;
176+ }
177+ } ) ;
113178} ) ;
114179
115180function normalizeNewlines ( text : string | undefined ) : string | undefined {
0 commit comments