-
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
AnalysisService improvments #1179
Conversation
// Load any of the profile paths that exist | ||
var command = new PSCommand(); | ||
bool hasLoadablePath = false; | ||
foreach (var profilePath in GetLoadableProfilePaths(this.profilePaths)) |
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.
Oh, I forgot. I was seeing an exception here in the debugger because none of the profile files existed. And it was my change that caused it in another PR. So I fixed it.
using Microsoft.Extensions.Logging; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Server; | ||
using System.Threading; | ||
using System.Collections.Concurrent; | ||
using Microsoft.PowerShell.EditorServices.Services.TextDocument; | ||
using Microsoft.PowerShell.EditorServices.Utility; | ||
using Microsoft.PowerShell.EditorServices.Services.Analysis; | ||
using Microsoft.PowerShell.EditorServices.Services.Configuration; |
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.
nit: can you sort these?
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.
don't forget this
_workplaceService = workspaceService; | ||
_analysisDelayMillis = 750; | ||
_mostRecentCorrectionsByFile = new ConcurrentDictionary<string, CorrectionTableEntry>(); | ||
_hasInstantiatedAnalysisEngine = false; |
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.
potential threading concern... If you wanna go down this route, maybe it's best to make the AnalysisEngine Lazy<>
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.
Yeah I was thinking about that, but unlike Lazy<>
, this will respond to a configuration update by re-instantiating the engine. It might be that the best solution is to put a lock in the getter?
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.
maybe use an Interlocked.Exchange or something instead. I'm concerned that if there's a configuration update when this is being instantiated for the first time that that could be a race condition?
_pssaModuleInfo = pssaModuleInfo; | ||
_mostRecentCorrectionsByFile = new ConcurrentDictionary<string, (SemaphoreSlim, Dictionary<string, MarkerCorrection>)>(); | ||
_workplaceService = workspaceService; | ||
_analysisDelayMillis = 750; |
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.
can this be a constant instead?
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 was wondering whether to put it in as a constructor parameter. It used to be inline where the task is. As a field, we could use reflection to change the setting even.
src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs
Show resolved
Hide resolved
@@ -530,7 +535,7 @@ internal string ResolveRelativeScriptPath(string baseFilePath, string relativePa | |||
return combinedPath; | |||
} | |||
|
|||
private static Uri UnescapeDriveColon(Uri fileUri) | |||
internal static Uri UnescapeDriveColon(Uri fileUri) |
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.
revert this when you use the other API
Diagnostics.Clear(); | ||
|
||
PwshExe = TestsFixture.PwshExe; |
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.
what's the reason for this change?
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 needed to edit the tests and moved this down so it wasn't with the list instantiation code
/// <returns>The output of PowerShell execution.</returns> | ||
private Collection<PSObject> InvokePowerShellWithModulePathPreservation(System.Management.Automation.PowerShell powershell) | ||
{ | ||
if (_alreadyRun) |
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.
What is this check for?
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.
Since runspace creation only happens at first invocation, I put a boolean in to reduce the overhead on subsequent calls
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.
Run a few manual tests to make sure - I know RunspacePool has a habit of creating new runspaces within the pool (as in, we don't have control over when, why and how it creates Runspaces). I've seen in Get-Runspace
incremental runspace numbering which is why I have concerns here.
src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/TextDocument/ScriptFileMarker.cs
Outdated
Show resolved
Hide resolved
using System.Collections; | ||
using System.Runtime.InteropServices; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; |
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.
nit: usually system* come first, then sorted everything else.
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.
That's how VS sorted it. I've corrected
|
||
private CancellationTokenSource _diagnosticsCancellationTokenSource; | ||
|
||
#region Engine Initialization | ||
#endregion |
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.
empty region?
@@ -107,6 +107,8 @@ public PssaCmdletAnalysisEngine Build() | |||
} | |||
} | |||
|
|||
private const int PSSA_RUNPOOL_SIZE = 10; |
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.
has this always been 10? 😮
_alreadyRun = true; | ||
finally | ||
{ | ||
Interlocked.Increment(ref _pssaRunCount); |
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.
is it guaranteed that a RunspacePool uses a new Runspace until it hits the max of what it can support?
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.
Otherwise the first 10 runs might use the same runspace and then subsequent runs spin up new runspaces.
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
This PR was originally supposed to stop crashes when we can't find PSScriptAnalyzer on the module path (when the Create() method returns null), but instead does a few things:
ConfigurationChanged
event so that things to can subscribe to it early onlong
IDs (even though we can in the function that takes diagnostic IDs) and (2) process them anyway (nocontinue
)...Aids PowerShell/vscode-powershell#2127 and PowerShell/vscode-powershell#2190