From bd539ae9895e4ab252ebd416bcf5f05d261378e7 Mon Sep 17 00:00:00 2001 From: nullptrdevs <16590917+nullptrdevs@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:19:24 -0800 Subject: [PATCH] [`std.zig.`] `parse(alloc, src)` -> `Ast.parse(alloc, src, Ast.Mode)` (#966) * Work in Zig's breaking changes (build sys apis) * [`std.zig.`] `parse(alloc, src)` -> `Ast.parse(alloc, src, Ast.Mode)` --- build.zig | 2 +- src/DocumentStore.zig | 4 ++-- tests/language_features/cimport.zig | 2 +- tests/utility/ast.zig | 2 +- tests/utility/offsets.zig | 6 ++++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 8d6da57..adddf0f 100644 --- a/build.zig +++ b/build.zig @@ -7,7 +7,7 @@ const zls_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 }; pub fn build(b: *std.build.Builder) !void { comptime { const current_zig = builtin.zig_version; - const min_zig = std.SemanticVersion.parse("0.11.0-dev.1524+efa25e7d5") catch return; // build API changes + const min_zig = std.SemanticVersion.parse("0.11.0-dev.1567+60935decd") catch return; // std.zig.parse(alloc, src) -> std.zig.Ast.parse(alloc, src, Ast.Mode) if (current_zig.order(min_zig) == .lt) { @compileError(std.fmt.comptimePrint("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig })); } diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 1384363..4bdc30b 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -196,7 +196,7 @@ pub fn refreshDocument(self: *DocumentStore, uri: Uri, new_text: [:0]const u8) ! self.allocator.free(handle.text); handle.text = new_text; - var new_tree = try std.zig.parse(self.allocator, handle.text); + var new_tree = try Ast.parse(self.allocator, handle.text, .zig); handle.tree.deinit(self.allocator); handle.tree = new_tree; @@ -619,7 +619,7 @@ fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]u8, open: bool) erro var duped_uri = try self.allocator.dupe(u8, uri); errdefer self.allocator.free(duped_uri); - var tree = try std.zig.parse(self.allocator, text); + var tree = try Ast.parse(self.allocator, text, .zig); errdefer tree.deinit(self.allocator); var nodes = tree.nodes.toMultiArrayList(); diff --git a/tests/language_features/cimport.zig b/tests/language_features/cimport.zig index 92a867f..10928ba 100644 --- a/tests/language_features/cimport.zig +++ b/tests/language_features/cimport.zig @@ -53,7 +53,7 @@ fn testConvertCInclude(cimport_source: []const u8, expected: []const u8) !void { const source: [:0]u8 = try std.fmt.allocPrintZ(allocator, "const c = {s};", .{cimport_source}); defer allocator.free(source); - var ast = try std.zig.parse(allocator, source); + var ast = try Ast.parse(allocator, source, .zig); defer ast.deinit(allocator); const main_tokens = ast.nodes.items(.main_token); diff --git a/tests/utility/ast.zig b/tests/utility/ast.zig index 3a3f404..611708e 100644 --- a/tests/utility/ast.zig +++ b/tests/utility/ast.zig @@ -47,7 +47,7 @@ fn testNodesAtLoc(source: []const u8) !void { const new_source = try allocator.dupeZ(u8, ccp.new_source); defer allocator.free(new_source); - var tree = try std.zig.parse(allocator, new_source); + var tree = try std.zig.Ast.parse(allocator, new_source, .zig); defer tree.deinit(allocator); const nodes = try ast.nodesAtLoc(allocator, tree, inner_loc); diff --git a/tests/utility/offsets.zig b/tests/utility/offsets.zig index 5dc189a..02cb0fc 100644 --- a/tests/utility/offsets.zig +++ b/tests/utility/offsets.zig @@ -4,6 +4,8 @@ const zls = @import("zls"); const types = zls.types; const offsets = zls.offsets; +const Ast = std.zig.Ast; + test "offsets - index <-> Position" { try testIndexPosition("", 0, 0, .{ 0, 0, 0 }); @@ -116,8 +118,8 @@ fn testIndexPosition(text: []const u8, index: usize, line: u32, characters: [3]u try std.testing.expectEqual(index, offsets.positionToIndex(text, position32, .@"utf-32")); } -fn testTokenToLoc(text: [:0]const u8, token_index: std.zig.Ast.TokenIndex, start: usize, end: usize) !void { - var tree = try std.zig.parse(std.testing.allocator, text); +fn testTokenToLoc(text: [:0]const u8, token_index: Ast.TokenIndex, start: usize, end: usize) !void { + var tree = try Ast.parse(std.testing.allocator, text, .zig); defer tree.deinit(std.testing.allocator); const actual = offsets.tokenToLoc(tree, token_index);