mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
plugins/openscad: migrate to mkVimPlugin
This commit is contained in:
parent
17905dec3d
commit
4f1fe403b1
5 changed files with 186 additions and 72 deletions
|
@ -32,6 +32,7 @@ EXCLUDES: list[str] = [
|
|||
"plugins/by-name/none-ls/prettierd.nix",
|
||||
"plugins/by-name/none-ls/settings.nix",
|
||||
"plugins/by-name/none-ls/sources.nix",
|
||||
"plugins/by-name/openscad/fuzzy-finder-plugin-option.nix",
|
||||
"plugins/by-name/rustaceanvim/renamed-options.nix",
|
||||
"plugins/by-name/rustaceanvim/settings-options.nix",
|
||||
"plugins/by-name/startify/options.nix",
|
||||
|
@ -75,7 +76,6 @@ KNOWN_PATHS: dict[
|
|||
"plugins/by-name/lint/default.nix": (State.OLD, Kind.NEOVIM, False),
|
||||
"plugins/by-name/lspkind/default.nix": (State.OLD, Kind.NEOVIM, False),
|
||||
"plugins/by-name/nix-develop/default.nix": (State.OLD, Kind.NEOVIM, False),
|
||||
"plugins/by-name/openscad/default.nix": (State.OLD, Kind.VIM, False),
|
||||
"plugins/by-name/rainbow-delimiters/default.nix": (State.OLD, Kind.NEOVIM, False),
|
||||
"plugins/by-name/treesitter-refactor/default.nix": (State.OLD, Kind.MISC, True),
|
||||
"plugins/by-name/treesitter-textobjects/default.nix": (
|
||||
|
|
|
@ -1,81 +1,93 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
defaultFuzzyFinder = "skim";
|
||||
inherit (lib) types;
|
||||
inherit (lib.nixvim) defaultNullOpts applyPrefixToAttrs;
|
||||
inherit (lib.nixvim.vim-plugin) mkSettingsOptionDescription;
|
||||
|
||||
name = "openscad";
|
||||
globalPrefix = "openscad_";
|
||||
in
|
||||
{
|
||||
options.plugins.openscad = {
|
||||
enable = mkEnableOption "openscad.nvim, a plugin to manage OpenSCAD files";
|
||||
lib.nixvim.neovim-plugin.mkNeovimPlugin {
|
||||
inherit name;
|
||||
packPathName = "openscad.nvim";
|
||||
package = "openscad-nvim";
|
||||
|
||||
package = lib.mkPackageOption pkgs "openscad.nvim" {
|
||||
default = [
|
||||
"vimPlugins"
|
||||
"openscad-nvim"
|
||||
];
|
||||
};
|
||||
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||
|
||||
fuzzyFinder = helpers.defaultNullOpts.mkEnum [
|
||||
"skim"
|
||||
"fzf"
|
||||
] defaultFuzzyFinder "fuzzy finder to find documentation";
|
||||
# TODO: Added 2024-12-17; remove after 25.05
|
||||
optionsRenamedToSettings = import ./renamed-options.nix;
|
||||
|
||||
cheatsheetWindowBlend = helpers.defaultNullOpts.mkNullable (types.ints.between 0 100) 15 "";
|
||||
settingsOptions = {
|
||||
fuzzy_finder = defaultNullOpts.mkStr "skim" ''
|
||||
Fuzzy finder to find documentation.
|
||||
|
||||
loadSnippets = helpers.defaultNullOpts.mkBool false "";
|
||||
If you set this option explicitly, Nixvim will install the relevant finder plugin.
|
||||
'';
|
||||
|
||||
autoOpen = helpers.defaultNullOpts.mkBool false "";
|
||||
cheatsheet_window_blend = defaultNullOpts.mkNullable (types.ints.between 0 100) 15 ''
|
||||
Transparency level of the cheatsheet window (in %).
|
||||
'';
|
||||
|
||||
keymaps = {
|
||||
enable = mkEnableOption "keymaps for openscad";
|
||||
load_snippets = defaultNullOpts.mkBool false ''
|
||||
Whether to load predefined snippets for OpenSCAD.
|
||||
'';
|
||||
|
||||
cheatsheetToggle = helpers.defaultNullOpts.mkStr "<Enter>" "Toggle cheatsheet window";
|
||||
auto_open = defaultNullOpts.mkBool false ''
|
||||
Whether the openscad project automatically be opened on startup.
|
||||
'';
|
||||
|
||||
helpTrigger = helpers.defaultNullOpts.mkStr "<A-h>" "Fuzzy find help resource";
|
||||
default_mappings = defaultNullOpts.mkBool true ''
|
||||
Whether to enable the default mappings.
|
||||
'';
|
||||
|
||||
helpManualTrigger = helpers.defaultNullOpts.mkStr "<A-m>" "Open offline openscad manual in pdf via zathura";
|
||||
cheatsheet_toggle_key = defaultNullOpts.mkStr "<Enter>" ''
|
||||
Keyboard shortcut for toggling the cheatsheet.
|
||||
'';
|
||||
|
||||
execOpenSCADTrigger = helpers.defaultNullOpts.mkStr "<A-o>" "Open file in OpenSCAD";
|
||||
help_trig_key = defaultNullOpts.mkStr "<A-h>" ''
|
||||
Keyboard shortcut for triggering the fuzzy-find help resource.
|
||||
'';
|
||||
|
||||
topToggle = helpers.defaultNullOpts.mkStr "<A-c>" "toggle htop filtered for openscad processes";
|
||||
};
|
||||
help_manual_trig_key = defaultNullOpts.mkStr "<A-m>" ''
|
||||
Keyboard shortcut for manually triggering the offline OpenSCAD manual.
|
||||
'';
|
||||
|
||||
exec_openscad_trig_key = defaultNullOpts.mkStr "<A-o>" ''
|
||||
Keyboard shortcut for opening the current file in OpenSCAD.
|
||||
'';
|
||||
|
||||
top_toggle = defaultNullOpts.mkStr "<A-c>" ''
|
||||
Keyboard shortcut for toggling `htop` filtered for OpenSCAD processes.
|
||||
'';
|
||||
};
|
||||
|
||||
config =
|
||||
let
|
||||
cfg = config.plugins.openscad;
|
||||
fuzzyFinder = if (cfg.fuzzyFinder == null) then defaultFuzzyFinder else cfg.fuzzyFinder;
|
||||
in
|
||||
mkIf cfg.enable {
|
||||
extraPlugins =
|
||||
with pkgs.vimPlugins;
|
||||
[ cfg.package ]
|
||||
++ (optional (fuzzyFinder == "skim") skim-vim)
|
||||
++ (optional (fuzzyFinder == "fzf") fzf-vim);
|
||||
settingsExample = {
|
||||
load_snippets = true;
|
||||
fuzzy_finder = "fzf";
|
||||
cheatsheet_window_blend = 15;
|
||||
auto_open = true;
|
||||
};
|
||||
|
||||
extraConfigLua = ''
|
||||
require('openscad')
|
||||
'';
|
||||
settingsDescription = mkSettingsOptionDescription { inherit name globalPrefix; };
|
||||
|
||||
globals = mkMerge [
|
||||
{
|
||||
openscad_fuzzy_finder = cfg.fuzzyFinder;
|
||||
openscad_cheatsheet_window_blend = cfg.cheatsheetWindowBlend;
|
||||
openscad_load_snippets = cfg.loadSnippets;
|
||||
}
|
||||
(mkIf cfg.keymaps.enable {
|
||||
openscad_default_mappings = true;
|
||||
openscad_cheatsheet_toggle_key = cfg.keymaps.cheatsheetToggle;
|
||||
openscad_help_trig_key = cfg.keymaps.helpTrigger;
|
||||
openscad_help_manual_trig_key = cfg.keymaps.helpManualTrigger;
|
||||
openscad_exec_openscad_trig_key = cfg.keymaps.execOpenSCADTrigger;
|
||||
openscad_top_toggle = cfg.keymaps.topToggle;
|
||||
})
|
||||
];
|
||||
};
|
||||
callSetup = false;
|
||||
|
||||
extraOptions = {
|
||||
fuzzyFinderPlugin = import ./fuzzy-finder-plugin-option.nix { inherit lib config pkgs; };
|
||||
};
|
||||
|
||||
extraConfig = cfg: {
|
||||
plugins.openscad.luaConfig.content = ''
|
||||
require('openscad')
|
||||
'';
|
||||
|
||||
globals = applyPrefixToAttrs globalPrefix cfg.settings;
|
||||
|
||||
extraPlugins = [ cfg.fuzzyFinderPlugin ];
|
||||
};
|
||||
}
|
||||
|
|
50
plugins/by-name/openscad/fuzzy-finder-plugin-option.nix
Normal file
50
plugins/by-name/openscad/fuzzy-finder-plugin-option.nix
Normal file
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
}:
|
||||
let
|
||||
optionName = "`settings.fuzzy_finder`";
|
||||
|
||||
fuzzyFinder = config.plugins.openscad.settings.fuzzy_finder;
|
||||
|
||||
defaultPluginName =
|
||||
{
|
||||
skim = "skim-vim";
|
||||
fzf = "fzf-vim";
|
||||
}
|
||||
.${fuzzyFinder} or null;
|
||||
|
||||
default =
|
||||
# If the user has not set `settings.fuzzy_finder`, do not pre-install a fuzzy-finder by default.
|
||||
if fuzzyFinder == null then
|
||||
null
|
||||
# Else, the value of `settings.fuzzy_finder` should be one of the supported options
|
||||
# (`skim` or `fzf`), else he has to provide a value (`null` or a package) to `fuzzyFinderPlugin`.
|
||||
else if defaultPluginName == null then
|
||||
throw ''
|
||||
We cannot automatically select a fuzzy finder plugin from the value given to `${optionName}`: "${fuzzyFinder}".
|
||||
Please, explicitly provide a value to the `plugins.openscad.fuzzyFinderPlugin`:
|
||||
- Either the package for the fuzzy finder plugin to be installed
|
||||
- or `null` if you do not want a plugin to be installed.
|
||||
''
|
||||
# Case where we automatically select the default plugin to install.
|
||||
else
|
||||
[
|
||||
"vimPlugins"
|
||||
defaultPluginName
|
||||
];
|
||||
|
||||
defaultText = lib.literalMD ''
|
||||
- `pkgs.vimPlugins.skim-vim` if ${optionName} is `"skim"`
|
||||
- `pkgs.vimPlugins.fzf-vim` if ${optionName} is `"fzf"`
|
||||
- `null` otherwise
|
||||
'';
|
||||
in
|
||||
lib.mkPackageOption pkgs "fuzzy finder" {
|
||||
nullable = true;
|
||||
inherit default;
|
||||
}
|
||||
// {
|
||||
inherit defaultText;
|
||||
}
|
48
plugins/by-name/openscad/renamed-options.nix
Normal file
48
plugins/by-name/openscad/renamed-options.nix
Normal file
|
@ -0,0 +1,48 @@
|
|||
[
|
||||
"fuzzyFinder"
|
||||
"cheatsheetWindowBlend"
|
||||
"loadSnippets"
|
||||
"autoOpen"
|
||||
{
|
||||
old = [
|
||||
"keymaps"
|
||||
"enabled"
|
||||
];
|
||||
new = "default_mappings";
|
||||
}
|
||||
{
|
||||
old = [
|
||||
"keymaps"
|
||||
"cheatsheetToggle"
|
||||
];
|
||||
new = "cheatsheet_toggle_key";
|
||||
}
|
||||
{
|
||||
old = [
|
||||
"keymaps"
|
||||
"helpTrigger"
|
||||
];
|
||||
new = "help_trig_key";
|
||||
}
|
||||
{
|
||||
old = [
|
||||
"keymaps"
|
||||
"helpManualTrigger"
|
||||
];
|
||||
new = "help_manual_trig_key";
|
||||
}
|
||||
{
|
||||
old = [
|
||||
"keymaps"
|
||||
"execOpenSCADTrigger"
|
||||
];
|
||||
new = "exec_openscad_trig_key";
|
||||
}
|
||||
{
|
||||
old = [
|
||||
"keymaps"
|
||||
"topToggle"
|
||||
];
|
||||
new = "top_toggle";
|
||||
}
|
||||
]
|
|
@ -7,26 +7,30 @@
|
|||
plugins.openscad = {
|
||||
enable = true;
|
||||
|
||||
fuzzyFinder = "skim";
|
||||
cheatsheetWindowBlend = 15;
|
||||
loadSnippets = false;
|
||||
autoOpen = false;
|
||||
|
||||
keymaps.enable = false;
|
||||
settings = {
|
||||
fuzzy_finder = "skim";
|
||||
cheatsheet_window_blend = 15;
|
||||
load_snippets = false;
|
||||
auto_open = false;
|
||||
default_mappings = true;
|
||||
cheatsheet_toggle_key = "<Enter>";
|
||||
help_trig_key = "<A-h>";
|
||||
help_manual_trig_key = "<A-m>";
|
||||
exec_openscad_trig_key = "<A-o>";
|
||||
top_toggle = "<A-c>";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
keymaps = {
|
||||
example = {
|
||||
plugins.openscad = {
|
||||
enable = true;
|
||||
|
||||
keymaps = {
|
||||
enable = true;
|
||||
cheatsheetToggle = "<Enter>";
|
||||
helpTrigger = "<A-h>";
|
||||
helpManualTrigger = "<A-m>";
|
||||
execOpenSCADTrigger = "<A-o>";
|
||||
topToggle = "<A-c>";
|
||||
settings = {
|
||||
load_snippets = true;
|
||||
fuzzy_finder = "fzf";
|
||||
cheatsheet_window_blend = 15;
|
||||
auto_open = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue