Skip to content

Commit 4bfa90b

Browse files
Merge pull request #32 from jonathanmorris180/fix/issue-24
Add diagnostics from push and pull commands
2 parents ff8e498 + 1fdc601 commit 4bfa90b

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

lua/salesforce/file_manager.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ local function push_to_org_callback(j)
5151
and sfdx_response.result.details
5252
and sfdx_response.result.details.componentFailures
5353
then
54-
local failures = {}
54+
local diagnostics = {}
5555
for _, failure in ipairs(sfdx_response.result.details.componentFailures) do
56-
if failure.problem then
57-
table.insert(failures, failure.problem)
56+
if failure.problem and failure.lineNumber and failure.columnNumber then
57+
table.insert(diagnostics, {
58+
lnum = failure.lineNumber - 1,
59+
col = failure.columnNumber - 1,
60+
message = failure.problem,
61+
severity = vim.diagnostic.severity.ERROR,
62+
})
5863
end
5964
end
60-
vim.notify("Error(s) while pushing " .. file_name, vim.log.levels.ERROR)
61-
vim.notify(table.concat(failures, "\n"), vim.log.levels.ERROR)
65+
Util.set_error_diagnostics(diagnostics)
66+
vim.notify(
67+
"Error(s) while pushing "
68+
.. file_name
69+
.. ". Check diagnostics. Overlapping messages from apex_ls have been omitted.",
70+
vim.log.levels.ERROR
71+
)
6272
return
6373
elseif sfdx_response.message then
6474
vim.notify(sfdx_response.message, vim.log.levels.ERROR)
@@ -184,6 +194,7 @@ local function pull(command)
184194
end
185195

186196
M.push_to_org = function()
197+
Util.clear_error_diagnostics()
187198
active_file_path = vim.fn.expand("%:p")
188199
local file_name = vim.fn.fnamemodify(active_file_path, ":t")
189200
local default_username = OrgManager:get_default_username()
@@ -208,6 +219,7 @@ M.push_to_org = function()
208219
end
209220

210221
M.pull_from_org = function()
222+
Util.clear_error_diagnostics()
211223
active_file_path = vim.fn.expand("%:p")
212224
local file_name = vim.fn.fnamemodify(active_file_path, ":t")
213225
local default_username = OrgManager:get_default_username()

lua/salesforce/util.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local Debug = require("salesforce.debug")
22

33
local M = {}
4+
local namespace = vim.api.nvim_create_namespace("salesforce.util")
45

56
local metadata_type_map = {
67
["lwc"] = "LightningComponentBundle",
@@ -121,4 +122,40 @@ function M.salesforce_cli_available()
121122
return false
122123
end
123124

125+
local function get_apex_ls_namespace()
126+
local diagnostic_namespaces = vim.diagnostic.get_namespaces()
127+
for id, ns in pairs(diagnostic_namespaces) do
128+
if string.find(ns.name, "apex_ls") then
129+
return id
130+
end
131+
end
132+
end
133+
134+
function M.set_error_diagnostics(diagnostics)
135+
local apex_ls_namespace = get_apex_ls_namespace()
136+
local bufnr = vim.api.nvim_get_current_buf()
137+
-- filter out overlapping diagnostics from apex_ls
138+
local filtered_diagnostics = {}
139+
for _, diagnostic in ipairs(diagnostics) do
140+
local apex_ls_diagnostics =
141+
vim.diagnostic.get(bufnr, { namespace = apex_ls_namespace, lnum = diagnostic.lnum })
142+
local found = false
143+
for _, apex_ls_diagnostic in ipairs(apex_ls_diagnostics) do
144+
if apex_ls_diagnostic.message == diagnostic.message then
145+
found = true
146+
break
147+
end
148+
end
149+
if not found then
150+
table.insert(filtered_diagnostics, diagnostic)
151+
end
152+
end
153+
vim.diagnostic.set(namespace, bufnr, filtered_diagnostics, {})
154+
end
155+
156+
function M.clear_error_diagnostics()
157+
local bufnr = vim.api.nvim_get_current_buf()
158+
vim.diagnostic.reset(namespace, bufnr)
159+
end
160+
124161
return M

0 commit comments

Comments
 (0)