@@ -58,6 +58,34 @@ suite("[Quick info test]", function(): void {
5858 disposables . forEach ( d => d . dispose ( ) ) ;
5959 } ) ;
6060
61+ async function getTypeHoverText ( ) : Promise < string > {
62+ const result : vscode . Hover [ ] = < vscode . Hover [ ] > ( await vscode . commands . executeCommand (
63+ 'vscode.executeHoverProvider' ,
64+ fileUri ,
65+ new vscode . Position ( 39 , 8 ) ) ) ;
66+ assert . ok ( result . length > 0 , "Expected a hover for HoverType." ) ;
67+ return result . flatMap ( hover => hover . contents )
68+ . map ( content => typeof content === "string" ? content : content . value )
69+ . join ( "\n" ) ;
70+ }
71+
72+ async function waitForTypeHover ( showSizeAndAlignment : boolean ) : Promise < string > {
73+ const deadline : number = Date . now ( ) + 5000 ;
74+ let hoverText : string = "" ;
75+ while ( Date . now ( ) < deadline ) {
76+ hoverText = await getTypeHoverText ( ) ;
77+ const showsSize : boolean = hoverText . includes ( "**Size:**" ) ;
78+ const showsAlignment : boolean = hoverText . includes ( "**Alignment:**" ) ;
79+ if ( hoverText . includes ( "struct HoverType" )
80+ && showsSize === showSizeAndAlignment
81+ && showsAlignment === showSizeAndAlignment ) {
82+ return hoverText ;
83+ }
84+ await testHelpers . delay ( 50 ) ;
85+ }
86+ assert . fail ( `Timed out waiting for type size and alignment to be ${ showSizeAndAlignment ? "shown" : "hidden" } . Last hover:\n${ hoverText } ` ) ;
87+ }
88+
6189 test ( "[Hover over function call - normal comment]" , async ( ) => {
6290 const result : vscode . Hover [ ] = < vscode . Hover [ ] > ( await vscode . commands . executeCommand ( 'vscode.executeHoverProvider' , fileUri , new vscode . Position ( 35 , 23 ) ) ) ;
6391 const expected_full_comment : string = `\`\`\`cpp\nbool isEven(int value)\n\`\`\` \nVerifies if input is even number or not` ;
@@ -111,15 +139,23 @@ suite("[Quick info test]", function(): void {
111139 const originalHover : string | undefined = configuration . inspect < string > ( "hover" ) ?. workspaceFolderValue ;
112140 const originalShowIntegralValuesInHexadecimal : boolean | undefined =
113141 configuration . inspect < boolean > ( "hoverShowIntegralValuesInHexadecimal" ) ?. workspaceFolderValue ;
142+ const originalShowTypeSizeAndAlignment : boolean | undefined =
143+ configuration . inspect < boolean > ( "hoverShowTypeSizeAndAlignment" ) ?. workspaceFolderValue ;
114144
115145 try {
116146 await configuration . update ( "hover" , "disabled" , vscode . ConfigurationTarget . WorkspaceFolder ) ;
117147 await configuration . update ( "hoverShowIntegralValuesInHexadecimal" , true , vscode . ConfigurationTarget . WorkspaceFolder ) ;
148+ await configuration . update ( "hoverShowTypeSizeAndAlignment" , false , vscode . ConfigurationTarget . WorkspaceFolder ) ;
118149
119150 const settings : CppSettings = new CppSettings ( fileUri ) ;
120151 assert . strictEqual ( settings . hover , "disabled" ) ;
121152 assert . strictEqual ( settings . hoverShowIntegralValuesInHexadecimal , true ) ;
153+ assert . strictEqual ( settings . hoverShowTypeSizeAndAlignment , false ) ;
122154 } finally {
155+ await configuration . update (
156+ "hoverShowTypeSizeAndAlignment" ,
157+ originalShowTypeSizeAndAlignment ,
158+ vscode . ConfigurationTarget . WorkspaceFolder ) ;
123159 await configuration . update (
124160 "hoverShowIntegralValuesInHexadecimal" ,
125161 originalShowIntegralValuesInHexadecimal ,
@@ -128,6 +164,32 @@ suite("[Quick info test]", function(): void {
128164 }
129165 } ) ;
130166
167+ test ( "[Toggle type size and alignment command updates hover]" , async ( ) => {
168+ const configuration : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "C_Cpp" , fileUri ) ;
169+ const originalShowTypeSizeAndAlignment : boolean | undefined =
170+ configuration . inspect < boolean > ( "hoverShowTypeSizeAndAlignment" ) ?. workspaceFolderValue ;
171+
172+ try {
173+ await configuration . update ( "hoverShowTypeSizeAndAlignment" , true , vscode . ConfigurationTarget . WorkspaceFolder ) ;
174+ await waitForTypeHover ( true ) ;
175+
176+ await vscode . commands . executeCommand ( "C_Cpp.ToggleTypeSizeAndAlignment" ) ;
177+ assert . strictEqual ( configuration . inspect < boolean > ( "hoverShowTypeSizeAndAlignment" ) ?. workspaceFolderValue , false ) ;
178+ const hiddenHover : string = await waitForTypeHover ( false ) ;
179+ assert . ok ( hiddenHover . includes ( "struct HoverType" ) ) ;
180+
181+ await vscode . commands . executeCommand ( "C_Cpp.ToggleTypeSizeAndAlignment" ) ;
182+ assert . strictEqual ( configuration . inspect < boolean > ( "hoverShowTypeSizeAndAlignment" ) ?. workspaceFolderValue , true ) ;
183+ const shownHover : string = await waitForTypeHover ( true ) ;
184+ assert . ok ( shownHover . includes ( "struct HoverType" ) ) ;
185+ } finally {
186+ await configuration . update (
187+ "hoverShowTypeSizeAndAlignment" ,
188+ originalShowTypeSizeAndAlignment ,
189+ vscode . ConfigurationTarget . WorkspaceFolder ) ;
190+ }
191+ } ) ;
192+
131193 test ( "[Folder hexadecimal setting preserves global disabled hover]" , async ( ) => {
132194 const configuration : vscode . WorkspaceConfiguration = vscode . workspace . getConfiguration ( "C_Cpp" , fileUri ) ;
133195 const originalGlobalHover : string | undefined = configuration . inspect < string > ( "hover" ) ?. globalValue ;
0 commit comments