From f543659e31175476277bdeb9960b5743340a8a1d Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:34:36 +0200 Subject: [PATCH] correctly handle path to uri conversion --- src/DocumentStore.zig | 7 +++++-- src/translate_c.zig | 5 +---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 8038d24..5ac1446 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -605,12 +605,15 @@ fn translate(self: *DocumentStore, handle: *Handle, source: []const u8) !?[]cons }; defer self.allocator.free(include_dirs); - return translate_c.translate( + const file_path = (try translate_c.translate( self.allocator, self.config, include_dirs, source, - ); + )) orelse return null; + defer self.allocator.free(file_path); + + return try URI.fromPath(self.allocator, file_path); } fn refreshDocument(self: *DocumentStore, handle: *Handle) !void { diff --git a/src/translate_c.zig b/src/translate_c.zig index 7d7d43e..49d63b3 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -161,10 +161,7 @@ pub fn translate(allocator: std.mem.Allocator, config: Config, include_dirs: []c return switch (result.term) { .Exited => |code| if (code == 0) { - return try std.mem.join(allocator, "", &.{ - "file://", - std.mem.sliceTo(result.stdout, '\n'), - }); + return try allocator.dupe(u8, std.mem.sliceTo(result.stdout, '\n')); } else { // TODO convert failure to `textDocument/publishDiagnostics` std.log.err("zig translate-c process failed, code: {}, stderr: '{s}'", .{ code, result.stderr });