-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new ParseError level to ScriptFileMarkerLevel and only have it send parse errors #888
Add new ParseError level to ScriptFileMarkerLevel and only have it send parse errors #888
Conversation
I'll try to fully review this tomorrow but one concern I have is that if someone turns off codeAnalysis, they'll lose parse errors now, right? Or does this fallback to using the PSES parse error diagnostics if code analysis is disabled. Oh yeah, maybe two concerns - PSSA performance - I get really tired of waiting for PSSA diagnostic markers catching up with my code edits in large files. Squiggles often display on the wrong lines for minutes some times. I'd hate to not get updated on parse errors for minutes. That could mean I've committed a file with a parse error. :-( |
Now that I think about, I'd almost prefer that we disable that rule (or ignore the marker) and rely on our parse error diagnostics because performance. I timed v1.18 on the InvokePlaster.ps1 file and it still takes 15 secs to complete. Seems like the response time on parse errors should be much faster than that. |
{ | ||
throw new ArgumentException( | ||
string.Format( | ||
"The provided DiagnosticSeverity value '{0}' is unknown.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: Using string interpolation ($""
) we could merge 3 lines into 1 whilst having better readability.
@rkeithhill The new version should be twice as fast for cold starts and magnitudes faster when re-analyzing. I am not sure if this is a PSES or PSSA issue that refreshes sometimes take a long time or require more typing. |
@rkeithhill was that 15-second delay a cold start, or every time you pressed a key? If it was just cold-start, how would you characterize performance after cold-start? |
I did a quick check on my mac with 1.18, cold-start definitely takes longer than I like, here is what I saw:
|
I did a comparison of PSSA |
Fair point, my second invocation does drop to < 1 second. How does your mac behave (what's the CPU usage) while this runs:
This simulates someone typing in a commandline of 100 chars where keystrokes are spaced about 250 milliseconds apart (OK, they are a fast-ish typist). What I see on my laptop (apparently twice as slow as your mac) is that while this runs, my CPU sits at 10%. That's not horrible but not great either. That said, we do have code in the extension that anticipates this scenario (delayThenInvokeDiagnostics) that should help here. Anyway, rather that characterize perf in isolation, I think we need to eval the perf of this running in the extension on some good size files and not only loading but editing them to see what the experience is like. Keeping track of how long a parse error diag takes to show up and what the CPU usage is. We've already gotten complaints about CPU usage. |
BTW the perf work & results on PSSA are great! Great job there. It's just that use with the extension is perhaps a bit abusive (runs a lot). Also we have other issues with the the message processing getting behind due to its sequential nature and the fact that we dont' handle cancelRequests. I have a PR open to attempt to address the cancelRequests but it hasn't gotten any traction yet. |
@JamesWTruher and I talked about this and agree with @rkeithhill in having PSES handle the parse errors... but we agree for a different reason. One of the things @rjmholt, @JamesWTruher and I have been set out to do was switch to using PSSA via a C# API that @JamesWTruher has been working on (not quite done yet). One of the requirements for that work is the ability to hand PSSA an AST so that the rules can be run on that because PSES already has the AST. If you pass something the AST, it can't get the parse errors so PSES will have to send parse errors from the initial parsing of the file anyway. I'll filter out the ParseErrors for now and continue sending them via PSES in preparation for PSSA as an API that accepts an AST. |
Ooh, I like the idea of using the API directly. That cuts out a bunch of PowerShell invocation goo and redundant parsing! Plus doing it this way means we still get parse error diags even if someone chooses to disable code analysis. |
Yes, the high level plan is to publish a NuGet package of PSSA (Engine and Rules) that multi-targets |
6c3af28
to
4937f56
Compare
I've updated the PR to use parse errors from PSES. |
@@ -162,36 +164,27 @@ internal static ScriptFileMarker FromDiagnosticRecord(PSObject psObject) | |||
}; | |||
} | |||
|
|||
string severity = diagnosticRecord.Severity.ToString(); | |||
if(!Enum.TryParse(severity, out ScriptFileMarkerLevel level)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit, space between if
and opening (
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad I wasn't the only one that felt like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - fixed.
} | ||
|
||
scriptFile.SyntaxMarkers.AddRange(semanticMarkers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to modify the SyntaxMarkers collection in ScriptFile by adding semantic markers? Maybe we should have two collections in ScriptFile (SyntaxMarkers and SemanticMarkers) or perhaps rename the property to DiagnosticMarkers (or something like that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the rename since the syntax markers and semantic markers are both treated the same when they get sent to vscode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -55,7 +55,7 @@ public class AnalysisService : IDisposable | |||
/// <summary> | |||
/// An empty script marker result to return when no script markers can be returned. | |||
/// </summary> | |||
private static readonly ScriptFileMarker[] s_emptyScriptMarkerResult = new ScriptFileMarker[0]; | |||
private static readonly List<ScriptFileMarker> s_emptyScriptMarkerResult = new List<ScriptFileMarker>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is supposed to be a readonly empty value, it can't be a List<T>
.
Otherwise, if we need to return a mutable collection, we should either:
- Return a readonly collection here and create a new mutable collection around it in the caller if it needs extending, or;
- Return a List and not have an
s_emptyScriptMarkerResult
, but instead return anew List<T>()
every time.
If we return s_emptyScriptMarkerResult
and the caller then mutates it, those additions will become permanently added to s_emptyScriptMarkerResult
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. I've switched to just some new lists.
…erLevel and only have it send parse errors
…d only have it send parse errors (#891)
In PSScriptAnalyzer 1.18, they've added parse errors to the diagnostic records that get sent back from PSSA.
This broke us because they come in as a different
ScriptFileMarkerLevel
calledParseError
that we didn't handle.This PR adds that additional enum member and filters PSSA invocations to only get back all diagnostics other than ParseErrors. PSES still handles its own ParseErrors so that (1) there's no startup cost to ParseErrors, (2) ParseErrors get shown no matter whether PSSA is available.
cc @bergmeister