languages: Fix C/C++ outline for mixed storage classes and type qualifiers (#46135)

ozacod created

Current tree sitter configuration for the outline was not working
correctly since the rule required a strict order, firstly
storage_class_specifier then type_qualifier. This resulted in a failure
to recognize types such as "constexpr int", "const double", etc. This PR
proposes a solution with diagnostic capture of type and storage
qualifiers which ensures full context capture and works well with C++.


Before:
<img width="924" height="365" alt="before"
src="https://github.com/user-attachments/assets/d4e0baab-b074-42fc-8a45-46c93d1d352b"
/>

After:
<img width="866" height="367" alt="after"
src="https://github.com/user-attachments/assets/0e69a4d8-fd91-44b3-bc7e-0c9e39b23d2e"
/>


Release Notes:

- Fixed outline configuration for C++ variables with complex specifiers.

Change summary

crates/languages/src/cpp/outline.scm | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

Detailed changes

crates/languages/src/cpp/outline.scm 🔗

@@ -46,8 +46,10 @@
     name: (_) @name) @item
 
 (declaration
-    (storage_class_specifier) @context
-    (type_qualifier)? @context
+    [
+        (storage_class_specifier)
+        (type_qualifier)
+    ]* @context
     type: (_) @context
     declarator: (init_declarator
       ; The declaration may define multiple variables, using @item on the
@@ -129,7 +131,10 @@
     (type_qualifier)? @context) @item
 
 (field_declaration
-    (type_qualifier)? @context
+    [
+        (storage_class_specifier)
+        (type_qualifier)
+    ]* @context
     type: (_) @context
     declarator: [
         (field_identifier) @name