mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
plugins/rest: switch to mkNeovimPlugin
This commit is contained in:
parent
3a161eaec0
commit
192b404e41
2 changed files with 365 additions and 184 deletions
|
@ -5,179 +5,320 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib; let
|
with lib;
|
||||||
cfg = config.plugins.rest;
|
helpers.neovim-plugin.mkNeovimPlugin config {
|
||||||
in {
|
name = "rest";
|
||||||
meta.maintainers = [maintainers.GaetanLepage];
|
originalName = "rest.nvim";
|
||||||
|
luaName = "rest-nvim";
|
||||||
|
defaultPackage = pkgs.vimPlugins.rest-nvim;
|
||||||
|
|
||||||
options.plugins.rest =
|
extraPackages = [pkgs.curl];
|
||||||
helpers.neovim-plugin.extraOptionsOptions
|
|
||||||
// {
|
|
||||||
enable = mkEnableOption "rest.nvim";
|
|
||||||
|
|
||||||
package = helpers.mkPackageOption "rest.nvim" pkgs.vimPlugins.rest-nvim;
|
maintainers = [maintainers.GaetanLepage];
|
||||||
|
|
||||||
resultSplitHorizontal = helpers.defaultNullOpts.mkBool false ''
|
# TODO introduced 2024-04-07: remove 2024-06-07
|
||||||
Open request results in a horizontal split (default opens on vertical).
|
deprecateExtraOptions = true;
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"envFile"
|
||||||
|
"encodeUrl"
|
||||||
|
"skipSslVerification"
|
||||||
|
"customDynamicVariables"
|
||||||
|
["highlight" "timeout"]
|
||||||
|
];
|
||||||
|
imports = let
|
||||||
|
basePluginPath = ["plugins" "rest"];
|
||||||
|
settingsPath = basePluginPath ++ ["settings"];
|
||||||
|
in [
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["resultSplitHorizontal"])
|
||||||
|
(settingsPath ++ ["result" "split" "horizontal"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["resultSplitInPlace"])
|
||||||
|
(settingsPath ++ ["result" "split" "in_place"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["stayInCurrentWindowAfterSplit"])
|
||||||
|
(settingsPath ++ ["result" "split" "stay_in_current_window_after_split"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["result" "showUrl"])
|
||||||
|
(settingsPath ++ ["result" "behavior" "show_info" "url"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["result" "showHeaders"])
|
||||||
|
(settingsPath ++ ["result" "behavior" "show_info" "headers"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["result" "showHttpInfo"])
|
||||||
|
(settingsPath ++ ["result" "behavior" "show_info" "http_info"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["result" "showCurlCommand"])
|
||||||
|
(settingsPath ++ ["result" "behavior" "show_info" "curl_command"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRemovedOptionModule
|
||||||
|
(basePluginPath ++ ["result" "showStatistics"])
|
||||||
|
''
|
||||||
|
Use `plugins.rest.settings.result.behavior.statistics.{enable,stats}` instead.
|
||||||
|
Refer to the documentation for more information.
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["result" "formatters"])
|
||||||
|
(settingsPath ++ ["result" "behavior" "formatters"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRenamedOptionModule
|
||||||
|
(basePluginPath ++ ["highlight" "enabled"])
|
||||||
|
(settingsPath ++ ["highlight" "enable"])
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRemovedOptionModule
|
||||||
|
(basePluginPath ++ ["jumpToRequest"])
|
||||||
|
''
|
||||||
|
This option has been deprecated upstream.
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRemovedOptionModule
|
||||||
|
(basePluginPath ++ ["yankDryRun"])
|
||||||
|
''
|
||||||
|
This option has been deprecated upstream.
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(
|
||||||
|
mkRemovedOptionModule
|
||||||
|
(basePluginPath ++ ["searchBack"])
|
||||||
|
''
|
||||||
|
This option has been deprecated upstream.
|
||||||
|
''
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
settingsOptions = {
|
||||||
|
client = helpers.defaultNullOpts.mkStr "curl" ''
|
||||||
|
The HTTP client to be used when running requests.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
resultSplitInPlace = helpers.defaultNullOpts.mkBool false ''
|
env_file = helpers.defaultNullOpts.mkStr ".env" ''
|
||||||
Keep the http file buffer above|left when split horizontal|vertical.
|
Environment variables file to be used for the request variables in the document.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
stayInCurrentWindowAfterSplit = helpers.defaultNullOpts.mkBool false ''
|
env_pattern = helpers.defaultNullOpts.mkStr "\\.env$" ''
|
||||||
Stay in current windows (`.http` file) or change to results window (default).
|
Environment variables file pattern for `telescope.nvim`.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
skipSslVerification = helpers.defaultNullOpts.mkBool false ''
|
env_edit_command = helpers.defaultNullOpts.mkStr "tabedit" ''
|
||||||
Skip SSL verification, useful for unknown certificates.
|
Neovim command to edit an environment file.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
encodeUrl = helpers.defaultNullOpts.mkBool true ''
|
encode_url = helpers.defaultNullOpts.mkBool true ''
|
||||||
Encode URL before making request.
|
Encode URL before making request.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
highlight = {
|
skip_ssl_verification = helpers.defaultNullOpts.mkBool false ''
|
||||||
enabled = helpers.defaultNullOpts.mkBool true ''
|
Skip SSL verification, useful for unknown certificates.
|
||||||
Enable the highlighting of the selected request when send.
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
timeout = helpers.defaultNullOpts.mkUnsignedInt 150 ''
|
custom_dynamic_variables = mkOption {
|
||||||
Timeout for highlighting.
|
type = with helpers.nixvimTypes;
|
||||||
|
nullOr (
|
||||||
|
maybeRaw (
|
||||||
|
attrsOf strLuaFn
|
||||||
|
)
|
||||||
|
);
|
||||||
|
default = null;
|
||||||
|
example = {
|
||||||
|
"$timestamp" = "os.time";
|
||||||
|
"$randomInt" = ''
|
||||||
|
function()
|
||||||
|
return math.random(0, 1000)
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
description = ''
|
||||||
|
Custom dynamic variables. Keys are variable names and values are lua functions.
|
||||||
|
|
||||||
|
default: `{}`
|
||||||
|
'';
|
||||||
|
apply = v:
|
||||||
|
if isAttrs v
|
||||||
|
then mapAttrs (_: helpers.mkRaw) v
|
||||||
|
else v;
|
||||||
|
};
|
||||||
|
|
||||||
|
logs = {
|
||||||
|
level = helpers.defaultNullOpts.mkNullable helpers.nixvimTypes.logLevel "info" ''
|
||||||
|
The logging level name, see `:h vim.log.levels`.
|
||||||
|
'';
|
||||||
|
|
||||||
|
save = helpers.defaultNullOpts.mkBool true ''
|
||||||
|
Whether to save log messages into a `.log` file.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
showUrl = helpers.defaultNullOpts.mkBool true ''
|
split = {
|
||||||
Toggle showing URL, HTTP info, headers at top the of result window.
|
horizontal = helpers.defaultNullOpts.mkBool false ''
|
||||||
|
Open request results in a horizontal split.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
showCurlCommand = helpers.defaultNullOpts.mkBool true ''
|
in_place = helpers.defaultNullOpts.mkBool false ''
|
||||||
Show the generated curl command in case you want to launch the same request via the
|
Keep the HTTP file buffer above|left when split horizontal|vertical.
|
||||||
terminal (can be verbose).
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
showHttpInfo = helpers.defaultNullOpts.mkBool true ''
|
stay_in_current_window_after_split = helpers.defaultNullOpts.mkBool true ''
|
||||||
Show HTTP information.
|
Stay in the current window (HTTP file) or change the focus to the results window.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
behavior = {
|
||||||
|
show_info = {
|
||||||
|
url = helpers.defaultNullOpts.mkBool true ''
|
||||||
|
Display the request URL.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
showHeaders = helpers.defaultNullOpts.mkBool true ''
|
headers = helpers.defaultNullOpts.mkBool true ''
|
||||||
Show headers information.
|
Display the request headers.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
showStatistics =
|
http_info = helpers.defaultNullOpts.mkBool true ''
|
||||||
helpers.defaultNullOpts.mkNullable
|
Display the request HTTP information.
|
||||||
(
|
'';
|
||||||
with types;
|
|
||||||
either
|
curl_command = helpers.defaultNullOpts.mkBool true ''
|
||||||
(enum [false])
|
Display the cURL command that was used for the request.
|
||||||
(
|
'';
|
||||||
listOf
|
};
|
||||||
(
|
|
||||||
either
|
decode_url = helpers.defaultNullOpts.mkBool true ''
|
||||||
str
|
Whether to decode the request URL query parameters to improve readability.
|
||||||
(listOf str)
|
'';
|
||||||
)
|
|
||||||
)
|
statistics = {
|
||||||
)
|
enable = helpers.defaultNullOpts.mkBool true ''
|
||||||
"false"
|
Whether to enable statistics or not.
|
||||||
|
'';
|
||||||
|
|
||||||
|
stats =
|
||||||
|
helpers.defaultNullOpts.mkListOf (with types; attrsOf str)
|
||||||
''
|
''
|
||||||
Table of curl `--write-out` variables or false if disabled.
|
[
|
||||||
For more granular control see [Statistics Spec](https://github.com/rest-nvim/rest.nvim?tab=readme-ov-file#statistics-spec).
|
{
|
||||||
|
__unkeyed = "total_time";
|
||||||
|
title = "Time taken:";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed = "size_download_t";
|
||||||
|
title = "Download size:";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
''
|
||||||
|
"See https://curl.se/libcurl/c/curl_easy_getinfo.html.";
|
||||||
|
};
|
||||||
|
|
||||||
|
formatters = {
|
||||||
|
json = helpers.defaultNullOpts.mkStr "jq" ''
|
||||||
|
JSON formatter.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
formatters =
|
html =
|
||||||
helpers.defaultNullOpts.mkAttrsOf
|
helpers.defaultNullOpts.mkStr
|
||||||
(
|
|
||||||
with types;
|
|
||||||
either str (enum [false])
|
|
||||||
)
|
|
||||||
''
|
''
|
||||||
{
|
{
|
||||||
json = "jq";
|
__raw = \'\'
|
||||||
html.__raw = \'\'
|
|
||||||
function(body)
|
function(body)
|
||||||
if vim.fn.executable("tidy") == 0 then
|
if vim.fn.executable("tidy") == 0 then
|
||||||
return body
|
return body, { found = false, name = "tidy" }
|
||||||
end
|
end
|
||||||
-- stylua: ignore
|
local fmt_body = vim.fn.system({
|
||||||
return vim.fn.system({
|
"tidy",
|
||||||
"tidy", "-i", "-q",
|
"-i",
|
||||||
|
"-q",
|
||||||
"--tidy-mark", "no",
|
"--tidy-mark", "no",
|
||||||
"--show-body-only", "auto",
|
"--show-body-only", "auto",
|
||||||
"--show-errors", "0",
|
"--show-errors", "0",
|
||||||
"--show-warnings", "0",
|
"--show-warnings", "0",
|
||||||
"-",
|
"-",
|
||||||
}, body):gsub("\n$", "")
|
}, body):gsub("\n$", "")
|
||||||
|
|
||||||
|
return fmt_body, { found = true, name = "tidy" }
|
||||||
end
|
end
|
||||||
\'\';
|
\'\';
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
|
"HTML formatter.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
highlight = {
|
||||||
|
enable = helpers.defaultNullOpts.mkBool true ''
|
||||||
|
Whether current request highlighting is enabled or not.
|
||||||
|
'';
|
||||||
|
|
||||||
|
timeout = helpers.defaultNullOpts.mkUnsignedInt 750 ''
|
||||||
|
Duration time of the request highlighting in milliseconds.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
keybinds =
|
||||||
|
helpers.defaultNullOpts.mkListOf (with types; listOf str)
|
||||||
''
|
''
|
||||||
Executables or functions for formatting response body [optional].
|
[
|
||||||
Set them to false if you want to disable them.
|
[
|
||||||
|
"<localleader>rr"
|
||||||
|
"<cmd>Rest run<cr>"
|
||||||
|
"Run request under the cursor"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"<localleader>rl"
|
||||||
|
"<cmd>Rest run last<cr>"
|
||||||
|
"Re-run latest request"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
''
|
||||||
|
''
|
||||||
|
Declare some keybindings.
|
||||||
|
Format: list of 3 strings lists: key, action and description.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
jumpToRequest = helpers.defaultNullOpts.mkBool false ''
|
settingsExample = {
|
||||||
Moves the cursor to the selected request line when send.
|
client = "curl";
|
||||||
'';
|
env_file = ".env";
|
||||||
|
logs = {
|
||||||
envFile = helpers.defaultNullOpts.mkStr ".env" ''
|
level = "info";
|
||||||
Specifies file name that consist environment variables.
|
save = true;
|
||||||
'';
|
|
||||||
|
|
||||||
customDynamicVariables = mkOption {
|
|
||||||
type = with helpers.nixvimTypes; nullOr (attrsOf strLuaFn);
|
|
||||||
default = null;
|
|
||||||
description = ''
|
|
||||||
Allows to extend or overwrite built-in dynamic variable functions.
|
|
||||||
'';
|
|
||||||
apply = v: helpers.ifNonNull' v (mapAttrs (_: helpers.mkRaw) v);
|
|
||||||
};
|
};
|
||||||
|
result = {
|
||||||
yankDryRun = helpers.defaultNullOpts.mkBool true "";
|
split = {
|
||||||
|
horizontal = false;
|
||||||
searchBack = helpers.defaultNullOpts.mkBool true "";
|
in_place = false;
|
||||||
|
stay_in_current_window_after_split = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
extraPlugins = [cfg.package];
|
|
||||||
|
|
||||||
extraPackages = [pkgs.curl];
|
|
||||||
|
|
||||||
extraConfigLua = let
|
|
||||||
setupOptions = with cfg;
|
|
||||||
{
|
|
||||||
result_split_horizontal = resultSplitHorizontal;
|
|
||||||
result_split_in_place = resultSplitInPlace;
|
|
||||||
stay_in_current_window_after_split = stayInCurrentWindowAfterSplit;
|
|
||||||
skip_ssl_verification = skipSslVerification;
|
|
||||||
encode_url = encodeUrl;
|
|
||||||
highlight = with highlight; {
|
|
||||||
inherit
|
|
||||||
(highlight)
|
|
||||||
enabled
|
|
||||||
timeout
|
|
||||||
;
|
|
||||||
};
|
};
|
||||||
result = with result; {
|
keybinds = [
|
||||||
show_url = showUrl;
|
[
|
||||||
show_curl_command = showCurlCommand;
|
"<localleader>rr"
|
||||||
show_http_info = showHttpInfo;
|
"<cmd>Rest run<cr>"
|
||||||
show_headers = showHeaders;
|
"Run request under the cursor"
|
||||||
show_statistics = showStatistics;
|
]
|
||||||
inherit formatters;
|
[
|
||||||
|
"<localleader>rl"
|
||||||
|
"<cmd>Rest run last<cr>"
|
||||||
|
"Re-run latest request"
|
||||||
|
]
|
||||||
|
];
|
||||||
};
|
};
|
||||||
jump_to_request = jumpToRequest;
|
|
||||||
env_file = envFile;
|
|
||||||
custom_dynamic_variables = customDynamicVariables;
|
|
||||||
yank_dry_run = yankDryRun;
|
|
||||||
search_back = searchBack;
|
|
||||||
}
|
}
|
||||||
// cfg.extraOptions;
|
|
||||||
in ''
|
|
||||||
require('rest-nvim').setup(${helpers.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,46 +7,86 @@
|
||||||
plugins.rest = {
|
plugins.rest = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
resultSplitHorizontal = false;
|
settings = {
|
||||||
resultSplitInPlace = false;
|
client = "curl";
|
||||||
stayInCurrentWindowAfterSplit = false;
|
env_file = ".env";
|
||||||
skipSslVerification = false;
|
env_pattern = "\\.env$";
|
||||||
encodeUrl = true;
|
env_edit_command = "tabedit";
|
||||||
highlight = {
|
encode_url = true;
|
||||||
enabled = true;
|
skip_ssl_verification = false;
|
||||||
timeout = 150;
|
custom_dynamic_variables = {};
|
||||||
|
logs = {
|
||||||
|
level = "info";
|
||||||
|
save = true;
|
||||||
};
|
};
|
||||||
result = {
|
result = {
|
||||||
showUrl = true;
|
split = {
|
||||||
showCurlCommand = true;
|
horizontal = false;
|
||||||
showHttpInfo = true;
|
in_place = false;
|
||||||
showHeaders = true;
|
stay_in_current_window_after_split = true;
|
||||||
showStatistics = false;
|
};
|
||||||
|
behavior = {
|
||||||
|
show_info = {
|
||||||
|
url = true;
|
||||||
|
headers = true;
|
||||||
|
http_info = true;
|
||||||
|
curl_command = true;
|
||||||
|
};
|
||||||
|
decode_url = true;
|
||||||
|
statistics = {
|
||||||
|
enable = true;
|
||||||
|
stats = [
|
||||||
|
{
|
||||||
|
__unkeyed = "total_time";
|
||||||
|
title = "Time taken:";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
__unkeyed = "size_download_t";
|
||||||
|
title = "Download size:";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
formatters = {
|
formatters = {
|
||||||
json = "jq";
|
json = "jq";
|
||||||
html.__raw = ''
|
html.__raw = ''
|
||||||
function(body)
|
function(body)
|
||||||
if vim.fn.executable("tidy") == 0 then
|
if vim.fn.executable("tidy") == 0 then
|
||||||
return body
|
return body, { found = false, name = "tidy" }
|
||||||
end
|
end
|
||||||
-- stylua: ignore
|
local fmt_body = vim.fn.system({
|
||||||
return vim.fn.system({
|
"tidy",
|
||||||
"tidy", "-i", "-q",
|
"-i",
|
||||||
|
"-q",
|
||||||
"--tidy-mark", "no",
|
"--tidy-mark", "no",
|
||||||
"--show-body-only", "auto",
|
"--show-body-only", "auto",
|
||||||
"--show-errors", "0",
|
"--show-errors", "0",
|
||||||
"--show-warnings", "0",
|
"--show-warnings", "0",
|
||||||
"-",
|
"-",
|
||||||
}, body):gsub("\n$", "")
|
}, body):gsub("\n$", "")
|
||||||
|
|
||||||
|
return fmt_body, { found = true, name = "tidy" }
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
jumpToRequest = false;
|
};
|
||||||
envFile = ".env";
|
highlight = {
|
||||||
customDynamicVariables = null;
|
enable = true;
|
||||||
yankDryRun = true;
|
timeout = 750;
|
||||||
searchBack = true;
|
};
|
||||||
|
keybinds = [
|
||||||
|
[
|
||||||
|
"<localleader>rr"
|
||||||
|
"<cmd>Rest run<cr>"
|
||||||
|
"Run request under the cursor"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"<localleader>rl"
|
||||||
|
"<cmd>Rest run last<cr>"
|
||||||
|
"Re-run latest request"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue