@@ -671,21 +671,42 @@ pub const Dispatch = struct {
671671 .{ .ignore_current = false },
672672 );
673673
674- var text = std .ArrayList (u8 ).init (state .allocator );
675- defer text .deinit ();
674+ // group completions by their documentation.
675+ var groups = std .StringArrayHashMap (std .ArrayListUnmanaged (* const lsp .CompletionItem ))
676+ .init (symbol_arena .allocator ());
677+ defer groups .deinit ();
676678
677679 for (completions .items ) | * completion | {
678- if (std .mem .eql (u8 , completion .label , token_text )) {
679- if (text .items .len != 0 ) {
680- try text .appendSlice ("\n\n ---\n\n " );
681- }
682- if (completion .detail ) | detail | {
683- try text .writer ().print ("```glsl\n {s}\n ```" , .{detail });
684- }
685- if (completion .documentation ) | docs | {
686- try text .appendSlice ("\n\n " );
687- try text .appendSlice (docs .value );
680+ if (! std .mem .eql (u8 , completion .label , token_text )) continue ;
681+
682+ const documentation_string = if (completion .documentation ) | markup | markup .value else "" ;
683+
684+ const result = try groups .getOrPut (documentation_string );
685+ if (! result .found_existing ) result .value_ptr .* = .{};
686+ try result .value_ptr .append (symbol_arena .allocator (), completion );
687+ }
688+
689+ var text = std .ArrayList (u8 ).init (symbol_arena .allocator ());
690+ defer text .deinit ();
691+
692+ for (groups .keys (), groups .values ()) | description , group | {
693+ if (text .items .len != 0 ) {
694+ try text .appendSlice ("\n\n ---\n\n " );
695+ }
696+
697+ if (group .items .len != 0 ) {
698+ try text .appendSlice ("```glsl\n " );
699+ for (group .items ) | completion | {
700+ if (completion .detail ) | detail | {
701+ try text .writer ().print ("{s}\n " , .{detail });
702+ }
688703 }
704+ try text .appendSlice ("```\n " );
705+ }
706+
707+ if (description .len != 0 ) {
708+ if (group .items .len != 0 ) try text .appendSlice ("\n " );
709+ try text .appendSlice (description );
689710 }
690711 }
691712
0 commit comments