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

Fix omnisharp config spontaneously combusting #18

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions lua/csharp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
81 changes: 50 additions & 31 deletions lua/csharp/log.lua
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
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
---@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)
return
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
Expand Down Expand Up @@ -74,4 +56,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