Skip to content

Commit

Permalink
feat: keep log file in rocks_path
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Apr 7, 2024
1 parent c9c0a6c commit 8b5e584
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/resources/init-windows.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vim.g.rocks_nvim = {
rocks_path = vim.fs.joinpath(vim.fn.getcwd(), "rocks"),
_log_level = vim.log.levels.TRACE,
}

local luarocks_path = {
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ jobs:
shell: bash
run: |
nvim -u .github/resources/init-windows.lua -c "lua io.write(require('rocks.config.internal').config_path)" +q 2>&1
cat rocks/rocks.log
3 changes: 3 additions & 0 deletions lua/rocks/api/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

local hooks = {}

local log = require("rocks.log")

---@param rock RockSpec
---@return string | nil
local function get_rocks_extension_module_name(rock)
Expand Down Expand Up @@ -54,6 +56,7 @@ end
---@package
---@param user_rocks RockSpec[]
function hooks.run_preload_hooks(user_rocks)
log.trace("Running preload hooks")
for _, rock_spec in pairs(user_rocks) do
local rock_extension_module_name = not rock_spec.opt and get_rocks_extension_module_name(rock_spec)
local hook = rock_extension_module_name and search_for_preload_hook(rock_extension_module_name)
Expand Down
2 changes: 2 additions & 0 deletions lua/rocks/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ local fzy = require("rocks.fzy")
local cache = require("rocks.cache")
local fs = require("rocks.fs")
local constants = require("rocks.constants")
local log = require("rocks.log")

---@param name string
---@param query string | nil
Expand Down Expand Up @@ -186,6 +187,7 @@ end

---@package
function commands.create_commands()
log.trace("Creating commands")
vim.api.nvim_create_user_command("Rocks", rocks, {
nargs = "+",
desc = "Interacts with currently installed rocks",
Expand Down
11 changes: 5 additions & 6 deletions lua/rocks/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ local function format_log(arg)
return vim.inspect(arg)
end

---For now, we have a log file per session
local logfilename = vim.fn.tempname() .. "-rocks-nvim.log"

---Get the rocks.nvim log file path.
---@package
---@return string filepath
function log.get_logfile()
return logfilename
return vim.fs.joinpath(require("rocks.config.internal").rocks_path, "rocks.log")
end

---Open the rocks.nvim log file.
Expand All @@ -69,7 +66,8 @@ local function open_logfile()
return false
end

logfile, openerr = io.open(log.get_logfile(), "a+")
vim.fn.mkdir(require("rocks.config.internal").rocks_path, "-p")
logfile, openerr = io.open(log.get_logfile(), "w+")
if not logfile then
local err_msg = string.format("Failed to open rocks.nvim log file: %s", openerr)
vim.notify(err_msg, vim.log.levels.ERROR)
Expand Down Expand Up @@ -139,6 +137,7 @@ for level, levelnr in pairs(vim.log.levels) do
end
end

log.set_level(vim.log.levels.INFO)
--- NOTE: We can't use rocks.config here, as that would lead to a cyclic module dependency
log.set_level(vim.tbl_get(vim.g, "rocks_nvim", "_log_level") or vim.log.levels.INFO)

return log
1 change: 1 addition & 0 deletions lua/rocks/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ end
---after we source start plugins.
---@param user_rocks RockSpec[]
function runtime.source_start_plugins(user_rocks)
log.trace("Sourcing start plugins")
for _, rock_spec in pairs(user_rocks) do
if not rock_spec.opt and rock_spec.version and rock_spec.name ~= constants.ROCKS_NVIM then
-- Append to rtp first in case a plugin needs another plugin's `autoload`
Expand Down
3 changes: 3 additions & 0 deletions plugin/rocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ end
local nio = require("nio")
local adapter = require("rocks.adapter")
local config = require("rocks.config.internal")
local log = require("rocks.log")

local function get_luarocks_lua_dir_from_luarocks()
local sc = vim.system({ config.luarocks_binary, "--lua-version=5.1", "which", "luarocks.loader" }):wait()
Expand Down Expand Up @@ -42,9 +43,11 @@ require("rocks.commands").create_commands()
local env_path_seperator = vim.uv.os_uname().sysname:lower():find("windows") and ";" or ":"

-- Append the binary directory to the system path.
log.trace("Appending luarocks binary directory to the system path")
vim.env.PATH = vim.fs.joinpath(config.rocks_path, "bin") .. env_path_seperator .. vim.env.PATH

if not config.lazy then
log.trace("Populating caches")
nio.run(function()
local cache = require("rocks.cache")
nio.gather({
Expand Down

0 comments on commit 8b5e584

Please sign in to comment.