-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): allow external modules to hook into
:Rocks sync
(#85)
- Loading branch information
Showing
5 changed files
with
173 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,12 @@ | |
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim | ||
-- Maintainer: NTBBloodbath <[email protected]> | ||
|
||
---@alias rock_name string | ||
|
||
---@class Rock | ||
---@field name string | ||
---@field name rock_name | ||
---@field version string | ||
|
||
---@alias rock_name string | ||
|
||
local api = {} | ||
|
||
local cache = require("rocks.cache") | ||
|
@@ -33,6 +33,7 @@ local fzy = require("rocks.fzy") | |
local luarocks = require("rocks.luarocks") | ||
local nio = require("nio") | ||
local state = require("rocks.state") | ||
local operations = require("rocks.operations") | ||
|
||
---Tries to get the cached rocks. | ||
---Returns an empty list if the cache has not been populated | ||
|
@@ -117,4 +118,25 @@ function api.register_rocks_subcommand(name, cmd) | |
commands.register_subcommand(name, cmd) | ||
end | ||
|
||
---@class RockSpec: { name: rock_name, version?: string, [string]: any } | ||
---@brief [[ | ||
--- { name: rock_name, version?: string, [string]: V } | ||
--- | ||
---Specification for a rock in rocks.toml. | ||
---@brief ]] | ||
|
||
---@alias rock_handler_callback fun(report_progress: fun(message: string), report_error: fun(message: string)) | ||
---@brief [[ | ||
---A function that operates on the rock, syncing it with the entry in rocks.toml | ||
---@brief ]] | ||
|
||
---@class RockHandler | ||
---@field get_sync_callback fun(spec: RockSpec):rock_handler_callback|nil Return a function that installs or updates the rock, or `nil` if the handler cannot or does not need to sync the rock. | ||
---@field get_prune_callback fun(specs: table<rock_name, RockSpec>):rock_handler_callback|nil Return a function that prunes unused rocks, or `nil` if the handler cannot or does not need to prune any rocks. | ||
|
||
---@param handler RockHandler | ||
function api.register_rock_handler(handler) | ||
operations.register_handler(handler) | ||
end | ||
|
||
return api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
---@mod rocks.log rocks.nvim logging | ||
---@mod rocks.log rocks.nvim logging API | ||
--- | ||
---@brief [[ | ||
--- | ||
---The internal logging interface for rocks.nvim | ||
---The logging interface for rocks.nvim. | ||
---Intended to be used by external modules. | ||
--- | ||
---@brief ]] | ||
|
||
|
@@ -15,15 +16,21 @@ | |
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim | ||
-- Maintainer: NTBBloodbath <[email protected]> | ||
|
||
local log = { | ||
-- NOTE: These functions are initialised as empty for type checking purposes | ||
-- and implemented later. | ||
trace = function(_) end, | ||
debug = function(_) end, | ||
info = function(_) end, | ||
warn = function(_) end, | ||
error = function(_) end, | ||
} | ||
local log = {} | ||
|
||
-- NOTE: These functions are initialised as empty for type checking purposes | ||
-- and implemented later. | ||
|
||
---@type fun(any) | ||
function log.trace(_) end | ||
---@type fun(any) | ||
function log.debug(_) end | ||
---@type fun(any) | ||
function log.info(_) end | ||
---@type fun(any) | ||
function log.warn(_) end | ||
---@type fun(any) | ||
function log.error(_) end | ||
|
||
local LARGE = 1e9 | ||
|
||
|
@@ -37,20 +44,22 @@ end | |
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 | ||
end | ||
|
||
---Open the rocks.nvim log file. | ||
---@package | ||
function log.open_logfile() | ||
vim.cmd.e(log.get_logfile()) | ||
end | ||
|
||
local logfile, openerr | ||
--- @private | ||
--- Opens log file. Returns true if file is open, false on error | ||
--- @return boolean | ||
---@private | ||
---Opens log file. Returns true if file is open, false on error | ||
---@return boolean | ||
local function open_logfile() | ||
-- Try to open file only once | ||
if logfile then | ||
|
@@ -79,9 +88,10 @@ local function open_logfile() | |
return true | ||
end | ||
|
||
--- Set the log level | ||
--- @param level (string|integer) The log level | ||
--- @see vim.log.levels | ||
---Set the log level | ||
---@param level (string|integer) The log level | ||
---@see vim.log.levels | ||
---@package | ||
function log.set_level(level) | ||
local log_levels = vim.deepcopy(vim.log.levels) | ||
vim.tbl_add_reverse_lookup(log_levels) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters