Skip to content

Commit 16ad1fd

Browse files
authored
Merge pull request #46 from nolanderc/group-hover-info
groups hover items with the same documentation strings
2 parents 05483d5 + 6626d28 commit 16ad1fd

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Zig
2222
uses: goto-bus-stop/setup-zig@v2.1.1
2323
with:
24-
version: ${{ ZIG_VERSION }}
24+
version: ${{ vars.ZIG_VERSION }}
2525
- name: Build
2626
run: zig build -Dtarget=${{ matrix.target }}
2727
test-pull-request:
@@ -37,7 +37,7 @@ jobs:
3737
- name: Setup Zig
3838
uses: goto-bus-stop/setup-zig@v2.1.1
3939
with:
40-
version: ${{ ZIG_VERSION }}
40+
version: ${{ vars.ZIG_VERSION }}
4141
- name: Test
4242
run: zig build test
4343

.github/workflows/release-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Zig
1414
uses: goto-bus-stop/setup-zig@v2.1.1
1515
with:
16-
version: ${{ ZIG_VERSION }}
16+
version: ${{ vars.ZIG_VERSION }}
1717
- name: Build
1818
run: ./release.sh
1919
- name: Release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
zig-out
22
zig-cache
33
stderr.log
4+
__pycache__

src/main.zig

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)