Skip to content

Commit 5004334

Browse files
fix: merge conflict
2 parents e71815e + 1dce2fd commit 5004334

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.4.0](https://github.com/jonathanmorris180/salesforce.nvim/compare/v1.3.2...v1.4.0) (2024-04-23)
4+
5+
6+
### Features
7+
8+
* allow executing unsaved buffers anonymously ([e472fe8](https://github.com/jonathanmorris180/salesforce.nvim/commit/e472fe8be97b24a25280693c6bc9f1f0a4f6b8ed))
9+
310
## [1.3.2](https://github.com/jonathanmorris180/salesforce.nvim/compare/v1.3.1...v1.3.2) (2024-04-04)
411

512

lua/salesforce/execute_anon.lua

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@ local M = {}
1616

1717
M.execute_anon = function()
1818
Debug:log("execute_anon.lua", "Executing anonymous Apex script...")
19+
local disallowed_extensions = { "cls", "trigger" }
1920
local path = vim.fn.expand("%:p")
20-
local file_type = vim.fn.expand("%:e")
21+
local extension = vim.fn.expand("%:e")
22+
local file_type = vim.bo.filetype
2123
local default_username = OrgManager:get_default_username()
24+
local file_contents = ""
25+
local is_unsaved_buffer = false
2226

23-
if file_type ~= "apex" then
24-
local message = "Not an Apex script file"
27+
if file_type == "apex" and not vim.tbl_contains(disallowed_extensions, extension) then
28+
if vim.fn.empty(path) == 1 then
29+
Debug:log("execute_anon.lua", "File path is empty, retrieving buffer contents...")
30+
is_unsaved_buffer = true
31+
local bufnr = vim.api.nvim_get_current_buf()
32+
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
33+
file_contents = vim.fn.join(lines, "\n")
34+
end
35+
else
36+
local message = "Not a valid Apex script"
2537
Debug:log("execute_anon.lua", message)
2638
vim.notify(message, vim.log.levels.ERROR)
2739
return
@@ -35,12 +47,24 @@ M.execute_anon = function()
3547
Popup:create_popup({})
3648
Popup:write_to_popup("Executing anonymous Apex script...")
3749
local executable = Util.get_sf_executable()
38-
local command = string.format("%s apex run -f '%s' -o %s", executable, path, default_username)
39-
Debug:log("execute_anon.lua", "Running " .. command .. "...")
50+
local args = {}
51+
local writer = nil
52+
if not is_unsaved_buffer then
53+
args = { "apex", "run", "-f", path, "-o", default_username }
54+
local command =
55+
string.format("%s apex run -f '%s' -o %s", executable, path, default_username)
56+
Debug:log("execute_anon.lua", "Running " .. command .. "...")
57+
else
58+
writer = file_contents
59+
args = { "apex", "run", "-o", default_username }
60+
local command = string.format("%s apex run -o %s", executable, default_username)
61+
Debug:log("execute_anon.lua", "Piping unsaved buffer contents into " .. command .. "...")
62+
end
4063
local new_job = Job:new({
4164
command = executable,
4265
env = Util.get_env(),
43-
args = { "apex", "run", "-f", path, "-o", default_username },
66+
args = args,
67+
writer = writer,
4468
on_exit = function(j, code)
4569
vim.schedule(function()
4670
if code == 0 then
@@ -56,9 +80,11 @@ M.execute_anon = function()
5680
on_stderr = function(_, data)
5781
vim.schedule(function()
5882
Debug:log("execute_anon.lua", "Command stderr is: %s", data)
59-
local trimmed_data = vim.trim(data)
60-
if string.len(trimmed_data) > 0 then
61-
Popup:write_to_popup(data)
83+
if data then
84+
local trimmed_data = vim.trim(data)
85+
if string.len(trimmed_data) > 0 then
86+
Popup:write_to_popup(data)
87+
end
6288
end
6389
end)
6490
end,

0 commit comments

Comments
 (0)