Better log levels

This commit is contained in:
Alexandros Naskos 2020-07-07 22:16:29 +03:00
parent 39c0cf429b
commit f55d5a25aa

View File

@ -961,20 +961,20 @@ fn loadConfig(folder_path: []const u8) ?Config {
const file_buf = folder.readFileAlloc(allocator, "zls.json", 0x1000000) catch |err| {
if (err != error.FileNotFound)
std.log.debug(.main, "Error while reading configuration file: {}\n", .{err});
std.log.warn(.main, "Error while reading configuration file: {}\n", .{err});
return null;
};
defer allocator.free(file_buf);
// TODO: Better errors? Doesn't seem like std.json can provide us positions or context.
var config = std.json.parse(Config, &std.json.TokenStream.init(file_buf), std.json.ParseOptions{ .allocator = allocator }) catch |err| {
std.log.debug(.main, "Error while parsing configuration file: {}\n", .{err});
std.log.warn(.main, "Error while parsing configuration file: {}\n", .{err});
return null;
};
if (config.zig_lib_path) |zig_lib_path| {
if (!std.fs.path.isAbsolute(zig_lib_path)) {
std.log.debug(.main, "zig library path is not absolute, defaulting to null.\n", .{});
std.log.warn(.main, "zig library path is not absolute, defaulting to null.\n", .{});
allocator.free(zig_lib_path);
config.zig_lib_path = null;
}
@ -1051,8 +1051,6 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
try loadWorkspaceConfigs();
}
std.log.debug(.main, "{}\n", .{client_capabilities});
std.log.debug(.main, "Using offset encoding: {}\n", .{std.meta.tagName(offset_encoding)});
if (!send_encoding) {
try respondGeneric(id, initialize_response);
} else {
@ -1063,6 +1061,8 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
try respondGeneric(id, response_str);
}
std.log.notice(.main, "zls initialized", .{});
std.log.info(.main, "{}\n", .{client_capabilities});
std.log.notice(.main, "Using offset encoding: {}\n", .{std.meta.tagName(offset_encoding)});
}
var keep_running = true;
@ -1115,7 +1115,7 @@ fn changeDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, r
fn saveDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.SaveDocument, config: Config) error{OutOfMemory}!void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to save non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to save non existent document {}", .{req.params.textDocument.uri});
return;
};
try document_store.applySave(handle);
@ -1129,7 +1129,7 @@ fn semanticTokensHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, r
const this_config = configFromUriOr(req.params.textDocument.uri, config);
if (this_config.enable_semantic_tokens) {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to get semantic tokens of non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to get semantic tokens of non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, no_semantic_tokens_response);
};
@ -1147,7 +1147,7 @@ fn semanticTokensHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, r
fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Completion, config: Config) !void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to complete in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to complete in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, no_completions_response);
};
@ -1204,7 +1204,7 @@ fn signatureHelperHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId,
fn gotoHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.GotoDefinition, config: Config, resolve_alias: bool) !void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to go to definition in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to go to definition in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, null_result_response);
};
@ -1235,7 +1235,7 @@ fn gotoDeclarationHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId,
fn hoverHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Hover, config: Config) !void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to get hover in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to get hover in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, null_result_response);
};
@ -1257,7 +1257,7 @@ fn hoverHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: reque
fn documentSymbolsHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.DocumentSymbols, config: Config) !void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to get document symbols in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to get document symbols in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, null_result_response);
};
try documentSymbol(arena, id, handle);
@ -1266,7 +1266,7 @@ fn documentSymbolsHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId,
fn formattingHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Formatting, config: Config) !void {
if (config.zig_exe_path) |zig_exe_path| {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to got to definition in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to got to definition in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, null_result_response);
};
@ -1276,7 +1276,7 @@ fn formattingHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
process.stdout_behavior = .Pipe;
process.spawn() catch |err| {
std.log.debug(.main, "Failed to spawn zig fmt process, error: {}\n", .{err});
std.log.warn(.main, "Failed to spawn zig fmt process, error: {}\n", .{err});
return try respondGeneric(id, null_result_response);
};
try process.stdin.?.writeAll(handle.document.text);
@ -1308,7 +1308,7 @@ fn formattingHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
fn renameHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Rename, config: Config) !void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to rename in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to rename in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, null_result_response);
};
@ -1330,7 +1330,7 @@ fn renameHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requ
fn referencesHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.References, config: Config) !void {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
std.log.debug(.main, "Trying to get references in non existent document {}", .{req.params.textDocument.uri});
std.log.warn(.main, "Trying to get references in non existent document {}", .{req.params.textDocument.uri});
return try respondGeneric(id, null_result_response);
};
@ -1414,7 +1414,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
done = extractErr(method_info[2](arena, id, request_obj, config));
} else |err| {
if (err == error.MalformedJson) {
std.log.debug(.main, "Could not create request type {} from JSON {}\n", .{ @typeName(ReqT), json });
std.log.warn(.main, "Could not create request type {} from JSON {}\n", .{ @typeName(ReqT), json });
}
done = err;
}
@ -1433,7 +1433,6 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
};
const unimplemented_map = std.ComptimeStringMap(void, .{
.{"textDocument/references"},
.{"textDocument/documentHighlight"},
.{"textDocument/codeAction"},
.{"textDocument/codeLens"},
@ -1531,7 +1530,7 @@ pub fn main() anyerror!void {
const env_path = std.process.getEnvVarOwned(allocator, "PATH") catch |err| switch (err) {
error.EnvironmentVariableNotFound => {
std.log.debug(.main, "Could not get PATH.\n", .{});
std.log.warn(.main, "Could not get PATH.\n", .{});
break :find_zig;
},
else => return err,
@ -1552,21 +1551,21 @@ pub fn main() anyerror!void {
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
zig_exe_path = try std.mem.dupe(allocator, u8, std.os.realpath(full_path, &buf) catch continue);
std.log.debug(.main, "Found zig in PATH: {}\n", .{zig_exe_path});
std.log.info(.main, "Found zig in PATH: {}\n", .{zig_exe_path});
break :find_zig;
}
}
if (zig_exe_path) |exe_path| {
config.zig_exe_path = exe_path;
std.log.debug(.main, "Using zig executable {}\n", .{exe_path});
std.log.info(.main, "Using zig executable {}\n", .{exe_path});
if (config.zig_lib_path == null) {
// Set the lib path relative to the executable path.
config.zig_lib_path = try std.fs.path.resolve(allocator, &[_][]const u8{
std.fs.path.dirname(exe_path).?, "./lib/zig",
});
std.log.debug(.main, "Resolved standard library from executable: {}\n", .{config.zig_lib_path});
std.log.info(.main, "Resolved standard library from executable: {}\n", .{config.zig_lib_path});
}
}
@ -1579,7 +1578,6 @@ pub fn main() anyerror!void {
const build_runner_path = try std.fs.path.resolve(allocator, &[_][]const u8{ exe_dir_path, "build_runner.zig" });
try document_store.init(allocator, zig_exe_path, build_runner_path, config.zig_lib_path);
}
defer document_store.deinit();
workspace_folder_configs = std.StringHashMap(?Config).init(allocator);
@ -1604,7 +1602,7 @@ pub fn main() anyerror!void {
while (keep_running) {
const headers = readRequestHeader(&arena.allocator, reader) catch |err| {
std.log.debug(.main, "{}; exiting!", .{@errorName(err)});
std.log.crit(.main, "{}; exiting!", .{@errorName(err)});
return;
};
const buf = try arena.allocator.alloc(u8, headers.content_length);
@ -1616,7 +1614,7 @@ pub fn main() anyerror!void {
arena.state.buffer_list = .{};
if (debug_alloc) |dbg| {
std.log.debug(.main, "\n{}\n", .{dbg.info});
std.log.notice(.main, "\n{}\n", .{dbg.info});
}
}
}