Skip to content

Expose C# API for hosted scenarios + allow AST to be passed directly #1056

Closed
@rjmholt

Description

@rjmholt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions