Description
A fairly large ask, but I would be very happy doing the work. Just want to discuss it with everyone.
In PowerShell EditorServices, we have a hosted PowerShell environment and do a lot of parsing and AST analysis separately from PSScriptAnalyzer. And we are often generating a new AST with every document change. This means PSScriptAnalyzer is doing a fair amount of duplicate work when we call it, since it only accepts input as a string or a filepath.
Our ideal would be to be able to embed PSScriptAnalyzer with a C# API call, pass in our own hosted PowerShell session as its engine in the constructor, and then send pre-parsed ASTs to PSScriptAnalyzer for analysis. The cmdlets would then wrap or be an alternative entry point for this API.
@JamesWTruher and I have discussed something like this before, but I just want to document the desire. He and I also discussed being able to only use rules that use the parser, rather than the whole engine.
Anyway, to summarise:
- We'd like to pass AST objects directly to PSSA, rather than having to reparse strings
- Ideally we could do this in C# (no
ps.AddCommand("Invoke-ScriptAnalyzer").Invoke()
) - Even more ideally we could pass in our own hosted PowerShell runtime for the analyzer to use, rather than have it spin up its own.