[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)`
This commit is contained in:
nullptrdevs 2023-02-04 10:19:24 -08:00 committed by GitHub
parent 384f227cb7
commit bd539ae989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 7 deletions

View File

@ -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 }));
}

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);