Skip to content

Commit 5714b71

Browse files
authored
Merge pull request #200 from teto/dontdisplay_binary_output
dont display binary outputs in answer
2 parents c21eed6 + 5ebe35f commit 5714b71

File tree

5 files changed

+46
-51
lines changed

5 files changed

+46
-51
lines changed

.github/workflows/default.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
with:
1212
nix_path: nixpkgs=channel:nixos-unstable
1313
- run: |
14-
nix develop . -c make test
14+
nix develop .#ci -c make test

flake.nix

+27-45
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,18 @@
1313

1414
mkDevShell = luaVersion:
1515
let
16-
# luaPkgs = pkgs."lua${luaVersion}".pkgs;
1716
luaEnv = pkgs."lua${luaVersion}".withPackages (lp: with lp; [
1817
busted
1918
luacheck
2019
luarocks
2120
]);
22-
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
23-
plugins = with pkgs.vimPlugins; [
24-
{
25-
plugin = packer-nvim;
26-
type = "lua";
27-
config = ''
28-
require('packer').init({
29-
luarocks = {
30-
python_cmd = 'python' -- Set the python command to use for running hererocks
31-
},
32-
})
33-
-- require my own manual config
34-
require('init-manual')
35-
'';
36-
}
37-
{ plugin = (nvim-treesitter.withPlugins (
38-
plugins: with plugins; [
39-
tree-sitter-lua
40-
tree-sitter-http
41-
tree-sitter-json
42-
]
43-
));
44-
}
45-
{ plugin = plenary-nvim; }
46-
];
47-
customRC = "";
48-
wrapRc = false;
49-
};
50-
myNeovim = pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped neovimConfig;
5121
in
5222
pkgs.mkShell {
5323
name = "rest-nvim";
5424
buildInputs = [
5525
pkgs.sumneko-lua-language-server
5626
luaEnv
5727
pkgs.stylua
58-
myNeovim
59-
# pkgs.neovim # assume user has one already installed
6028
];
6129

6230
shellHook = let
@@ -68,31 +36,45 @@
6836
tree-sitter-json
6937
]
7038
))];
71-
# opt = map (x: x.plugin) pluginsPartitioned.right;
7239
};
73-
# };
7440
packDirArgs.myNeovimPackages = myVimPackage;
7541
in
7642
''
77-
export DEBUG_PLENARY="debug"
78-
cat <<-EOF > minimal.vim
79-
set rtp+=.
80-
set packpath^=${pkgs.vimUtils.packDir packDirArgs}
81-
EOF
43+
export DEBUG_PLENARY="debug"
44+
cat <<-EOF > minimal.vim
45+
set rtp+=.
46+
set packpath^=${pkgs.vimUtils.packDir packDirArgs}
47+
EOF
8248
'';
8349
};
8450

8551
in
8652
{
8753

88-
# packages = {
89-
# default = self.packages.${system}.luarocks-51;
90-
# luarocks-51 = mkPackage "5_1";
91-
# luarocks-52 = mkPackage "5_2";
92-
# };
93-
9454
devShells = {
9555
default = self.devShells.${system}.luajit;
56+
ci = let
57+
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
58+
plugins = with pkgs.vimPlugins; [
59+
{ plugin = (nvim-treesitter.withPlugins (
60+
plugins: with plugins; [
61+
tree-sitter-lua
62+
tree-sitter-http
63+
tree-sitter-json
64+
]
65+
));
66+
}
67+
{ plugin = plenary-nvim; }
68+
];
69+
customRC = "";
70+
wrapRc = false;
71+
};
72+
myNeovim = pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped neovimConfig;
73+
in
74+
(mkDevShell "jit").overrideAttrs(oa: {
75+
buildInputs = oa.buildInputs ++ [ myNeovim ];
76+
});
77+
9678
luajit = mkDevShell "jit";
9779
lua-51 = mkDevShell "5_1";
9880
lua-52 = mkDevShell "5_2";

lua/rest-nvim/curl/init.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ local function create_callback(method, url, script_str)
6363
-- get content type
6464
for _, header in ipairs(res.headers) do
6565
if string.lower(header):find("^content%-type") then
66-
content_type = header:match("application/(%l+)") or header:match("text/(%l+)")
66+
content_type = header:match("application/([-a-z]+)") or header:match("text/(%l+)")
6767
break
6868
end
6969
end
@@ -150,9 +150,15 @@ local function create_callback(method, url, script_str)
150150
end
151151

152152
-- append response container
153-
res.body = "#+RESPONSE\n" .. res.body .. "\n#+END"
153+
local buf_content = "#+RESPONSE\n"
154+
if utils.is_binary_content_type(content_type) then
155+
buf_content = buf_content .. "Binary answer"
156+
else
157+
buf_content = buf_content .. res.body
158+
end
159+
buf_content = buf_content .. "\n#+END"
154160

155-
local lines = utils.split(res.body, "\n")
161+
local lines = utils.split(buf_content, "\n")
156162
local line_count = vim.api.nvim_buf_line_count(res_bufnr) - 1
157163
vim.api.nvim_buf_set_lines(res_bufnr, line_count, line_count + #lines, false, lines)
158164

lua/rest-nvim/request/init.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local function get_importfile_name(bufnr, start_line, stop_line)
2121
local fileimport_spliced
2222
fileimport_line = vim.api.nvim_buf_get_lines(bufnr, import_line - 1, import_line, false)
2323
fileimport_string =
24-
string.gsub(fileimport_line[1], "<", "", 1):gsub("^%s+", ""):gsub("%s+$", "")
24+
string.gsub(fileimport_line[1], "<", "", 1):gsub("^%s+", ""):gsub("%s+$", "")
2525
fileimport_spliced = utils.replace_vars(fileimport_string)
2626
if path:new(fileimport_spliced):is_absolute() then
2727
return fileimport_spliced
@@ -89,7 +89,6 @@ local function get_body(bufnr, start_line, stop_line, has_json)
8989
end
9090
end
9191

92-
9392
return body
9493
end
9594

lua/rest-nvim/utils/init.lua

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ math.randomseed(os.time())
55

66
local M = {}
77

8+
M.binary_content_types = {
9+
"octet-stream",
10+
}
11+
12+
M.is_binary_content_type = function(content_type)
13+
return vim.tbl_contains(M.binary_content_types, content_type)
14+
end
15+
816
-- move_cursor moves the cursor to the desired position in the provided buffer
917
-- @param bufnr Buffer number, a.k.a id
1018
-- @param line the desired line

0 commit comments

Comments
 (0)