Skip to content

Commit 68268b4

Browse files
committed
add development sectionn
1 parent 8bdd4d1 commit 68268b4

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use { 'sourcegraph/sg.nvim', run = 'nvim -l build/init.lua' }
7676
use { 'nvim-lua/plenary.nvim' }
7777

7878
-- And optionally, you can install telescope for some search functionality
79-
-- "nvim-lua/plenary.nvim", --[[ "nvim-telescope/telescope.nvim ]]
79+
-- "nvim-lua/plenary.nvim", --[[ "nvim-telescope/telescope.nvim ]]
8080
```
8181
</details>
8282

@@ -190,3 +190,56 @@ For Nix contributors and maintainers:
190190

191191
[nix-flakes]: https://nixos.wiki/wiki/Flakes
192192

193+
## Development
194+
195+
### Loading the plugin
196+
To be able to test our changes we need to tell our favourite plugin manager to load the plugin locally rather than clone it from GitHub. Below is a snippet on how to do it with `lazy.nvim`
197+
198+
```lua
199+
{
200+
--- The dir specified here is the absolute path to the sg.nvim repository
201+
dir = "~/code/path-to-sg-nvim-repo",
202+
dependencies = { "nvim-lua/plenary.nvim" }
203+
}
204+
```
205+
206+
### Dynamically switch to loading the plugin from the repository
207+
208+
For ease for development it can be useful to automatically switch to loading the plugin from this repository if we enter this directory. We can do this by doing the following:
209+
210+
1. In your plugin manager configuration, create the following function
211+
212+
```lua
213+
local function load_sg()
214+
if vim.env.SG_NVIM_DEV then
215+
return { dir = vim.fn.getcwd(), dependencies = { "nvim-lua/plenary.nvim" } }
216+
else
217+
--- This is the configuration that lazy.nvim expects, but you can change it to whatever configuration your plugin manager expects
218+
return {
219+
"sourcegraph/sg.nvim",
220+
dependencies = { "nvim-lua/plenary.nvim" },
221+
}
222+
end
223+
end
224+
```
225+
2. Update your configuration - example (lazy.nvim):
226+
227+
```lua
228+
require("lazy").setup({
229+
"example/other-plugin",
230+
load_sg(),
231+
}
232+
```
233+
3. Finally, we need the `SG_NVIM_DEV` variable to exist in our environment as soon as we enter the repository. We can do that by using [direnv](https://direnv.net/) which automatically loads `.envrc` is it exists. Let's edit the present `.envrc`
234+
235+
```bash
236+
export SG_NVIM_DEV="true"
237+
# If nix-shell available, then nix is installed. We're going to use nix-direnv.
238+
# for automatic devshell injection after opt-in `direnv allow`
239+
if command -v nix-shell &> /dev/null
240+
then
241+
use flake
242+
fi
243+
```
244+
245+
With the above changes, as soon as we enter this repository directory `direnv` will run `.envrc` which exports our `SG_NVIM_DEV` variable. Once we open Neovim and our plugins are loaded our `load_sg` function will get executed and see the `SG_NVIM_DEV` varialbe in the environment and rather load the `sg.nvim` plugin from the current working directory!

0 commit comments

Comments
 (0)