Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use zig-lsp-codegen #850

Merged
merged 21 commits into from
Dec 27, 2022
Merged
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "src/tracy"]
path = src/tracy
url = https://github.com/wolfpld/tracy
[submodule "src/tres"]
path = src/tres
url = https://github.com/ziglibs/tres.git
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub fn build(b: *std.build.Builder) !void {
const known_folders_path = b.option([]const u8, "known-folders", "Path to known-folders package (default: " ++ KNOWN_FOLDERS_DEFAULT_PATH ++ ")") orelse KNOWN_FOLDERS_DEFAULT_PATH;
exe.addPackage(.{ .name = "known-folders", .source = .{ .path = known_folders_path } });

exe.addPackage(.{ .name = "tres", .source = .{ .path = "src/tres/tres.zig" } });

if (enable_tracy) {
const client_cpp = "src/tracy/TracyClient.cpp";

Expand Down Expand Up @@ -146,6 +148,7 @@ pub fn build(b: *std.build.Builder) !void {
}

tests.addPackage(.{ .name = "zls", .source = .{ .path = "src/zls.zig" }, .dependencies = exe.packages.items });
tests.addPackage(.{ .name = "tres", .source = .{ .path = "src/tres/tres.zig" } });
tests.setBuildMode(.Debug);
tests.setTarget(target);
test_step.dependOn(&tests.step);
Expand Down
3 changes: 1 addition & 2 deletions src/DocumentStore.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const types = @import("types.zig");
const requests = @import("requests.zig");
const types = @import("lsp.zig");
const URI = @import("uri.zig");
const analysis = @import("analysis.zig");
const offsets = @import("offsets.zig");
Expand Down
38 changes: 27 additions & 11 deletions src/header.zig → src/Header.zig
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
const std = @import("std");

const RequestHeader = struct {
content_length: usize,
const Header = @This();

/// null implies "application/vscode-jsonrpc; charset=utf-8"
content_type: ?[]const u8,
content_length: usize,

pub fn deinit(self: @This(), allocator: std.mem.Allocator) void {
if (self.content_type) |ct| allocator.free(ct);
}
};
/// null implies "application/vscode-jsonrpc; charset=utf-8"
content_type: ?[]const u8 = null,

pub fn deinit(self: @This(), allocator: std.mem.Allocator) void {
if (self.content_type) |ct| allocator.free(ct);
}

pub fn readRequestHeader(allocator: std.mem.Allocator, instream: anytype) !RequestHeader {
var r = RequestHeader{
// Caller owns returned memory.
pub fn parse(allocator: std.mem.Allocator, reader: anytype) !Header {
var r = Header{
.content_length = undefined,
.content_type = null,
};
errdefer r.deinit(allocator);

var has_content_length = false;
while (true) {
const header = try instream.readUntilDelimiterAlloc(allocator, '\n', 0x100);
const header = try reader.readUntilDelimiterAlloc(allocator, '\n', 0x100);
defer allocator.free(header);
if (header.len == 0 or header[header.len - 1] != '\r') return error.MissingCarriageReturn;
if (header.len == 1) break;
Expand All @@ -41,3 +42,18 @@ pub fn readRequestHeader(allocator: std.mem.Allocator, instream: anytype) !Reque

return r;
}

pub fn format(
header: Header,
comptime unused_fmt_string: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) @TypeOf(writer).Error!void {
_ = options;
std.debug.assert(unused_fmt_string.len == 0);
try writer.print("Content-Length: {}\r\n", .{header.content_length});
if (header.content_type) |content_type| {
try writer.print("Content-Type: {s}\r\n", .{content_type});
}
try writer.writeAll("\r\n");
}
Loading