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

feat(lua-api): add rocks.packadd function #214

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ opt = true
```

You can then load the plugin with the `:Rocks[!] packadd {rock}` command.
Or, before rocks.nvim is initialised, with `require("rocks").packadd("<rock_name>")`.

> [!NOTE]
>
Expand Down
27 changes: 23 additions & 4 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
==============================================================================
Table of Contents *rocks.contents*

rocks.nvim ····························································· |rocks|
rocks.nvim ························································ |rocks.nvim|
rocks.nvim Lua API ················································· |rocks.lua|
rocks.nvim commands ··········································· |rocks.commands|
rocks.nvim configuration ········································ |rocks.config|
rocks.nvim Lua API ················································· |rocks.api|
Lua API for rocks.nvim extensions ·································· |rocks.api|
rocks.nvim API hooks ········································· |rocks.api.hooks|
rocks.nvim logging API ············································· |rocks.log|

==============================================================================
rocks.nvim *rocks*
rocks.nvim *rocks.nvim*


A luarocks plugin manager for Neovim.


==============================================================================
rocks.nvim Lua API *rocks.lua*

rocks.packadd({rock_name}, {opts}) *rocks.packadd*
Search for a rock with `opt = true`, add it to the runtimepath and source any plugin files found.

Parameters: ~
{rock_name} (string)
{opts} (rocks.PackaddOpts)


rocks.PackaddOpts *rocks.PackaddOpts*

Fields: ~
{bang?} (boolean) If `true`, rocks.nvim will only add the rock to the runtimepath, but not source any plugin or ftdetect scripts. Default: `false`.
{packadd_fallback?} (boolean) Fall back to the builtin |packadd|? Default `true`.


==============================================================================
rocks.nvim commands *rocks.commands*

Expand Down Expand Up @@ -68,7 +87,7 @@ RocksOpts *RocksOpts*


==============================================================================
rocks.nvim Lua API *rocks.api*
Lua API for rocks.nvim extensions *rocks.api*


The Lua API for rocks.nvim.
Expand Down
2 changes: 1 addition & 1 deletion lua/rocks/api/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@mod rocks.api rocks.nvim Lua API
---@mod rocks.api Lua API for rocks.nvim extensions
---
---@brief [[
---
Expand Down
17 changes: 15 additions & 2 deletions lua/rocks/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---@toc rocks.contents

---@mod rocks rocks.nvim
---@mod rocks.nvim rocks.nvim
---
---@brief [[
---
Expand All @@ -13,10 +13,23 @@
-- Version: 0.1.0
-- License: GPLv3
-- Created: 05 Jul 2023
-- Updated: 27 Aug 2023
-- Updated: 20 Mar 2024
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim
-- Maintainers: NTBBloodbath <bloodbathalchemist@protonmail.com>, Vhyrro <vhyrro@gmail.com>, mrcjkb <marc@jakobi.dev>

---@mod rocks.lua rocks.nvim Lua API

local rocks = {}

---Search for a rock with `opt = true`, add it to the runtimepath and source any plugin files found.
---@param rock_name string
---@param opts rocks.PackaddOpts
function rocks.packadd(rock_name, opts)
require("rocks.runtime").packadd(rock_name, opts)
end

---@class rocks.PackaddOpts
---@field bang? boolean If `true`, rocks.nvim will only add the rock to the runtimepath, but not source any plugin or ftdetect scripts. Default: `false`.
---@field packadd_fallback? boolean Fall back to the builtin |packadd|? Default `true`.

return rocks
8 changes: 3 additions & 5 deletions lua/rocks/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,19 @@ local function rtp_append(rtp_glob)
_appended_rtp[rtp_glob] = true
end

---@class (exact) PackaddOpts
---@field bang? boolean
---@field packadd_fallback? boolean Fall back to the builtin |packadd|? Default `true`.
---@class PackaddOpts: rocks.PackaddOpts
---@field error_on_not_found? boolean Notify with an error message if no plugin could be found. Ignored if `packadd_fallback` is set to `true`.

---@param rock_name rock_name
---@param opts? PackaddOpts
---@param opts? rocks.PackaddOpts
function runtime.packadd(rock_name, opts)
---@cast rock_name rock_name
---@cast opts table
opts = vim.tbl_deep_extend("force", {
bang = false,
packadd_fallback = true,
error_on_not_found = false,
}, opts or {})
---@cast opts PackaddOpts
local rtp_glob = mk_rtp_glob(rock_name)
rtp_append(rtp_glob)
if opts.bang then
Expand Down
Loading