Revamp bulid.zig discovery (#688)

* walk down tree instead of up for build.zig discovery

* account for windows URIs in tests
This commit is contained in:
Matt Knight
2022-09-28 20:12:34 -07:00
committed by GitHub
parent e3803d760f
commit 6ec6d4ea36
5 changed files with 244 additions and 105 deletions

View File

@@ -1,5 +1,6 @@
const std = @import("std");
const zls = @import("zls");
const builtin = @import("builtin");
const helper = @import("../helper.zig");
const Context = @import("../context.zig").Context;
@@ -73,7 +74,12 @@ fn testInlayHints(source: []const u8) !void {
var ctx = try Context.init();
defer ctx.deinit();
try ctx.requestDidOpen("file:///test.zig", phr.new_source);
const test_uri: []const u8 = switch (builtin.os.tag) {
.windows => "file:///C:\\test.zig",
else => "file:///test.zig",
};
try ctx.requestDidOpen(test_uri, phr.new_source);
const range = types.Range{
.start = types.Position{ .line = 0, .character = 0 },
@@ -88,7 +94,7 @@ fn testInlayHints(source: []const u8) !void {
const request = requests.InlayHint{
.params = .{
.textDocument = .{ .uri = "file:///test.zig" },
.textDocument = .{ .uri = test_uri },
.range = range,
},
};
@@ -117,7 +123,7 @@ fn testInlayHints(source: []const u8) !void {
for (hints) |hint| {
if (position.line != hint.position.line or position.character != hint.position.character) continue;
const actual_label = hint.label[0 .. hint.label.len - 1]; // exclude :
if (!std.mem.eql(u8, expected_label, actual_label)) {

View File

@@ -1,5 +1,6 @@
const std = @import("std");
const zls = @import("zls");
const builtin = @import("builtin");
const helper = @import("../helper.zig");
const Context = @import("../context.zig").Context;
@@ -85,7 +86,10 @@ test "references - label" {
}
fn testReferences(source: []const u8) !void {
const file_uri = "file:///test.zig";
const file_uri: []const u8 = switch (builtin.os.tag) {
.windows => "file:///C:\\test.zig",
else => "file:///test.zig",
};
const new_name = "placeholder";
var phr = try helper.collectReplacePlaceholders(allocator, source, new_name);

View File

@@ -1,5 +1,6 @@
const std = @import("std");
const zls = @import("zls");
const builtin = @import("builtin");
const Context = @import("../context.zig").Context;
@@ -20,6 +21,11 @@ test "semantic tokens" {
// 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();
@@ -27,7 +33,7 @@ fn testSemanticTokens(source: []const u8, expected: []const u32) !void {
const open_document = requests.OpenDocument{
.params = .{
.textDocument = .{
.uri = "file:///test.zig",
.uri = file_uri,
// .languageId = "zig",
// .version = 420,
.text = source,
@@ -47,7 +53,9 @@ fn testSemanticTokens(source: []const u8, expected: []const u32) !void {
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:///test.zig"}}
, expected_bytes);
try ctx.request(
"textDocument/semanticTokens/full",
"{\"textDocument\":{\"uri\":\"" ++ file_uri ++ "\"}}",
expected_bytes,
);
}