mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +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/prettierd.nix",
|
||||||
"plugins/by-name/none-ls/settings.nix",
|
"plugins/by-name/none-ls/settings.nix",
|
||||||
"plugins/by-name/none-ls/sources.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/renamed-options.nix",
|
||||||
"plugins/by-name/rustaceanvim/settings-options.nix",
|
"plugins/by-name/rustaceanvim/settings-options.nix",
|
||||||
"plugins/by-name/startify/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/lint/default.nix": (State.OLD, Kind.NEOVIM, False),
|
||||||
"plugins/by-name/lspkind/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/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/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-refactor/default.nix": (State.OLD, Kind.MISC, True),
|
||||||
"plugins/by-name/treesitter-textobjects/default.nix": (
|
"plugins/by-name/treesitter-textobjects/default.nix": (
|
||||||
|
|
|
@ -1,81 +1,93 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
defaultFuzzyFinder = "skim";
|
inherit (lib) types;
|
||||||
|
inherit (lib.nixvim) defaultNullOpts applyPrefixToAttrs;
|
||||||
|
inherit (lib.nixvim.vim-plugin) mkSettingsOptionDescription;
|
||||||
|
|
||||||
|
name = "openscad";
|
||||||
|
globalPrefix = "openscad_";
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.neovim-plugin.mkNeovimPlugin {
|
||||||
options.plugins.openscad = {
|
inherit name;
|
||||||
enable = mkEnableOption "openscad.nvim, a plugin to manage OpenSCAD files";
|
packPathName = "openscad.nvim";
|
||||||
|
package = "openscad-nvim";
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "openscad.nvim" {
|
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
# TODO: Added 2024-12-17; remove after 25.05
|
||||||
"openscad-nvim"
|
optionsRenamedToSettings = import ./renamed-options.nix;
|
||||||
];
|
|
||||||
|
settingsOptions = {
|
||||||
|
fuzzy_finder = defaultNullOpts.mkStr "skim" ''
|
||||||
|
Fuzzy finder to find documentation.
|
||||||
|
|
||||||
|
If you set this option explicitly, Nixvim will install the relevant finder plugin.
|
||||||
|
'';
|
||||||
|
|
||||||
|
cheatsheet_window_blend = defaultNullOpts.mkNullable (types.ints.between 0 100) 15 ''
|
||||||
|
Transparency level of the cheatsheet window (in %).
|
||||||
|
'';
|
||||||
|
|
||||||
|
load_snippets = defaultNullOpts.mkBool false ''
|
||||||
|
Whether to load predefined snippets for OpenSCAD.
|
||||||
|
'';
|
||||||
|
|
||||||
|
auto_open = defaultNullOpts.mkBool false ''
|
||||||
|
Whether the openscad project automatically be opened on startup.
|
||||||
|
'';
|
||||||
|
|
||||||
|
default_mappings = defaultNullOpts.mkBool true ''
|
||||||
|
Whether to enable the default mappings.
|
||||||
|
'';
|
||||||
|
|
||||||
|
cheatsheet_toggle_key = defaultNullOpts.mkStr "<Enter>" ''
|
||||||
|
Keyboard shortcut for toggling the cheatsheet.
|
||||||
|
'';
|
||||||
|
|
||||||
|
help_trig_key = defaultNullOpts.mkStr "<A-h>" ''
|
||||||
|
Keyboard shortcut for triggering the fuzzy-find help resource.
|
||||||
|
'';
|
||||||
|
|
||||||
|
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.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
fuzzyFinder = helpers.defaultNullOpts.mkEnum [
|
settingsExample = {
|
||||||
"skim"
|
load_snippets = true;
|
||||||
"fzf"
|
fuzzy_finder = "fzf";
|
||||||
] defaultFuzzyFinder "fuzzy finder to find documentation";
|
cheatsheet_window_blend = 15;
|
||||||
|
auto_open = true;
|
||||||
cheatsheetWindowBlend = helpers.defaultNullOpts.mkNullable (types.ints.between 0 100) 15 "";
|
|
||||||
|
|
||||||
loadSnippets = helpers.defaultNullOpts.mkBool false "";
|
|
||||||
|
|
||||||
autoOpen = helpers.defaultNullOpts.mkBool false "";
|
|
||||||
|
|
||||||
keymaps = {
|
|
||||||
enable = mkEnableOption "keymaps for openscad";
|
|
||||||
|
|
||||||
cheatsheetToggle = helpers.defaultNullOpts.mkStr "<Enter>" "Toggle cheatsheet window";
|
|
||||||
|
|
||||||
helpTrigger = helpers.defaultNullOpts.mkStr "<A-h>" "Fuzzy find help resource";
|
|
||||||
|
|
||||||
helpManualTrigger = helpers.defaultNullOpts.mkStr "<A-m>" "Open offline openscad manual in pdf via zathura";
|
|
||||||
|
|
||||||
execOpenSCADTrigger = helpers.defaultNullOpts.mkStr "<A-o>" "Open file in OpenSCAD";
|
|
||||||
|
|
||||||
topToggle = helpers.defaultNullOpts.mkStr "<A-c>" "toggle htop filtered for openscad processes";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
settingsDescription = mkSettingsOptionDescription { inherit name globalPrefix; };
|
||||||
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);
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
callSetup = false;
|
||||||
|
|
||||||
|
extraOptions = {
|
||||||
|
fuzzyFinderPlugin = import ./fuzzy-finder-plugin-option.nix { inherit lib config pkgs; };
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = cfg: {
|
||||||
|
plugins.openscad.luaConfig.content = ''
|
||||||
require('openscad')
|
require('openscad')
|
||||||
'';
|
'';
|
||||||
|
|
||||||
globals = mkMerge [
|
globals = applyPrefixToAttrs globalPrefix cfg.settings;
|
||||||
{
|
|
||||||
openscad_fuzzy_finder = cfg.fuzzyFinder;
|
extraPlugins = [ cfg.fuzzyFinderPlugin ];
|
||||||
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;
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
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 = {
|
plugins.openscad = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
fuzzyFinder = "skim";
|
settings = {
|
||||||
cheatsheetWindowBlend = 15;
|
fuzzy_finder = "skim";
|
||||||
loadSnippets = false;
|
cheatsheet_window_blend = 15;
|
||||||
autoOpen = false;
|
load_snippets = false;
|
||||||
|
auto_open = false;
|
||||||
keymaps.enable = 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 = {
|
plugins.openscad = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
keymaps = {
|
settings = {
|
||||||
enable = true;
|
load_snippets = true;
|
||||||
cheatsheetToggle = "<Enter>";
|
fuzzy_finder = "fzf";
|
||||||
helpTrigger = "<A-h>";
|
cheatsheet_window_blend = 15;
|
||||||
helpManualTrigger = "<A-m>";
|
auto_open = true;
|
||||||
execOpenSCADTrigger = "<A-o>";
|
|
||||||
topToggle = "<A-c>";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue