From 07ef45913eaabae1758e308ac5591f117fc18763 Mon Sep 17 00:00:00 2001 From: usr <81042605+a-usr@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:58:23 +0100 Subject: [PATCH 1/4] Fix omnisharp config deleting itself when config() is passed a user configuration, and add logging --- lua/csharp/config.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/csharp/config.lua b/lua/csharp/config.lua index c4ee802..7e9b58c 100644 --- a/lua/csharp/config.lua +++ b/lua/csharp/config.lua @@ -114,8 +114,9 @@ function M.set_defaults(user_config) } for index, key in ipairs(deprecated_omnisharp_keys) do - if merged_config.lsp.omnisharp[key] ~= nil then - merged_config.lsp.omnisharp[key] = nil + if merged_config.lsp[key] ~= nil then + merged_config.lsp[key] = nil + require("csharp.log").error("Use of deprecated key 'lsp."..key.."'. Use 'lsp.omnisharp."..key.."' instead.") end end From 0e81d7ad7928f3b0b344fe2cc7d142972fc21913 Mon Sep 17 00:00:00 2001 From: usr <81042605+a-usr@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:05:57 +0100 Subject: [PATCH 2/4] Update log.lua: Add log queue for logs during plugin initialization --- lua/csharp/log.lua | 77 ++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/lua/csharp/log.lua b/lua/csharp/log.lua index d136fb6..cf4e4d9 100644 --- a/lua/csharp/log.lua +++ b/lua/csharp/log.lua @@ -1,35 +1,12 @@ +local queue = {} local M = {} -function M.setup() - local ok, structlog = pcall(require, "structlog") - - if not ok then - vim.notify("csharp.nvim: structlog.nvim dependency is not installed. This won't prevent the plugin from working, but it's recommended to install it.", vim.log.levels.WARN) - return - end - - structlog.configure({ - csharp_logger = { - pipelines = { - { - level = structlog.level.TRACE, - processors = { - structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3 }), - structlog.processors.Timestamper("%H:%M:%S"), - function(log) - log["buffer"] = vim.api.nvim_get_current_buf() - return log - end, - }, - formatter = structlog.formatters.Format( -- - "%s [%s] %s: %-30s buffer=%s", - { "timestamp", "level", "logger_name", "msg", "buffer" } - ), - sink = structlog.sinks.File(vim.fn.stdpath("log") .. "/csharp.log"), - }, - }, - }, - }) +---Queue a log message until logging is initialized +---@param level string +---@param message string +---@param data table? +function M.queue(level, message, data) + table.insert(queue, {level = level, message = message, data = data}) end ---@param level string @@ -37,6 +14,9 @@ end ---@param data table? function M.log(level, message, data) local config = require("csharp.config").get_config().logging + if config == nil then + M.queue(level, message, data) + end local logger = require("structlog").get_logger("csharp_logger") if logger == nil or vim.log.levels[level] < vim.log.levels[config.level] then return @@ -74,4 +54,41 @@ end function M.error(message, data) M.log("ERROR", message, data) end + +function M.setup() + local ok, structlog = pcall(require, "structlog") + + if not ok then + vim.notify("csharp.nvim: structlog.nvim dependency is not installed. This won't prevent the plugin from working, but it's recommended to install it.", vim.log.levels.WARN) + return + end + + structlog.configure({ + csharp_logger = { + pipelines = { + { + level = structlog.level.TRACE, + processors = { + structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3 }), + structlog.processors.Timestamper("%H:%M:%S"), + function(log) + log["buffer"] = vim.api.nvim_get_current_buf() + return log + end, + }, + formatter = structlog.formatters.Format( -- + "%s [%s] %s: %-30s buffer=%s", + { "timestamp", "level", "logger_name", "msg", "buffer" } + ), + sink = structlog.sinks.File(vim.fn.stdpath("log") .. "/csharp.log"), + }, + }, + }, + }) + + for _, msg in pairs(queue) do + M.log(msg.level, msg.message, msg.data) + end +end + return M From 66e6dfdc4b090de12e60aa3928d06021c1895272 Mon Sep 17 00:00:00 2001 From: usr <81042605+a-usr@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:07:16 +0100 Subject: [PATCH 3/4] minor mistake --- lua/csharp/log.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/csharp/log.lua b/lua/csharp/log.lua index cf4e4d9..2e89a88 100644 --- a/lua/csharp/log.lua +++ b/lua/csharp/log.lua @@ -13,10 +13,11 @@ end ---@param message string ---@param data table? function M.log(level, message, data) - local config = require("csharp.config").get_config().logging + local config = require("csharp.config").get_config() if config == nil then M.queue(level, message, data) end + config = config.logging local logger = require("structlog").get_logger("csharp_logger") if logger == nil or vim.log.levels[level] < vim.log.levels[config.level] then return From 2f2530d517a13573bf00119ea388fc85e67f7aaf Mon Sep 17 00:00:00 2001 From: usr <81042605+a-usr@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:08:00 +0100 Subject: [PATCH 4/4] another one --- lua/csharp/log.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/csharp/log.lua b/lua/csharp/log.lua index 2e89a88..f664123 100644 --- a/lua/csharp/log.lua +++ b/lua/csharp/log.lua @@ -16,6 +16,7 @@ function M.log(level, message, data) local config = require("csharp.config").get_config() if config == nil then M.queue(level, message, data) + return end config = config.logging local logger = require("structlog").get_logger("csharp_logger")