@@ -95,6 +95,9 @@ local function create_callback(method, url)
9595 res .body = vim .fn .system (formatter , res .body ):gsub (" \n $" , " " )
9696 end
9797
98+ -- append response container
99+ res .body = " #+RESPONSE\n " .. res .body .. " \n #+END"
100+
98101 local lines = utils .split (res .body , " \n " )
99102 local line_count = vim .api .nvim_buf_line_count (res_bufnr ) - 1
100103 vim .api .nvim_buf_set_lines (res_bufnr , line_count , line_count + # lines , false , lines )
@@ -117,22 +120,16 @@ local function create_callback(method, url)
117120 utils .move_cursor (res_bufnr , 1 )
118121
119122 -- add syntax highlights for response
120- if content_type == " json" then
121- vim .cmd ([[
122- unlet b:current_syntax
123- syn include @json syntax/json.vim
124- syn region jsonBody start="\v\{" end="\v\}$" contains=@json
123+ local syntax_file = vim .fn .expand (string.format (" $VIMRUNTIME/syntax/%s.vim" , content_type ))
125124
126- let b:current_syntax = "httpResult"
127- ]] )
128- elseif content_type == " html" then
129- vim .cmd ([[
125+ if vim .fn .filereadable (syntax_file ) == 1 then
126+ vim .cmd (string.gsub ([[
130127 unlet b:current_syntax
131- syn include @html syntax/html .vim
132- syn region htmlBody start=+<html.*>+ end=+<\/ *html>+ contains=@html
128+ syn include @%s syntax/%s .vim
129+ syn region %sBody matchgroup=Comment start=+\v^#\+RESPONSE$+ end=+\v^#\+END$+ contains=@%s
133130
134131 let b:current_syntax = "httpResult"
135- ]] )
132+ ]] , " %%s " , content_type ) )
136133 end
137134 end
138135end
@@ -165,7 +162,7 @@ M.curl_cmd = function(opts)
165162 vim .cmd (" let @+=" .. string.format (" %q" , curl_cmd ))
166163 end
167164
168- log . debug ( " [rest.nvim] Request preview:\n " .. curl_cmd )
165+ vim . api . nvim_echo ({{ " [rest.nvim] Request preview:\n " , " Comment " }, { curl_cmd }}, false , {} )
169166 return
170167 else
171168 opts .callback = vim .schedule_wrap (create_callback (opts .method , opts .url ))
0 commit comments