zls/tests/lsp_features/semantic_tokens.zig
Techatrix 61c0981294
Use zig-lsp-codegen (#850)
* add lsp.zig

* change references from types.zig to lsp.zig

* remove types.zig and requests.zig

* add tres as a submodule

* transition codebase from types.zig to lsp.zig

* update lsp.zig

* completely overhaul message handler

* fix memory errors

* partially transition tests to lsp.zig

* update lsp.zig

* more test fixes

* disable failing tests

* fix message handling bugs

* fix remaining tests

* access correct union in diff.applyTextEdits

* more message handler fixes

* run zig fmt

* update tres submodule

* fix memory access to freed memory

* simplify initialize_msg for testing

* check if publishDiagnostics is supported
2022-12-27 01:47:57 -05:00

59 lines
1.3 KiB
Zig

const std = @import("std");
const zls = @import("zls");
const builtin = @import("builtin");
const Context = @import("../context.zig").Context;
const types = zls.types;
const allocator: std.mem.Allocator = std.testing.allocator;
test "semantic tokens - empty" {
try testSemanticTokens("", &.{});
}
test "semantic tokens" {
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 },
);
// TODO more tests
}
test "semantic tokens - comments" {
try testSemanticTokens(
\\//!─
,
&.{ 0, 0, 4, 8, 128 },
);
// TODO more tests
}
const file_uri = switch (builtin.os.tag) {
.windows => "file:///C:/test.zig",
else => "file:///test.zig",
};
fn testSemanticTokens(source: []const u8, expected: []const u32) !void {
var ctx = try Context.init();
defer ctx.deinit();
try ctx.requestDidOpen(file_uri, source);
const Response = struct {
data: []const u32,
};
const expected_bytes = try std.json.stringifyAlloc(allocator, Response{ .data = expected }, .{});
defer allocator.free(expected_bytes);
try ctx.request(
"textDocument/semanticTokens/full",
"{\"textDocument\":{\"uri\":\"" ++ file_uri ++ "\"}}",
expected_bytes,
);
}