nix-community.nixvim/plugins/utils/rest.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

437 lines
10 KiB
Nix
Raw Normal View History

2024-01-21 15:34:18 +01:00
{
config,
2024-01-21 15:34:18 +01:00
lib,
pkgs,
...
}:
2024-09-09 17:18:43 -05:00
let
inherit (lib) mkRemovedOptionModule mkRenamedOptionModule types;
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin {
2024-04-07 14:07:31 +02:00
name = "rest";
originalName = "rest.nvim";
luaName = "rest-nvim";
package = "rest-nvim";
2024-05-05 19:39:35 +02:00
2024-04-07 14:07:31 +02:00
extraPackages = [ pkgs.curl ];
2024-05-05 19:39:35 +02:00
2024-09-09 17:18:43 -05:00
maintainers = [ lib.maintainers.GaetanLepage ];
2024-05-05 19:39:35 +02:00
2024-04-07 14:07:31 +02:00
# TODO introduced 2024-04-07: remove 2024-06-07
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"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
))
(mkRenamedOptionModule (basePluginPath ++ [ "resultSplitInPlace" ]) (
settingsPath
++ [
"result"
"split"
"in_place"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
))
(mkRenamedOptionModule (basePluginPath ++ [ "stayInCurrentWindowAfterSplit" ]) (
settingsPath
++ [
"result"
"split"
"stay_in_current_window_after_split"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
))
(mkRenamedOptionModule
(
basePluginPath
++ [
"result"
"showUrl"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
(
settingsPath
++ [
"result"
"behavior"
"show_info"
"url"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
)
(mkRenamedOptionModule
(
basePluginPath
++ [
"result"
"showHeaders"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
(
settingsPath
++ [
"result"
"behavior"
"show_info"
"headers"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
)
(mkRenamedOptionModule
(
basePluginPath
++ [
"result"
"showHttpInfo"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
(
settingsPath
++ [
"result"
"behavior"
"show_info"
"http_info"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
)
(mkRenamedOptionModule
(
basePluginPath
++ [
"result"
"showCurlCommand"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
(
settingsPath
++ [
"result"
"behavior"
"show_info"
"curl_command"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
)
(mkRemovedOptionModule
(
basePluginPath
++ [
"result"
"showStatistics"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
''
Use `plugins.rest.settings.result.behavior.statistics.{enable,stats}` instead.
Refer to the documentation for more information.
''
)
(mkRenamedOptionModule
(
basePluginPath
++ [
"result"
"formatters"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
(
settingsPath
++ [
"result"
"behavior"
"formatters"
2024-05-05 19:39:35 +02:00
]
2024-04-07 14:07:31 +02:00
)
)
(mkRenamedOptionModule
(
basePluginPath
++ [
"highlight"
"enabled"
2024-05-05 19:39:35 +02:00
]
)
(
2024-04-07 14:07:31 +02:00
settingsPath
2024-05-05 19:39:35 +02:00
++ [
2024-04-07 14:07:31 +02:00
"highlight"
2024-05-05 19:39:35 +02:00
"enable"
]
)
2024-04-07 14:07:31 +02:00
)
(mkRemovedOptionModule (basePluginPath ++ [ "jumpToRequest" ]) ''
This option has been deprecated upstream.
2024-05-05 19:39:35 +02:00
'')
2024-04-07 14:07:31 +02:00
(mkRemovedOptionModule (basePluginPath ++ [ "yankDryRun" ]) ''
This option has been deprecated upstream.
2024-05-05 19:39:35 +02:00
'')
2024-04-07 14:07:31 +02:00
(mkRemovedOptionModule (basePluginPath ++ [ "searchBack" ]) ''
This option has been deprecated upstream.
2024-05-05 19:39:35 +02:00
'')
2024-04-07 14:07:31 +02:00
];
2024-01-21 15:34:18 +01:00
2024-04-07 14:07:31 +02:00
settingsOptions = {
2024-09-09 17:18:43 -05:00
client = defaultNullOpts.mkStr "curl" ''
2024-04-07 14:07:31 +02:00
The HTTP client to be used when running requests.
2024-01-21 15:34:18 +01:00
'';
2024-05-05 19:39:35 +02:00
2024-09-09 17:18:43 -05:00
env_file = defaultNullOpts.mkStr ".env" ''
2024-04-07 14:07:31 +02:00
Environment variables file to be used for the request variables in the document.
2024-01-21 15:34:18 +01:00
'';
2024-05-05 19:39:35 +02:00
2024-09-09 17:18:43 -05:00
env_pattern = defaultNullOpts.mkStr "\\.env$" ''
2024-04-07 14:07:31 +02:00
Environment variables file pattern for `telescope.nvim`.
2024-05-05 19:39:35 +02:00
'';
2024-09-09 17:18:43 -05:00
env_edit_command = defaultNullOpts.mkStr "tabedit" ''
2024-04-07 14:07:31 +02:00
Neovim command to edit an environment file.
2024-05-05 19:39:35 +02:00
'';
2024-09-09 17:18:43 -05:00
encode_url = defaultNullOpts.mkBool true ''
2024-01-21 15:34:18 +01:00
Encode URL before making request.
2024-05-05 19:39:35 +02:00
'';
2024-09-09 17:18:43 -05:00
skip_ssl_verification = defaultNullOpts.mkBool false ''
2024-04-07 14:07:31 +02:00
Skip SSL verification, useful for unknown certificates.
2024-05-05 19:39:35 +02:00
'';
2024-09-09 17:18:43 -05:00
custom_dynamic_variables = lib.mkOption {
type = with types; nullOr (maybeRaw (attrsOf strLuaFn));
2024-04-07 14:07:31 +02:00
default = null;
example = {
"$timestamp" = "os.time";
"$randomInt" = ''
function()
return math.random(0, 1000)
2024-05-05 19:39:35 +02:00
end
2024-01-21 15:34:18 +01:00
'';
2024-05-05 19:39:35 +02:00
};
2024-04-07 14:07:31 +02:00
description = ''
Custom dynamic variables. Keys are variable names and values are lua functions.
2024-01-21 15:34:18 +01:00
2024-04-07 14:07:31 +02:00
default: `{}`
2024-01-21 15:34:18 +01:00
'';
2024-09-09 17:18:43 -05:00
apply = v: if lib.isAttrs v then lib.mapAttrs (_: lib.nixvim.mkRaw) v else v;
2024-05-05 19:39:35 +02:00
};
2024-01-21 15:34:18 +01:00
2024-05-05 19:39:35 +02:00
logs = {
2024-09-09 17:18:43 -05:00
level = defaultNullOpts.mkNullable types.logLevel "info" ''
2024-01-21 15:34:18 +01:00
The logging level name, see `:h vim.log.levels`.
'';
2024-09-09 17:18:43 -05:00
save = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Whether to save log messages into a `.log` file.
'';
2024-05-05 19:39:35 +02:00
};
2024-01-21 15:34:18 +01:00
2024-04-07 14:07:31 +02:00
result = {
split = {
2024-09-09 17:18:43 -05:00
horizontal = defaultNullOpts.mkBool false ''
2024-04-07 14:07:31 +02:00
Open request results in a horizontal split.
2024-01-21 15:34:18 +01:00
'';
2024-09-09 17:18:43 -05:00
in_place = defaultNullOpts.mkBool false ''
2024-04-07 14:07:31 +02:00
Keep the HTTP file buffer above|left when split horizontal|vertical.
2024-01-21 15:34:18 +01:00
'';
2024-09-09 17:18:43 -05:00
stay_in_current_window_after_split = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Stay in the current window (HTTP file) or change the focus to the results window.
2024-01-21 15:34:18 +01:00
'';
2024-04-07 14:07:31 +02:00
};
2024-01-21 15:34:18 +01:00
2024-04-07 14:07:31 +02:00
behavior = {
show_info = {
2024-09-09 17:18:43 -05:00
url = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Display the request URL.
2024-01-21 15:34:18 +01:00
'';
2024-09-09 17:18:43 -05:00
headers = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Display the request headers.
2024-01-21 15:34:18 +01:00
'';
2024-09-09 17:18:43 -05:00
http_info = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Display the request HTTP information.
'';
2024-01-21 15:34:18 +01:00
2024-09-09 17:18:43 -05:00
curl_command = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Display the cURL command that was used for the request.
'';
2024-05-05 19:39:35 +02:00
};
2024-01-21 15:34:18 +01:00
2024-09-09 17:18:43 -05:00
decode_url = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Whether to decode the request URL query parameters to improve readability.
'';
2024-01-21 15:34:18 +01:00
2024-04-07 14:07:31 +02:00
statistics = {
2024-09-09 17:18:43 -05:00
enable = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Whether to enable statistics or not.
'';
2024-01-21 15:34:18 +01:00
2024-09-09 17:18:43 -05:00
stats = defaultNullOpts.mkListOf (with types; attrsOf str) [
{
__unkeyed = "total_time";
title = "Time taken:";
}
{
__unkeyed = "size_download_t";
title = "Download size:";
}
] "See https://curl.se/libcurl/c/curl_easy_getinfo.html.";
2024-04-07 14:07:31 +02:00
};
2024-04-07 14:07:31 +02:00
formatters = {
2024-09-09 17:18:43 -05:00
json = defaultNullOpts.mkStr "jq" ''
2024-04-07 14:07:31 +02:00
JSON formatter.
'';
2024-09-09 17:18:43 -05:00
html = defaultNullOpts.mkStr {
__raw = ''
function(body)
if vim.fn.executable("tidy") == 0 then
return body, { found = false, name = "tidy" }
2024-05-05 19:39:35 +02:00
end
local fmt_body = vim.fn.system({
"tidy",
"-i",
"-q",
"--tidy-mark", "no",
"--show-body-only", "auto",
"--show-errors", "0",
"--show-warnings", "0",
"-",
}, body):gsub("\n$", "")
return fmt_body, { found = true, name = "tidy" }
end
'';
} "HTML formatter.";
2024-04-07 14:07:31 +02:00
};
2024-04-07 14:07:31 +02:00
};
keybinds = {
2024-09-09 17:18:43 -05:00
buffer_local = defaultNullOpts.mkBool false ''
2024-04-07 14:07:31 +02:00
Enable keybinds only in request result buffer.
'';
2024-09-09 17:18:43 -05:00
prev = defaultNullOpts.mkStr "H" ''
2024-04-07 14:07:31 +02:00
Mapping for cycle to previous result pane.
2024-05-05 19:39:35 +02:00
'';
2024-09-09 17:18:43 -05:00
next = defaultNullOpts.mkStr "L" ''
2024-04-07 14:07:31 +02:00
Mapping for cycle to next result pane.
'';
};
2024-05-05 19:39:35 +02:00
};
2024-04-07 14:07:31 +02:00
highlight = {
2024-09-09 17:18:43 -05:00
enable = defaultNullOpts.mkBool true ''
2024-04-07 14:07:31 +02:00
Whether current request highlighting is enabled or not.
2024-05-05 19:39:35 +02:00
'';
2024-09-09 17:18:43 -05:00
timeout = defaultNullOpts.mkUnsignedInt 750 ''
2024-04-07 14:07:31 +02:00
Duration time of the request highlighting in milliseconds.
2024-05-05 19:39:35 +02:00
'';
};
2024-04-07 14:07:31 +02:00
keybinds =
2024-09-09 17:18:43 -05:00
defaultNullOpts.mkListOf (with types; listOf str)
[
2024-04-07 14:07:31 +02:00
[
"<localleader>rr"
"<cmd>Rest run<cr>"
"Run request under the cursor"
2024-04-07 14:07:31 +02:00
]
[
"<localleader>rl"
"<cmd>Rest run last<cr>"
"Re-run latest request"
]
]
2024-04-07 14:07:31 +02:00
''
Declare some keybindings.
Format: list of 3 strings lists: key, action and description.
'';
2024-05-05 19:39:35 +02:00
};
2024-04-07 14:07:31 +02:00
settingsExample = {
client = "curl";
env_file = ".env";
2024-05-05 19:39:35 +02:00
logs = {
2024-04-07 14:07:31 +02:00
level = "info";
save = true;
};
result = {
split = {
horizontal = false;
in_place = false;
stay_in_current_window_after_split = true;
};
};
keybinds = [
2024-05-05 19:39:35 +02:00
[
2024-04-07 14:07:31 +02:00
"<localleader>rr"
"<cmd>Rest run<cr>"
"Run request under the cursor"
2024-05-05 19:39:35 +02:00
]
[
2024-04-07 14:07:31 +02:00
"<localleader>rl"
"<cmd>Rest run last<cr>"
"Re-run latest request"
2024-05-05 19:39:35 +02:00
]
];
};
extraOptions = {
curlPackage = lib.mkPackageOption pkgs "curl" {
nullable = true;
};
enableHttpFiletypeAssociation = lib.mkOption {
type = types.bool;
default = true;
description = ''
Sets up the filetype association of `.http` files to trigger treesitter support to enable `rest` functionality.
'';
};
};
extraConfig = cfg: {
assertions = [
{
assertion = config.plugins.treesitter.enable;
message = ''
Nixvim (plugins.rest): Requires the `http` parser from `plugins.treesitter`, please set `plugins.treesitter.enable`.
'';
}
];
extraPackages = [ cfg.curlPackage ];
filetype = lib.mkIf cfg.enableHttpFiletypeAssociation {
extension.http = "http";
};
};
2024-04-07 14:07:31 +02:00
}