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

Lazy luarocks support #1506

Merged
merged 4 commits into from
Jul 8, 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
47 changes: 13 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ Neorg's setup process is slightly more complex than average, so we encourage you

**After you're done with the installation process, run `:checkhealth neorg` to see if everything's correct!**

> [!TIP]
> If you're having severe difficulties with installing `8.0.0`, we encourage you to try the `7.0.0` version
> instead. You will not have all of the latest features but Neorg will continue to function there.

### `rocks.nvim`

The recommended installation method is via [rocks.nvim](https://github.com/nvim-neorocks/rocks.nvim).
One way of installing Neorg is via [rocks.nvim](https://github.com/nvim-neorocks/rocks.nvim).

<details open>
<details>
<summary>Installation snippet.</summary>

- Run `:Rocks install rocks-config.nvim` (if you don't have it already!).
Expand Down Expand Up @@ -114,38 +110,21 @@ which will get you up and running with Neorg without any prior Neovim configurat

### `lazy.nvim`

In order to install Neorg via `lazy.nvim`, you must take a few extra steps - this is because `luarocks` is a critical component for Neorg to function.
See [this blog](https://vhyrro.github.io/posts/neorg-and-luarocks/) for more information.

> [!IMPORTANT]
> Using luarocks Neorg will install itself and these dependencies with their respective versions:
> - `lua-utils.nvim`
> - `nvim-nio`
> - `nui.nvim`
> - `plenary.nvim`
> - `pathlib.nvim`
To install Neorg via lazy, first ensure that you have `luarocks` installed on your system.
On Linux/Mac, this involves installing using your system's package manager. On Windows, consider
the [Lua for Windows](https://github.com/rjpcomputing/luaforwindows) all-in-one package.

<details>
<summary>Click for installation snippet.</summary>

- Ensure you have [`vhyrro/luarocks.nvim`](https://github.com/vhyrro/luarocks.nvim) installed (**NOTE**: there are additional install steps in that README):
```lua
{
"vhyrro/luarocks.nvim",
priority = 1000,
config = true,
}
```
- Add the following to your plugin list:
```lua
{
"nvim-neorg/neorg",
dependencies = { "luarocks.nvim" },
lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
version = "*", -- Pin Neorg to the latest stable release
config = true,
}
```
```lua
{
"nvim-neorg/neorg",
lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
version = "*", -- Pin Neorg to the latest stable release
config = true,
}
```

</details>

Expand Down
26 changes: 0 additions & 26 deletions build.lua

This file was deleted.

4 changes: 1 addition & 3 deletions lua/neorg/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ local neorg = {
log = require("neorg.core.log"),
modules = require("neorg.core.modules"),
utils = require("neorg.core.utils"),

---@module "lua-utils"
lib = nil,
lib = require("lua-utils"),
}

return neorg
30 changes: 4 additions & 26 deletions lua/neorg/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ return {
)
)
else
vim.health.ok(string.format("Module declaration `%s` is well-formed", key))
vim.health.ok(string.format("Module declaration for `%s` is well-formed", key))
end
end

Expand All @@ -71,32 +71,10 @@ return {

vim.health.info("Checking existence of dependencies...")

if pcall(require, "lazy") then
if not (pcall(require, "luarocks-nvim")) then
vim.health.error(
"Required dependency `vhyrro/luarocks.nvim` not found! Neither `theHamsta/nvim_rocks` nor `camspiers/luarocks` are compatible. Check installation instructions in the README for how to fix the error."
)
else
vim.health.ok("Required dependency `vhyrro/luarocks` found!")

vim.health.info("Checking existence of luarocks dependencies...")

local has_lua_utils = (pcall(require, "lua-utils"))

if not has_lua_utils then
vim.health.error(
"Critical dependency `lua-utils.nvim` not found! Please run `:Lazy build luarocks.nvim` and then `:Lazy build neorg`! Neorg will refuse to load."
)
else
vim.health.ok("Critical dependencies are installed. You are free to use Neorg!")
vim.health.warn("If you ever encounter errors please rerun `:Lazy build neorg` again :)")
end
end
if vim.fn.executable("luarocks") then
vim.health.ok("`luarocks` is installed.")
else
vim.health.ok("Using plugin manager other than lazy, no need for the `vhyrro/luarocks.nvim` dependency.")
vim.health.warn(
"If you are on an unsupported plugin manager you may still need the plugin for Neorg to function."
)
vim.health.error("`luarocks` not installed on your system! Please consult the Neorg README for installation instructions.")
end
end,
}
42 changes: 0 additions & 42 deletions lua/neorg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
local neorg = require("neorg.core")
local config, log, modules = neorg.config, neorg.log, neorg.modules

-- HACK(vhyrro): This variable is here to prevent issues with lazy's build.lua script loading.

---@type neorg.configuration.user?
local user_configuration

--- @module "neorg.core.config"

--- Initializes Neorg. Parses the supplied user configuration, initializes all selected modules and adds filetype checking for `.norg`.
Expand All @@ -36,19 +31,6 @@ function neorg.setup(cfg)
}
end

if not (pcall(require, "lua-utils")) then
vim.notify(
"Warning [neorg]: lua-utils not found. If you're just installing the plugin, ignore this message, when in doubt run `:Lazy build neorg`. If you're not on lazy please rerun the build scripts.",
vim.log.levels.WARN
)

-- Allow neorg to be reloaded once more.
package.loaded.neorg = nil

user_configuration = cfg
return
end

config.user_config = vim.tbl_deep_extend("force", config.user_config, cfg)

-- Create a new global instance of the neorg logger.
Expand All @@ -62,11 +44,6 @@ function neorg.setup(cfg)
},
})

local ok, lua_utils = pcall(require, "lua-utils")
assert(ok, "unable to find lua-utils dependency. Perhaps try restarting Neovim?")

neorg.lib = lua_utils

-- If the file we have entered has a `.norg` extension:
if vim.fn.expand("%:e") == "norg" or not config.user_config.lazy_loading then
-- Then boot up the environment.
Expand All @@ -87,25 +64,6 @@ function neorg.setup(cfg)
end
end

--- Equivalent of `setup()`, but is executed by Lazy.nvim's build.lua script.
--- It attempts to pull the configuration options provided by the user when setup()
--- first ran, and relays those configuration options to the actual Neorg runtime.
function neorg.setup_after_build()
if not user_configuration then
return
end

package.loaded["lua-utils"] = nil

-- HACK(vhyrro): Please do this elsewhere.
local ok, lua_utils = pcall(require, "lua-utils")
assert(ok, "unable to find lua-utils dependency. Perhaps try restarting Neovim?")

neorg.lib = lua_utils

neorg.setup(user_configuration)
end

--- This function gets called upon entering a .norg file and loads all of the user-defined modules.
--- @param manual boolean If true then the environment was kickstarted manually by the user.
--- @param arguments string? A list of arguments in the format of "key=value other_key=other_value".
Expand Down
127 changes: 63 additions & 64 deletions res/wiki/static/Kickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ Get up and running with Neorg even with zero Neovim knowledge.

To use this configuration, a set of prerequisites must be fulfilled beforehand.

1. Install one of the Nerd fonts, for example Meslo Nerd Font from [Nerd Fonts](https://www.nerdfonts.com/font-downloads).
1. Install one of the Nerd fonts, for example the Meslo Nerd Font from [Nerd Fonts](https://www.nerdfonts.com/font-downloads).
2. Set your terminal font to the installed Nerd Font.
3. Make sure you have git by running `git --version`.
4. Ensure you have Lua 5.1 *or* LuaJIT installed on your system:
4. Ensure you have Luarocks installed on your system:
- **Windows**: install [lua for windows](https://github.com/rjpcomputing/luaforwindows/releases/tag/v5.1.5-52).
- **MacOS**: install via `brew install luajit`. Lua 5.1 is incorrectly marked as "deprecated" on MacOS systems, therefore luajit should be used instead.
- **`apk`**: `sudo apk add luajit luajit-dev wget`
- **`apt`**: `sudo apt install liblua5.1-0-dev`
- **`dnf`**: `sudo dnf install compat-lua-devel-5.1.5`
- **`pacman`**: `sudo pacman -Syu luajit`
- **MacOS**: install via `brew install luarocks`.
- **`apk`**: `sudo apk add luarocks wget`
- **`apt`**: `sudo apt install luarocks`
- **`dnf`**: `sudo dnf install luarocks`
- **`pacman`**: `sudo pacman -Syu luarocks`

## Troubleshooting

If you have any issues like bold or italic not rendering or highlights being improperly applied
If you have any issues like bold/italic not rendering or highlights being improperly applied
I encourage you to check out the [dependencies document](https://github.com/nvim-neorg/neorg/wiki/Dependencies) which explains troubleshooting steps
for different kinds of terminals.

Expand All @@ -38,75 +38,74 @@ With that, let's begin!

Put the following into the `init.lua` file:
```lua
-- Adapted from https://github.com/folke/lazy.nvim#-installation

-- Install lazy.nvim
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)

-- Set up both the traditional leader (for keymaps) as well as the local leader (for norg files)
vim.g.mapleader = " "
vim.g.maplocalleader = ","

-- Setup lazy.nvim
require("lazy").setup({
{
"rebelot/kanagawa.nvim", -- neorg needs a colorscheme with treesitter support
config = function()
vim.cmd.colorscheme("kanagawa")
end,
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
opts = {
ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
highlight = { enable = true },
spec = {
{
"rebelot/kanagawa.nvim", -- neorg needs a colorscheme with treesitter support
config = function()
vim.cmd.colorscheme("kanagawa")
end,
},
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
end,
},
{
"vhyrro/luarocks.nvim",
priority = 1000,
config = true,
},
{
"nvim-neorg/neorg",
dependencies = { "luarocks.nvim" },
version = "*",
config = function()
require("neorg").setup {
load = {
["core.defaults"] = {},
["core.concealer"] = {},
["core.dirman"] = {
config = {
workspaces = {
notes = "~/notes",
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
opts = {
ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
highlight = { enable = true },
},
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
end,
},
{
"nvim-neorg/neorg",
lazy = false,
version = "*",
config = function()
require("neorg").setup {
load = {
["core.defaults"] = {},
["core.concealer"] = {},
["core.dirman"] = {
config = {
workspaces = {
notes = "~/notes",
},
default_workspace = "notes",
},
default_workspace = "notes",
},
},
},
}

vim.wo.foldlevel = 99
vim.wo.conceallevel = 2
end,
}
}

vim.wo.foldlevel = 99
vim.wo.conceallevel = 2
end,
},
},
})
```
- Close and reopen Neovim. Everything should just work! If you do not see Neorg working
for any reason, run `:Lazy build luarocks.nvim` and afterwards `:Lazy build neorg`.
- Open up any `.norg` file and start typing!
- Close and reopen Neovim. Everything should just work!
- Open up any `.norg` file and start typing! You may see an initial error, just hit enter a few times, after
which Neorg should immediately fix itself.
Loading