diff --git a/nvim-core/src/lib.rs b/nvim-core/src/lib.rs index 137333e..5ae5078 100644 --- a/nvim-core/src/lib.rs +++ b/nvim-core/src/lib.rs @@ -1326,7 +1326,14 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) { ) } "edit" => { - let args_rmp = json_to_rmpv(args); + let mut modified_args = args.clone(); + if let Some(content) = modified_args.get_mut("replacement_content") { + if let Some(s) = content.as_str() { + let lines: Vec = s.split('\n').map(|l| l.trim_end_matches('\r').to_string()).collect(); + *content = serde_json::json!(lines); + } + } + let args_rmp = json_to_rmpv(&modified_args); let code = " local args = ... local file = args.file @@ -1341,8 +1348,8 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) { if not end_line then error(\"Missing 'end_line'\") end - local content = args.replacement_content - if not content or content == vim.NIL then + local content_lines = args.replacement_content + if not content_lines or content_lines == vim.NIL then error(\"Missing 'replacement_content'\") end @@ -1351,8 +1358,7 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) { vim.fn.bufload(bufnr) end - local lines = vim.split(content, '\\n', { plain = true }) - vim.api.nvim_buf_set_lines(bufnr, start_line - 1, end_line, false, lines) + vim.api.nvim_buf_set_lines(bufnr, start_line - 1, end_line, false, content_lines) local win = vim.fn.bufwinid(bufnr) if win ~= -1 then @@ -1398,7 +1404,14 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) { ) } "create_scratch" | "open_buffer" => { - let args_rmp = json_to_rmpv(args); + let mut modified_args = args.clone(); + if let Some(content) = modified_args.get_mut("content") { + if let Some(s) = content.as_str() { + let lines: Vec = s.split('\n').map(|l| l.trim_end_matches('\r').to_string()).collect(); + *content = serde_json::json!(lines); + } + } + let args_rmp = json_to_rmpv(&modified_args); let code = " local args = ... local name = (args.name and args.name ~= '') and args.name or '[Antigravity Scratch]' @@ -1408,8 +1421,7 @@ pub async fn run_mcp_loop(app_name: &str, app_version: &str) { vim.bo[buf].buftype = 'nofile' vim.bo[buf].bufhidden = 'hide' if args.content then - local lines = vim.split(args.content, '\\n') - vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + vim.api.nvim_buf_set_lines(buf, 0, -1, false, args.content) end if args.filetype and args.filetype ~= '' then vim.bo[buf].filetype = args.filetype