Skip to content

Commit

Permalink
fix: Debug logging on plugin start
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmorris180 committed Mar 23, 2024
1 parent f84f7e6 commit 7e10f89
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lua/salesforce/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Debugger:log(scope, item, ...)
or (type(item) == "string" and string.format(item, ...))

local debug_str =
string.format("[salesforce:%s %s in %s] > %s", os.date("%H:%M:%S"), line, scope, final_arg)
string.format("[salesforce:%s %s in %s] > %s", os.date("%c"), line, scope, final_arg)
self:log_str(debug_str)
end

Expand Down
2 changes: 1 addition & 1 deletion lua/salesforce/diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local function diff_callback(j)

local json_ok, sfdx_response = pcall(vim.json.decode, sfdx_output)
if not json_ok or not sfdx_response then
vim.notify("Failed to parse the SFDX command output", vim.log.levels.ERROR)
vim.notify("Failed to parse the 'diff' SFDX command output", vim.log.levels.ERROR)
vim.fn.delete(temp_dir, "rf")
return
end
Expand Down
4 changes: 2 additions & 2 deletions lua/salesforce/file_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local function push_to_org_callback(j)

local json_ok, sfdx_response = pcall(vim.json.decode, sfdx_output)
if not json_ok or not sfdx_response then
vim.notify("Failed to parse the SFDX command output", vim.log.levels.ERROR)
vim.notify("Failed to parse the 'push to org' SFDX command output", vim.log.levels.ERROR)
return
end

Expand Down Expand Up @@ -78,7 +78,7 @@ local function pull_from_org_callback(j)

local json_ok, sfdx_response = pcall(vim.json.decode, sfdx_output)
if not json_ok or not sfdx_response then
vim.notify("Failed to parse the SFDX command output", vim.log.levels.ERROR)
vim.notify("Failed to parse the 'pull from org' SFDX command output", vim.log.levels.ERROR)
return
end

Expand Down
2 changes: 2 additions & 0 deletions lua/salesforce/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
--- }
--- <
local Config = require("salesforce.config")
local OrgManager = require("salesforce.org_manager")

local Salesforce = {}

Expand All @@ -58,6 +59,7 @@ local Salesforce = {}
---@usage `require("salesforce").setup({})`
function Salesforce.setup(opts)
Salesforce.config = Config:setup(opts)
OrgManager:get_org_info(true)
end

return Salesforce
9 changes: 4 additions & 5 deletions lua/salesforce/org_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function OrgManager:new()
local o = {}
setmetatable(o, self)
self.__index = self
self:get_org_info(false)
return o
end

Expand Down Expand Up @@ -75,7 +74,7 @@ function OrgManager:command_in_progress()
end
end

function OrgManager:get_org_info(add_log)
function OrgManager:get_org_info(add_success_message)
local command = string.format("%s org list --json", executable)
Debug:log("org_manager.lua", "Executing command: %s", command)
local args = Util.split(command, " ")
Expand All @@ -91,10 +90,10 @@ function OrgManager:get_org_info(add_log)
Debug:log("org_manager.lua", sfdx_output)
local json_ok, sfdx_response = pcall(vim.json.decode, sfdx_output)
if not json_ok or not sfdx_response then
vim.notify("Failed to parse the SFDX command output", vim.log.levels.ERROR)
vim.notify("Failed to parse the 'org list' SFDX command output", vim.log.levels.ERROR)
return
end
if add_log then
if add_success_message then
Util.clear_and_notify("Successfully refreshed org info")
end
self:parse_orgs(sfdx_response)
Expand Down Expand Up @@ -140,7 +139,7 @@ function OrgManager:select_org()
Debug:log("org_manager.lua", sfdx_output)
local json_ok, sfdx_response = pcall(vim.json.decode, sfdx_output)
if not json_ok or not sfdx_response then
vim.notify("Failed to parse the SFDX command output", vim.log.levels.ERROR)
vim.notify("Failed to parse the 'config set target-org' SFDX command output", vim.log.levels.ERROR)
return
end

Expand Down
9 changes: 1 addition & 8 deletions lua/salesforce/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ function M.get_file_name_without_extension(fileName)
end

function M.split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
return vim.split(inputstr, sep, {trimempty = true})
end

function M.get_env()
Expand Down

0 comments on commit 7e10f89

Please sign in to comment.