@@ -60,38 +60,36 @@ local function run_request(req)
60
60
61
61
-- NOTE: wrap with schedule to do vim stuffs outside of lua callback loop (`on_exit`
62
62
-- callback from `vim.system()` call)
63
- nio .run (function ()
64
- ui .update ({ request = req })
65
- local ok , res = pcall (client .request (req ).wait )
66
- if not ok then
67
- logger .error (" request failed" )
68
- vim .notify (" request failed. See `:Rest logs` for more info" , vim .log .levels .ERROR , { title = " rest.nvim" })
69
- return
70
- end
71
- --- @cast res rest.Response
72
- logger .info (" request success" )
73
-
74
- -- run request handler scripts
75
- logger .debug ((" run %d handers" ):format (# req .handlers ))
76
- vim .iter (req .handlers ):each (function (f )
77
- f (res )
78
- end )
79
- logger .info (" handler done" )
80
-
81
- _G .rest_request = req
82
- _G .rest_response = res
83
- vim .api .nvim_exec_autocmds (" User" , {
84
- pattern = { " RestResponse" , " RestResponsePre" },
85
- })
86
- _G .rest_request = nil
87
- _G .rest_response = nil
88
-
89
- -- update cookie jar
90
- jar .update_jar (req .url , res )
91
-
92
- -- update result UI
93
- ui .update ({ response = res })
63
+ ui .update ({ request = req })
64
+ local ok , res = pcall (client .request (req ).wait )
65
+ if not ok then
66
+ logger .error (" request failed" )
67
+ vim .notify (" request failed. See `:Rest logs` for more info" , vim .log .levels .ERROR , { title = " rest.nvim" })
68
+ return
69
+ end
70
+ --- @cast res rest.Response
71
+ logger .info (" request success" )
72
+
73
+ -- run request handler scripts
74
+ logger .debug ((" run %d handers" ):format (# req .handlers ))
75
+ vim .iter (req .handlers ):each (function (f )
76
+ f (res )
94
77
end )
78
+ logger .info (" handler done" )
79
+
80
+ _G .rest_request = req
81
+ _G .rest_response = res
82
+ vim .api .nvim_exec_autocmds (" User" , {
83
+ pattern = { " RestResponse" , " RestResponsePre" },
84
+ })
85
+ _G .rest_request = nil
86
+ _G .rest_response = nil
87
+
88
+ -- update cookie jar
89
+ jar .update_jar (req .url , res )
90
+
91
+ -- update result UI
92
+ ui .update ({ response = res })
95
93
-- FIXME(boltless): return future to pass the command state
96
94
end
97
95
@@ -107,17 +105,20 @@ function M.run(name)
107
105
if config .env .enable and vim .b ._rest_nvim_env_file then
108
106
ctx :load_file (vim .b ._rest_nvim_env_file )
109
107
end
110
- local req = parser .parse (req_node , 0 , ctx )
111
- if not req then
112
- logger .error (" failed to parse request" )
113
- vim .notify (" failed to parse request" , vim .log .levels .ERROR , { title = " rest.nvim" })
114
- return
115
- end
116
- local highlight = config .highlight
117
- if highlight .enable then
118
- utils .ts_highlight_node (0 , req_node , require (" rest-nvim.api" ).namespace , highlight .timeout )
119
- end
120
- run_request (req )
108
+ local bufnr = vim .api .nvim_get_current_buf ()
109
+ nio .run (function ()
110
+ local req = parser .parse (req_node , bufnr , ctx )
111
+ if not req then
112
+ logger .error (" failed to parse request" )
113
+ vim .notify (" failed to parse request" , vim .log .levels .ERROR , { title = " rest.nvim" })
114
+ return
115
+ end
116
+ local highlight = config .highlight
117
+ if highlight .enable then
118
+ utils .ts_highlight_node (0 , req_node , require (" rest-nvim.api" ).namespace , highlight .timeout )
119
+ end
120
+ run_request (req )
121
+ end )
121
122
end
122
123
123
124
--- run last request
@@ -134,31 +135,4 @@ function M.last_request()
134
135
return rest_nvim_last_request
135
136
end
136
137
137
- -- ---run all requests in current file with same context
138
- -- function M.run_all()
139
- -- local reqs = parser.get_all_request_nodes(0)
140
- -- local ctx = Context:new()
141
- -- for _, req_node in ipairs(reqs) do
142
- -- local req = parser.parse(req_node, 0, ctx)
143
- -- if not req then
144
- -- vim.notify(
145
- -- "Parsing request failed. See `:Rest logs` for more info",
146
- -- vim.log.levels.ERROR,
147
- -- { title = "rest.nvim" }
148
- -- )
149
- -- return false
150
- -- end
151
- -- -- FIXME: wait for previous request ends
152
- -- local ok = run_request(req)
153
- -- if not ok then
154
- -- vim.notify(
155
- -- "Running request failed. See `:Rest logs` for more info",
156
- -- vim.log.levels.ERROR,
157
- -- { title = "rest.nvim" }
158
- -- )
159
- -- return
160
- -- end
161
- -- end
162
- -- end
163
-
164
138
return M
0 commit comments