xixiaofinland / sf.nvim

22 stars 6 forks source link

SF Run Query - Run with selected text from visual mode #94

Closed ognjen-vuceljic closed 5 days ago

ognjen-vuceljic commented 1 week ago

Hello,

thanks a lot for continuous improvements for this plugin!

Here's an idea that I have (similar feature, I think, exists in VS Code):

sf data query --query "{this would be the selected text}"

Example of usage:

image

Sometimes there is a need to quickly inspect data from the current org, without the need to create a separate file that would be a source for SFRunQuery command.

Having the ability to execute a query by visually selecting SOQL portion from any file might speed some things up.

Apologies in advance if such feature already exists, or if it is hard to implement.

@xixiaofinland

xixiaofinland commented 1 week ago

Thanks for submitting this feature request!

It does look like a neat feature. Do you know how this works in VSCode, would you mind to elaborate the steps?

There are steps I don't have clear picture in mind yet. For example, once the highlighted SOQL runs, should it run in the terminal or background? Is the result the debug log or precisely the SQOL result? Should the result display in a new buffer/window or in the terminal?

ognjen-vuceljic commented 1 week ago

@xixiaofinland Sure, please find the VS Code feature breakdown below:

  1. Find the SOQL portion of the code, and highlight it (in this example, I've used the SOQL that is part of existing APEX class)

Screenshot 2024-07-08 at 09 25 30

Notice the "Execute SOQL With The Currently Selected Text" above - that's the VS Code shortcut that I can use whenever a portion of code is selected. This command is triggered via shortcut that VS Code gives us with this Salesforce extension. It would probably be equivalent to the keymap in Neovim which would grab the selected code and put it in the sf data query command

  1. Once this "Execute SOQL..." is selected , VS Code asks us about the mode in which we want to execute this query (aka which API to use)

Screenshot 2024-07-08 at 09 28 05

  1. The query results are simply written to the terminal, as they would if we executed this command directly via terminal instead of triggering the VS Code extension shortcut

Screenshot 2024-07-08 at 09 28 20

For consistency sake, I would keep the output structure of this command the same as the structure of any other SF command we execute in the terminal. It's descriptive enough for us to understand what the final result was, and what are the rows that query returned.

The key part here is an easy way to execute SOQL commands regardless of where we are within our project structure. Having dedicated .soql files from which we can run existing SOQL commands is nice and useful, but I think this would speed things up even more, and provide better user experience.

Hope this breakdown was useful - feel free to let me know if anything else is needed!

xixiaofinland commented 1 week ago

Appreciate for the clear description. This is clear for now. I will inform here once it's done.

xixiaofinland commented 6 days ago

a new run_highlighted_soql() (hotkey <leader>sq) is added.

The hotkey is enabled in visual mode only, it copies the selected text and pastes into the term as a SOQL. Please test out.

ognjen-vuceljic commented 6 days ago

Thank you @xixiaofinland

Initial tests are showing that <leader>sq executes the highlighted SOQL properly for both one-line and multi-line (formatted) queries.

There's just one UI/UX thing that I spotted (multi-line formatted query via prettier):

Screenshot 2024-07-11 at 14 03 42

This query functionally worked, and produced expected results. However, the UI representation in the terminal appears to show some command not found messages.

xixiaofinland commented 6 days ago

Not fully get your point. I did a quick bug fix, does it happen to solve ur problem?

xixiaofinland commented 6 days ago

Selection across multi lines should be ok Screenshot 2024-07-11 at 15 28 01

ognjen-vuceljic commented 6 days ago

Thank you @xixiaofinland , now it looks ok :)

Apologies, I had to edit the previous comment, as I initially didn't write that multi-line queries were affected.

Now both single and multi line queries are correctly visualized in terminal, and they both produce expected results.

xixiaofinland commented 5 days ago

great!