Skip to content

Commit

Permalink
feat: deprecate rocks.api.source_runtime_dir (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Apr 25, 2024
1 parent 047b8f7 commit b93c313
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 83 deletions.
1 change: 1 addition & 0 deletions .github/workflows/luarocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
fidget.nvim >= 1.1.0
fzy
nvim-nio
rtp.nvim
labels: |
neovim
detailed_description: |
Expand Down
7 changes: 2 additions & 5 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,8 @@ api.register_rock_handler({handler}) *api.register_rock_handler*
{handler} (RockHandler)


api.source_runtime_dir({dir}) *api.source_runtime_dir*
Source the `plugin` and `ftdetect` directories.

Parameters: ~
{dir} (string) The runtime directory to source
api.source_runtime_dir() *api.source_runtime_dir*
@deprecated Use the rtp.nvim luarock


*api.install*
Expand Down
12 changes: 5 additions & 7 deletions lua/rocks/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
---
---@brief ]]

-- Copyright (C) 2023 Neorocks Org.
-- Copyright (C) 2024 Neorocks Org.
--
-- Version: 0.1.0
-- License: GPLv3
-- Created: 07 Dec 2023
-- Updated: 07 Dec 2023
-- Updated: 25 Apr 2024
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim
-- Maintainers: NTBBloodbath <[email protected]>, Vhyrro <[email protected]>, mrcjkb <[email protected]>

Expand All @@ -32,7 +31,6 @@ local luarocks = require("rocks.luarocks")
local nio = require("nio")
local state = require("rocks.state")
local operations = require("rocks.operations")
local runtime = require("rocks.runtime")

---Tries to get the cached rocks.
---Returns an empty list if the cache has not been populated
Expand Down Expand Up @@ -167,10 +165,10 @@ function api.register_rock_handler(handler)
operations.register_handler(handler)
end

---Source the `plugin` and `ftdetect` directories.
---@param dir string The runtime directory to source
---@deprecated Use the rtp.nvim luarock
function api.source_runtime_dir(dir)
runtime.source_rtp_dir(dir)
vim.deprecate("rocks.api.source_rtp_dir", "the rtp.nvim luarock", "3.0.0", "rocks.nvim")
require("rtp_nvim").source_rtp_dir(dir)
end

---Invoke ':Rocks install' with a callback
Expand Down
72 changes: 1 addition & 71 deletions lua/rocks/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
--
-- License: GPLv3
-- Created: 25 Dec 2023
-- Updated: 11 Apr 2024
-- Updated: 25 Apr 2024
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim
-- Maintainers: NTBBloodbath <[email protected]>, Vhyrro <[email protected]>, mrcjkb <[email protected]>

Expand All @@ -21,69 +21,6 @@ local log = require("rocks.log")

---@alias rock_pattern "*" | rock_name

---`ftdetect` scripts should only be sourced once.
---@type table<string, boolean|nil>
local _sourced_ftdetect = {}

---@enum RtpSourceDir Directories to be sourced on packadd
local RtpSourceDir = {
plugin = "plugin",
ftdetect = "ftdetect",
}

---Recursively iterate over a directory's children
---@param dir string
---@return fun(_:any, path:string):(path: string, name: string, type: string)
---@async
local function iter_children(dir)
return coroutine.wrap(function()
local handle = vim.uv.fs_scandir(dir)
while handle do
local name, ty = vim.uv.fs_scandir_next(handle)
local path = vim.fs.joinpath(dir, name)
ty = ty or vim.uv.fs_stat(path).type
if not name then
return
elseif ty == "directory" then
for child_path, child, child_type in iter_children(path) do
coroutine.yield(child_path, child, child_type)
end
end
coroutine.yield(path, name, ty)
end
end)
end

---@param rtp_source_dir RtpSourceDir
---@param dir string
local function source(rtp_source_dir, dir)
local rtp_dir = vim.fs.joinpath(dir, rtp_source_dir)
for script, name, ty in iter_children(rtp_dir) do
local ext = name:sub(-3)
if vim.tbl_contains({ "file", "link" }, ty) and vim.tbl_contains({ "lua", "vim" }, ext) then
local ok, err = pcall(vim.cmd.source, script)
if not ok and type(err) == "string" then
log.error(err)
vim.notify(err, vim.log.levels.ERROR)
break
end
end
end
end

---@param dir string
local function source_plugin(dir)
source(RtpSourceDir.plugin, dir)
end

---@param dir string
local function source_ftdetect(dir)
if not _sourced_ftdetect[dir] then
source(RtpSourceDir.ftdetect, dir)
_sourced_ftdetect[dir] = true
end
end

---@class rocks.PackaddOpts
---@field bang? boolean

Expand All @@ -106,13 +43,6 @@ function runtime.packadd(rock_name, opts)
return true
end

---Source the `plugin` and `ftdetect` directories
---@param dir string
function runtime.source_rtp_dir(dir)
source_plugin(dir)
source_ftdetect(dir)
end

---@param rock_spec RockSpec
---@return boolean?
local function is_start_plugin(rock_spec)
Expand Down
27 changes: 27 additions & 0 deletions nix/plugin-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@
nativeBuildInputs = with final; [cargo rustPlatform.cargoSetupHook] ++ oa.nativeBuildInputs;
});

rtp-nvim = luaself.callPackage ({
buildLuarocksPackage,
fetchzip,
fetchurl,
lua,
luaOlder,
}:
buildLuarocksPackage {
pname = "rtp.nvim";
version = "1.0.0-1";
knownRockspec =
(fetchurl {
url = "mirror://luarocks/rtp.nvim-1.0.0-1.rockspec";
sha256 = "0ddlwhk62g3yx1ysddsmlggfqv0hj7dljgczfwij1ijbz7qyp3hy";
})
.outPath;
src = fetchzip {
url = "https://github.com/nvim-neorocks/rtp.nvim/archive/v1.0.0.zip";
sha256 = "1kx7qzdz8rpwsjcp63wwn619nrkxn6xd0nr5pfm3g0z4072nnpzn";
};

disabled = luaOlder "5.1";
propagatedBuildInputs = [lua];
}) {};

nvim-nio =
# TODO: Replace with nixpkgs package when available
luaself.callPackage ({
Expand Down Expand Up @@ -113,6 +138,7 @@
fidget-nvim,
nvim-nio,
fzy,
rtp-nvim,
}:
buildLuarocksPackage {
pname = name;
Expand All @@ -126,6 +152,7 @@
fidget-nvim
nvim-nio
fzy
rtp-nvim
];
}) {};
};
Expand Down
1 change: 1 addition & 0 deletions nix/test-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
fidget-nvim
fzy
nvim-nio
rtp-nvim
];

extraPackages = [
Expand Down
2 changes: 2 additions & 0 deletions rocks.nvim-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies = {
"fidget.nvim >= 1.1.0",
"fzy",
"nvim-nio",
"rtp.nvim",
}

test_dependencies = {
Expand All @@ -20,6 +21,7 @@ test_dependencies = {
"fidget.nvim >= 1.1.0",
"fzy",
"nvim-nio",
"rtp.nvim",
}

source = {
Expand Down

0 comments on commit b93c313

Please sign in to comment.