Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {

var version: std.ArrayList(u8) = .empty;
defer version.deinit(b.allocator);
gen_version(b, version.writer(b.allocator)) catch |e| {
gen_version(b, &version) catch |e| {
if (b.release_mode != .off)
std.debug.panic("gen_version failed: {any}", .{e});
version.clearAndFree(b.allocator);
Expand Down Expand Up @@ -274,7 +274,7 @@ pub fn build_exe(

var version_info: std.ArrayList(u8) = .empty;
defer version_info.deinit(b.allocator);
gen_version_info(b, target, version_info.writer(b.allocator), optimize) catch |e| {
gen_version_info(b, target, &version_info, optimize) catch |e| {
if (b.release_mode != .off)
std.debug.panic("gen_version failed: {any}", .{e});
version_info.clearAndFree(b.allocator);
Expand Down Expand Up @@ -815,7 +815,7 @@ pub fn build_exe(
fn gen_version_info(
b: *std.Build,
target: std.Build.ResolvedTarget,
writer: anytype,
out: *std.ArrayList(u8),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right fix. The gen_* functions should keep taking a writer, but it should be changed to a concrete std.Io.Writer

And the ArrayList that is written to should be changed into a std.Io.Writer.Allocating

optimize: std.builtin.OptimizeMode,
) !void {
var code: u8 = 0;
Expand All @@ -835,7 +835,7 @@ fn gen_version_info(
const tracking_remote_ = if (tracking_remote_name.len > 0) blk: {
var remote_config_path: std.ArrayList(u8) = .empty;
defer remote_config_path.deinit(b.allocator);
try remote_config_path.writer(b.allocator).print("remote.{s}.url", .{tracking_remote_name});
try remote_config_path.print(b.allocator, "remote.{s}.url", .{tracking_remote_name});
break :blk b.runAllowFail(&[_][]const u8{ "git", "config", remote_config_path.items }, &code, .Ignore) catch "(remote not found)";
} else "";
const remote_ = b.runAllowFail(&[_][]const u8{ "git", "config", "remote.origin.url" }, &code, .Ignore) catch "(origin not found)";
Expand All @@ -854,35 +854,35 @@ fn gen_version_info(
const diff = std.mem.trimRight(u8, diff_, "\r\n ");
const target_triple = try target.result.zigTriple(b.allocator);

try writer.print("Flow Control: a programmer's text editor\n\nversion: {s}{s}\ncommitted: {s}\ntarget: {s}\n", .{
try out.print(b.allocator, "Flow Control: a programmer's text editor\n\nversion: {s}{s}\ncommitted: {s}\ntarget: {s}\n", .{
version,
if (diff.len > 0) "-dirty" else "",
date,
target_triple,
});

if (branch.len > 0) if (tracking_branch.len > 0)
try writer.print("branch: {s} tracking {s} at {s}\n", .{ branch, tracking_branch, tracking_remote })
try out.print(b.allocator, "branch: {s} tracking {s} at {s}\n", .{ branch, tracking_branch, tracking_remote })
else
try writer.print("branch: {s} at {s}\n", .{ branch, remote });
try out.print(b.allocator, "branch: {s} at {s}\n", .{ branch, remote });

try writer.print("built-with: zig {s} ({t})\n", .{ builtin.zig_version_string, builtin.zig_backend });
try writer.print("build-mode: {t}\n", .{optimize});
try out.print(b.allocator, "built-with: zig {s} ({t})\n", .{ builtin.zig_version_string, builtin.zig_backend });
try out.print(b.allocator, "build-mode: {t}\n", .{optimize});

if (log.len > 0)
try writer.print("\nbranched off {s} @ {s} with the following diverging commits:\n{s}\n", .{ tracking_branch, describe_base_commit, log });
try out.print(b.allocator, "\nbranched off {s} @ {s} with the following diverging commits:\n{s}\n", .{ tracking_branch, describe_base_commit, log });

if (diff.len > 0)
try writer.print("\nwith the following uncommited changes:\n\n{s}\n", .{diff});
try out.print(b.allocator, "\nwith the following uncommited changes:\n\n{s}\n", .{diff});
}

fn gen_version(b: *std.Build, writer: anytype) !void {
fn gen_version(b: *std.Build, out: *std.ArrayList(u8)) !void {
var code: u8 = 0;

const describe = try b.runAllowFail(&[_][]const u8{ "git", "describe", "--always", "--tags" }, &code, .Ignore);
const diff_ = try b.runAllowFail(&[_][]const u8{ "git", "diff", "--stat", "--patch", "HEAD" }, &code, .Ignore);
const diff = std.mem.trimRight(u8, diff_, "\r\n ");
const version = std.mem.trimRight(u8, describe, "\r\n ");

try writer.print("{s}{s}", .{ version, if (diff.len > 0) "-dirty" else "" });
try out.print(b.allocator, "{s}{s}", .{ version, if (diff.len > 0) "-dirty" else "" });
}
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
.hash = "zigwin32-25.0.28-preview-AAAAAICM5AMResOGQnQ85mfe60TTOQeMtt7GRATUOKoP",
.lazy = true,
},
.uucode = .{
.url = "git+https://github.com/jacobsandlund/uucode?ref=zig-0.16#faab8894d753207878283d523add01817e23b805",
.hash = "uucode-0.2.0-ZZjBPl1XVACasBRHQowdN6_UB_jkKpOMgKSkGNEB1vSk",
},
.diffz = .{
.url = "git+https://github.com/ziglibs/diffz.git#fbdf690b87db6b1142bbce6d4906f90b09ce60bb",
.hash = "diffz-0.0.1-G2tlIezMAQBwGNGDs7Hn_N25dWSjEzgR_FAx9GFAvCuZ",
Expand Down
34 changes: 16 additions & 18 deletions src/Project.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ fn send_lsp_init_request(self: *Self, from: tp.pid_ref, lsp: *const LSP, project

const version = if (root.version.len > 0 and root.version[0] == 'v') root.version[1..] else root.version;
const initializationOptions: struct {
pub fn cborEncode(ctx: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void {
pub fn cborEncode(ctx: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {
if (ctx.language_server_options.len == 0) {
try cbor.writeValue(writer, null);
return;
Expand Down Expand Up @@ -2727,24 +2727,22 @@ fn send_lsp_triggerCharacters(to: tp.pid_ref, project_path: []const u8, language
};
}

fn fmt_lsp_name_func(bytes: []const u8) std.fmt.Formatter([]const u8, format_lsp_name_func) {
return .{ .data = bytes };
}

fn format_lsp_name_func(
bytes: []const u8,
writer: *std.Io.Writer,
) std.Io.Writer.Error!void {
var iter: []const u8 = bytes;
var len = cbor.decodeArrayHeader(&iter) catch return;
var first: bool = true;
while (len > 0) : (len -= 1) {
var value: []const u8 = undefined;
if (!(cbor.matchValue(&iter, cbor.extract(&value)) catch return))
return;
if (first) first = false else try writer.writeAll(" ");
try writer.writeAll(value);
fn fmt_lsp_name_func(bytes: []const u8) struct {
data: []const u8,
pub fn format(self: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {
var iter: []const u8 = self.data;
var len = cbor.decodeArrayHeader(&iter) catch return;
var first: bool = true;
while (len > 0) : (len -= 1) {
var value: []const u8 = undefined;
if (!(cbor.matchValue(&iter, cbor.extract(&value)) catch return))
return;
if (first) first = false else try writer.writeAll(" ");
try writer.writeAll(value);
}
}
} {
return .{ .data = bytes };
}

const eol = '\n';
Expand Down
5 changes: 2 additions & 3 deletions src/buffer/unicode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ pub fn utf8_sanitize(allocator: std.mem.Allocator, input: []const u8) error{
UnexpectedSecondSurrogateHalf,
}![]u8 {
var output: std.ArrayListUnmanaged(u8) = .{};
const writer = output.writer(allocator);
var buf: [4]u8 = undefined;
for (input) |byte| try writer.writeAll(try raw_byte_to_utf8(byte, &buf));
for (input) |byte| try output.appendSlice(allocator, try raw_byte_to_utf8(byte, &buf));
return output.toOwnedSlice(allocator);
}

Expand All @@ -117,7 +116,7 @@ fn utf8_write_transform_T(comptime View: anytype, comptime field: uucode.FieldEn
var it = view.iterator();
while (it.nextCodepoint()) |cp| {
const cp_ = switch (field) {
.simple_uppercase_mapping, .simple_lowercase_mapping => uucode.get(field, cp) orelse cp,
.simple_uppercase_mapping, .simple_lowercase_mapping => uucode.get(field, cp),
.case_folding_simple => uucode.get(field, cp),
else => @compileError(@tagName(field) ++ " is not a unicode transformation"),
};
Expand Down
6 changes: 3 additions & 3 deletions src/list_languages.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const checkmark_width = if (builtin.os.tag != .windows) 2 else 3;
const success_mark = if (builtin.os.tag != .windows) "✓ " else "[y]";
const fail_mark = if (builtin.os.tag != .windows) "✘ " else "[n]";

pub fn list(allocator: std.mem.Allocator, writer: *std.io.Writer, tty_config: std.io.tty.Config) !void {
pub fn list(allocator: std.mem.Allocator, writer: *std.Io.Writer, tty_config: std.Io.tty.Config) !void {
var max_language_len: usize = 0;
var max_langserver_len: usize = 0;
var max_formatter_len: usize = 0;
Expand Down Expand Up @@ -69,7 +69,7 @@ fn args_string_length(args_: ?[]const []const u8) usize {
return len;
}

fn write_checkmark(writer: anytype, success: bool, tty_config: std.io.tty.Config) !void {
fn write_checkmark(writer: anytype, success: bool, tty_config: std.Io.tty.Config) !void {
try tty_config.setColor(writer, if (success) .green else .red);
if (success) try writer.writeAll(success_mark) else try writer.writeAll(fail_mark);
}
Expand All @@ -79,7 +79,7 @@ fn write_segmented(
args_: ?[]const []const u8,
sep: []const u8,
pad: ?usize,
tty_config: std.io.tty.Config,
tty_config: std.Io.tty.Config,
) !void {
const args = args_ orelse return;
var len: usize = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/log.zig
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ pub const Logger = struct {
//
} else {
var failed = false;
msg_fmt.writer(std.heap.c_allocator).print("{f}", .{msg_}) catch {
msg_fmt.print(std.heap.c_allocator, "{f}", .{msg_}) catch {
failed = true;
};
if (failed) {
msg_fmt.clearRetainingCapacity();
msg_fmt.writer(std.heap.c_allocator).print("{f}", .{std.ascii.hexEscape(msg_.buf, .lower)}) catch {};
msg_fmt.print(std.heap.c_allocator, "{f}", .{std.ascii.hexEscape(msg_.buf, .lower)}) catch {};
}
msg__ = msg_fmt.items;
tp.trace(tp.channel.debug, .{ "log_err_fmt", msg__.len, msg__[0..@min(msg__.len, 128)] });
Expand Down
8 changes: 6 additions & 2 deletions src/lsp_config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ fn get_project(project: []const u8, lsp_name: []const u8) ?[]const u8 {
defer allocator.free(file_name);
const file: std.fs.File = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null;
defer file.close();
return file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch return null;
var buf: [4096]u8 = undefined;
var r = file.reader(&buf);
return r.interface.allocRemaining(allocator, .unlimited) catch return null;
}

fn get_global(lsp_name: []const u8) ?[]const u8 {
const file_name = get_config_file_path(&.{}, lsp_name, .global, .no_create) catch return null;
defer allocator.free(file_name);
const file: std.fs.File = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null;
defer file.close();
return file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch return null;
var buf: [4096]u8 = undefined;
var r = file.reader(&buf);
return r.interface.allocRemaining(allocator, .unlimited) catch return null;
}

pub fn get_config_file_path(project: ?[]const u8, lsp_name: []const u8, scope: Scope, mode: Mode) ![]u8 {
Expand Down
18 changes: 13 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn main() anyerror!void {
return std.fs.File.stdout().writeAll(version_info);

if (args.list_languages) {
const tty_config = std.io.tty.detectConfig(std.fs.File.stdout());
const tty_config = std.Io.tty.detectConfig(std.fs.File.stdout());
return list_languages.list(a, stdout, tty_config);
}

Expand Down Expand Up @@ -542,7 +542,9 @@ fn read_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs: *[][]
fn read_text_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: *[][]const u8, file_name: []const u8) !void {
var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only });
defer file.close();
const content = try file.readToEndAlloc(allocator, 64 * 1024);
var read_buf: [4096]u8 = undefined;
var r = file.reader(&read_buf);
const content = try r.interface.allocRemaining(allocator, .limited(64 * 1024));
defer allocator.free(content);
return parse_text_config_file(T, allocator, conf, bufs_, file_name, content);
}
Expand Down Expand Up @@ -581,7 +583,9 @@ pub fn parse_text_config_file(T: type, allocator: std.mem.Allocator, conf: *T, b
fn read_json_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: *[][]const u8, file_name: []const u8) !void {
var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only });
defer file.close();
const json = try file.readToEndAlloc(allocator, 64 * 1024);
var read_buf: [4096]u8 = undefined;
var r = file.reader(&read_buf);
const json = try r.interface.allocRemaining(allocator, .limited(64 * 1024));
defer allocator.free(json);
const cbor_buf: []u8 = try allocator.alloc(u8, json.len);
var bufs = std.ArrayListUnmanaged([]const u8).fromOwnedSlice(bufs_.*);
Expand Down Expand Up @@ -854,7 +858,9 @@ pub fn read_keybind_namespace(allocator: std.mem.Allocator, namespace_name: []co
const file_name = get_keybind_namespace_file_name(namespace_name) catch return null;
var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null;
defer file.close();
return file.readToEndAlloc(allocator, 64 * 1024) catch null;
var read_buf: [4096]u8 = undefined;
var r = file.reader(&read_buf);
return r.interface.allocRemaining(allocator, .limited(64 * 1024)) catch null;
}

pub fn write_keybind_namespace(namespace_name: []const u8, content: []const u8) !void {
Expand Down Expand Up @@ -882,7 +888,9 @@ pub fn read_theme(allocator: std.mem.Allocator, theme_name: []const u8) ?[]const
const file_name = get_theme_file_name(theme_name) catch return null;
var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch return null;
defer file.close();
return file.readToEndAlloc(allocator, 64 * 1024) catch null;
var read_buf: [4096]u8 = undefined;
var r = file.reader(&read_buf);
return r.interface.allocRemaining(allocator, .limited(64 * 1024)) catch null;
}

pub fn write_theme(theme_name: []const u8, content: []const u8) !void {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/vaxis/renderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque
unreachable;
}

fn handleSegfaultPosixNoAbort(stderr: *std.io.Writer, sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void {
fn handleSegfaultPosixNoAbort(stderr: *std.Io.Writer, sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void {
const debug = @import("std/debug.zig");
debug.resetSegfaultHandler();
const addr = switch (builtin.os.tag) {
Expand Down
Loading