correctly handle path to uri conversion

This commit is contained in:
Techatrix 2022-08-20 15:34:36 +02:00
parent d57f8e3a64
commit f543659e31
2 changed files with 6 additions and 6 deletions

View File

@ -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 {

View File

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