Skip to content

Commit

Permalink
wrap number hover in code block
Browse files Browse the repository at this point in the history
  • Loading branch information
xdBronch committed Oct 25, 2024
1 parent 5acc066 commit c2bfaf1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/features/hover.zig
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,14 @@ fn hoverNumberLiteral(

switch (markup_kind) {
.markdown => return try std.fmt.allocPrint(arena,
\\```md
\\| Base | {[value]s:<[count]} |
\\| ---- | {[dash]s:-<[count]} |
\\| BIN | {[sign]s}0b{[number]b:<[len]} |
\\| OCT | {[sign]s}0o{[number]o:<[len]} |
\\| DEC | {[sign]s}{[number]d:<[len]} |
\\| HEX | {[sign]s}0x{[number]X:<[len]} |
\\```
, .{
.sign = if (is_negative) "-" else "",
.dash = "-",
Expand Down
18 changes: 18 additions & 0 deletions tests/lsp_features/hover.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,96 +95,114 @@ test "char literal" {
try testHover(
\\const foo = '<cursor>a';
,
\\```md
\\| Base | Value |
\\| ---- | --------- |
\\| BIN | 0b1100001 |
\\| OCT | 0o141 |
\\| DEC | 97 |
\\| HEX | 0x61 |
\\```
);

try testHover(
\\const foo = '<cursor>\'';
,
\\```md
\\| Base | Value |
\\| ---- | -------- |
\\| BIN | 0b100111 |
\\| OCT | 0o47 |
\\| DEC | 39 |
\\| HEX | 0x27 |
\\```
);

try testHover(
\\const foo = '\'<cursor>';
,
\\```md
\\| Base | Value |
\\| ---- | -------- |
\\| BIN | 0b100111 |
\\| OCT | 0o47 |
\\| DEC | 39 |
\\| HEX | 0x27 |
\\```
);
}
test "integer literal" {
try testHover(
\\const foo = 4<cursor>2;
,
\\```md
\\| Base | Value |
\\| ---- | -------- |
\\| BIN | 0b101010 |
\\| OCT | 0o52 |
\\| DEC | 42 |
\\| HEX | 0x2A |
\\```
);
try testHover(
\\const foo = -4<cursor>2;
,
\\```md
\\| Base | Value |
\\| ---- | --------- |
\\| BIN | -0b101010 |
\\| OCT | -0o52 |
\\| DEC | -42 |
\\| HEX | -0x2A |
\\```
);
try testHover(
\\const foo = 0b101<cursor>010;
,
\\```md
\\| Base | Value |
\\| ---- | -------- |
\\| BIN | 0b101010 |
\\| OCT | 0o52 |
\\| DEC | 42 |
\\| HEX | 0x2A |
\\```
);
try testHover(
\\const foo = -0b101<cursor>010;
,
\\```md
\\| Base | Value |
\\| ---- | --------- |
\\| BIN | -0b101010 |
\\| OCT | -0o52 |
\\| DEC | -42 |
\\| HEX | -0x2A |
\\```
);
try testHover(
\\const foo = 0x2<cursor>A;
,
\\```md
\\| Base | Value |
\\| ---- | -------- |
\\| BIN | 0b101010 |
\\| OCT | 0o52 |
\\| DEC | 42 |
\\| HEX | 0x2A |
\\```
);
try testHover(
\\const foo = -0x2<cursor>A;
,
\\```md
\\| Base | Value |
\\| ---- | --------- |
\\| BIN | -0b101010 |
\\| OCT | -0o52 |
\\| DEC | -42 |
\\| HEX | -0x2A |
\\```
);
try testHoverWithOptions(
\\const foo = 4<cursor>2;
Expand Down

0 comments on commit c2bfaf1

Please sign in to comment.