[PSS 2017] Auto-include functions when running selected code

Post feature requests, product enhancement ideas, and other product-specific suggestions here. Do not post bug reports.
Forum rules
Do not post any licensing information in this forum.
This topic is 7 years and 4 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Bosparan
Posts: 290
Last visit: Fri Oct 08, 2021 11:59 am

[PSS 2017] Auto-include functions when running selected code

Post by Bosparan »

Hi,

one of the more frequently used features I use in PSS is the ability to run the code I have currently selected. Now sometimes, especially in a bigger project I have helper functions strewn across multiple files (usually structured by category). Actually, most of the projects that get compiled to exe are structured thus:
- Main Workflow File
- One file for each main step of the workflow
- As many utility function files as there are categories of utility functions
- Miscellaneous other things (configuration framework, audit framework, serialization framework, etc.)

Now if I'm building a substep of the process, I like to select a few lines and run them, just to see whether they work as intended. However, if those use helper functions, they obviously are stored in another file (or several of them). So here's the idea:
How about adding a function (and adding it to the ribbon bar) to include all project-functions called in the selected code being run?

That way I could simply run the selection. Currently I tend to open a powershell console, go through the effort to paste all helper functions used and then the selection. Ugh.

Mocking the code
Now sometimes not all functions can be called in isolation without other steps, and for running just this snippet all that may not be necessary or even possible. So if there were a way to include mock functions (similar to how pester handles that) it would be even better.
I guess I could write a mocking framework to include do just that (at least in conjunction with the first part of this feature request), but ... if I could set project files to a new build type ("Mock"), which would cause the file to be loaded before running code directly, but not be part of the build action, that would be even better. I could just set up a default mock function for something that is used more frequently but must be mocked in quick test-runs.

Cheers,
Fred
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: [PSS 2017] Auto-include functions when running selected code

Post by DevinL »

This one is a bit more complicated of a feature to implement as I'm sure you can imagine :D

That being said, as always, I have added it to the Wishlist and whenever we have more information it'll be posted here.
DevinL
SAPIEN Technologies, Inc.
Bosparan
Posts: 290
Last visit: Fri Oct 08, 2021 11:59 am

Re: [PSS 2017] Auto-include functions when running selected code

Post by Bosparan »

Hi Devin,

oh, I agree it's a tad bit more complex than my request to allow setting "Shared" to true on a file's configuration when the file is set to Content (Which is still my hottest and most burning feature request btw. . Try building a module project with one file per function and multiple subfolders *grml*). On the other hand, it's fairly simple as far as complexity is concerned:
Took me about 30 minutes to build a simple function that did that. I'm fully aware that ...
- Doing it in C#
- Optimizing it for performance
- Integrating it into an already complex tool
- Building it solid, rather than slapdash
- Testing it
- QA and realease it
... takes a tad bit of extra time, but basically, it is fairly simple as far as the complexity is:

1) Gather list of relevant files
2) Parse scriptblock, retrieve all commands
3) Parse files, retrieve all function definitions and alias declarations
4) Create new runspace, add all functions and aliases found to it
5) Resolve all commands in the scriptblock within that runspace
6) Send all function definitions of all thus found custom functions to the parser, same as the scriptblock, figuring out meta-dependencies
7) Repeat until finished (Recursion is your best friend here :) )
8) Create a new runspace, add all definitions of all needed functions to it
9) Import all mock files to that runspace
10) Run the scriptblock

You can cut down a lot of that time by caching all available functions on a background thread and processing dependent functions within the project (you can probably hitch that to the part that's handling Primal Sense processing for project internal content). That would cut down on 1) and 3-7) when actually using the feature, leaving you with parsing the scriptblock that is executed, looking up the dependency table and creating the runspace that runs it all, which should be an acceptable overhead from the users experience point of view.

No, it's not trivial, but far from one of the "big&ugly"-ones I already threw at your head ;)

That said, no, I don't expect it to happen overnight. What's more, I'd appreciate other users sharing their opinion on that feature: I don't know whether it's a "just me" kind of thing - after all, the usefulness of this feature depends heavily on just how PSS is being used.

Cheers,
Fred
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: [PSS 2017] Auto-include functions when running selected code

Post by DevinL »

Hey Bosparan,

Just a note that we've added this feature in our latest service build (5.4.136) and we'd appreciate it if you could give it a try.

Let us know if you have any troubles or concerns :)
DevinL
SAPIEN Technologies, Inc.
This topic is 7 years and 4 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked