2022-08-26 15:51:43 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const zls = @import("zls");
|
2022-09-29 04:12:34 +01:00
|
|
|
const builtin = @import("builtin");
|
2022-08-26 15:51:43 +01:00
|
|
|
|
2022-09-18 23:47:06 +01:00
|
|
|
const Context = @import("../context.zig").Context;
|
2022-08-26 15:51:43 +01:00
|
|
|
|
2022-12-27 06:47:57 +00:00
|
|
|
const types = zls.types;
|
2022-08-26 15:51:43 +01:00
|
|
|
|
|
|
|
const allocator: std.mem.Allocator = std.testing.allocator;
|
|
|
|
|
|
|
|
test "semantic tokens - empty" {
|
|
|
|
try testSemanticTokens("", &.{});
|
|
|
|
}
|
|
|
|
|
|
|
|
test "semantic tokens" {
|
2022-12-04 02:35:51 +00:00
|
|
|
try testSemanticTokens(
|
|
|
|
\\const std = @import("std");
|
|
|
|
,
|
|
|
|
&.{ 0, 0, 5, 7, 0, 0, 6, 3, 0, 33, 0, 4, 1, 11, 0, 0, 2, 7, 12, 0, 0, 8, 5, 9, 0 },
|
|
|
|
);
|
2022-12-02 20:14:58 +00:00
|
|
|
|
2022-08-26 15:51:43 +01:00
|
|
|
// TODO more tests
|
|
|
|
}
|
|
|
|
|
2022-12-23 03:27:38 +00:00
|
|
|
test "semantic tokens - comments" {
|
|
|
|
try testSemanticTokens(
|
|
|
|
\\//!─
|
|
|
|
,
|
|
|
|
&.{ 0, 0, 4, 8, 128 },
|
|
|
|
);
|
|
|
|
|
|
|
|
// TODO more tests
|
|
|
|
}
|
|
|
|
|
2023-01-26 21:04:49 +00:00
|
|
|
test "semantic tokens - string literals" {
|
|
|
|
// https://github.com/zigtools/zls/issues/921
|
|
|
|
try testSemanticTokens(
|
|
|
|
\\"
|
|
|
|
\\"",//
|
|
|
|
\\"":
|
|
|
|
,
|
|
|
|
// no idea if this output is correct but at least it doesn't crash
|
|
|
|
&.{ 1, 3, 3, 8, 0, 1, 0, 2, 4, 0, 0, 0, 2, 9, 0 },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-29 04:12:34 +01:00
|
|
|
const file_uri = switch (builtin.os.tag) {
|
|
|
|
.windows => "file:///C:/test.zig",
|
|
|
|
else => "file:///test.zig",
|
|
|
|
};
|
|
|
|
|
2022-08-26 15:51:43 +01:00
|
|
|
fn testSemanticTokens(source: []const u8, expected: []const u32) !void {
|
|
|
|
var ctx = try Context.init();
|
|
|
|
defer ctx.deinit();
|
|
|
|
|
2022-12-27 06:47:57 +00:00
|
|
|
try ctx.requestDidOpen(file_uri, source);
|
2022-08-26 15:51:43 +01:00
|
|
|
|
|
|
|
const Response = struct {
|
|
|
|
data: []const u32,
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected_bytes = try std.json.stringifyAlloc(allocator, Response{ .data = expected }, .{});
|
|
|
|
defer allocator.free(expected_bytes);
|
|
|
|
|
2022-09-29 04:12:34 +01:00
|
|
|
try ctx.request(
|
|
|
|
"textDocument/semanticTokens/full",
|
|
|
|
"{\"textDocument\":{\"uri\":\"" ++ file_uri ++ "\"}}",
|
|
|
|
expected_bytes,
|
|
|
|
);
|
2022-08-26 15:51:43 +01:00
|
|
|
}
|