xixiaofinland/sf.nvim

Proposal: List/pull debug logs

Closed this issue · 1 comments

So, I want to start working on adding a new feature: The ability to list debug logs in the org and pull one into a file. This is something the cli supports and the VSCode extension as well.

Currently, the cli allows pulling a list of all debug logs in the org using sf apex list log --json. This prints a json to stdout with a list of all debug logs and properties for them in it. Using the information in that, one can then sf apex get log --id=<id> using the id found in the previous json to pull a log into a file.

I'm thinking, since logs can change quite rapidly (one would usually want to pull a very recently created log), there's little incentive to save the log list file on disk, and then use that to list logs to pull. Instead, we could have a single command Sf.pull_log() that would:

  1. Call sf apex list log --json to get all currently available logs
  2. Put that json into a table and into fzf-lua, and when one is selected:
  3. Pull that log using sf apex get log --id= and save it to file, then open that file

I volunteer to work on this, just have one blocker I'm not sure what the best way to solve is: We'd need to run a command, and get the stdout output and use that next to create the fzf-lua table. I think all our current job_call methods at most run a callback function with no arguments, but none can await a command then read the stdout from that command.

What would be the best way to approach this?

Good initiative :)!

In util.lua there is M.silent_job_call using vim.fn.jobstart.
It hason_stdout callback too, check :h jobstart.

Despitevim.fn.jobstart works, it's vimscript based and old. If you have interests, I'd recommend to explore :h vim.loop and :h vim.system providing more idiomatic Lua bindings and are often more flexible. This is an item in my to-do :).

Pseudocode as below for jobstart.

vim.fn.jobstart(cmd, {
  stdout_buffered = true,
  on_stdout = function(_, data)
    if data then
      -- Join the stdout lines and parse the JSON like the existing features in sf.nvim
      if err then
        vim.notify("Failed to parse JSON: " .. err, vim.log.levels.ERROR)
      else
        -- Do something with the parsed JSON result
      end
    end
  end,