docs: extension bundling (#2068)

This commit is contained in:
Simon Hauser
2022-07-12 15:48:10 +02:00
committed by GitHub
parent 5acb9474a0
commit 2d4ef4d6e5

View File

@@ -9,6 +9,7 @@
- [Oneshot job](#oneshot-job)
- [Previewer](#previewer)
- [More examples](#more-examples)
- [Bundling as Extension](#bundling-as-extension)
- [Technical](#technical)
- [picker](#picker)
- [finders](#finders)
@@ -278,6 +279,51 @@ more information on [gitter](https://gitter.im/nvim-telescope/community?utm_sour
and we will happily answer your questions and hopefully allow us to improve this guide. You can also
help us to improve this guide by sending a PR.
### Bundling as extension
If you now want to bundle your picker as extension, so it is available as
picker via the `:Telescope` command, the following has to be done.
Structure your plugin as follows, so it can be found by telescope:
```
.
└── lua
├── plugin_name # Your actual plugin code
│ ├── init.lua
│ └── some_file.lua
└── telescope
└── _extensions # The underscore is significant
└─ plugin_name.lua # Init and register your extension
```
The `lua/telescope/_extensions/plugin_name.lua` file needs to return the
following: (see `:help telescope.register_extension`)
```lua
return require("telescope").register_extension {
setup = function(ext_config, config)
-- access extension config and user config
end,
exports = {
stuff = require("plugin_name").stuff
},
}
```
The setup function can be used to access the extension config and setup
extension specific global configuration. You also have access to the user
telescope default config, so you can override specific internal function. For
example sorters if you have an extension that provides a replacement sorter,
like
[telescope-fzf-native](https://github.com/nvim-telescope/telescope-fzf-native.nvim).
The exports table declares the exported pickers that can then be accessed via
`Telescope plugin_name stuff`. If you only provide one export it is suggested
that you name the key like the plugin, so you can access it with `Telescope
plugin_name`.
## Technical
### Picker