diff --git a/src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs b/src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs
index 73e5cfa27..514e629a5 100644
--- a/src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs
+++ b/src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs
@@ -122,7 +122,7 @@ public AnalysisService(
///
/// The analysis engine to use for running script analysis.
///
- private PssaCmdletAnalysisEngine AnalysisEngine => _analysisEngineLazy?.Value;
+ internal PssaCmdletAnalysisEngine AnalysisEngine => _analysisEngineLazy?.Value;
///
/// Sets up a script analysis run, eventually returning the result.
@@ -346,7 +346,7 @@ private void ClearOpenFileMarkers()
}
}
- private async Task DelayThenInvokeDiagnosticsAsync(ScriptFile[] filesToAnalyze, CancellationToken cancellationToken)
+ internal async Task DelayThenInvokeDiagnosticsAsync(ScriptFile[] filesToAnalyze, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
@@ -409,7 +409,7 @@ private void PublishScriptDiagnostics(ScriptFile scriptFile, IReadOnlyList(diagnostics)
diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs
index d0f1f0ef0..02a5a23bc 100644
--- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs
+++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs
@@ -532,8 +532,8 @@ public async Task DebuggerBreaksInUntitledScript()
const string scriptPath = "untitled:Untitled-1";
Assert.True(ScriptFile.IsUntitledPath(scriptPath));
ScriptFile scriptFile = workspace.GetFileBuffer(scriptPath, contents);
- Assert.Equal(scriptFile.DocumentUri, scriptPath);
- Assert.Equal(scriptFile.Contents, contents);
+ Assert.Equal(scriptPath, scriptFile.DocumentUri);
+ Assert.Equal(contents, scriptFile.Contents);
Assert.True(workspace.TryGetFile(scriptPath, out ScriptFile _));
await debugService.SetCommandBreakpointsAsync(
diff --git a/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs b/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs
index b6fbd881e..430687f93 100644
--- a/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs
+++ b/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs
@@ -72,8 +72,8 @@ await psesHost.ExecutePSCommandAsync(
CancellationToken.None).ConfigureAwait(true);
Assert.NotNull(commandAdded);
- Assert.Equal(commandAdded.Name, commandName);
- Assert.Equal(commandAdded.DisplayName, commandDisplayName);
+ Assert.Equal(commandName, commandAdded.Name);
+ Assert.Equal(commandDisplayName, commandAdded.DisplayName);
// Invoke the command
await extensionCommandService.InvokeCommandAsync(commandName, editorContext).ConfigureAwait(true);
diff --git a/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs b/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs
index 05f069f2c..9e8c00dde 100644
--- a/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs
+++ b/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs
@@ -2,11 +2,11 @@
// Licensed under the MIT License.
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services;
-using Microsoft.PowerShell.EditorServices.Services.Analysis;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Test;
using Xunit;
@@ -16,13 +16,15 @@ namespace PowerShellEditorServices.Test.Services.Symbols
[Trait("Category", "PSScriptAnalyzer")]
public class PSScriptAnalyzerTests
{
+ private readonly WorkspaceService workspaceService = new(NullLoggerFactory.Instance);
private readonly AnalysisService analysisService;
+ private const string script = "function Get-Widgets {}";
public PSScriptAnalyzerTests() => analysisService = new(
NullLoggerFactory.Instance,
languageServer: null,
configurationService: null,
- workspaceService: null,
+ workspaceService: workspaceService,
new HostStartupInfo(
name: "",
profileId: "",
@@ -39,11 +41,13 @@ public class PSScriptAnalyzerTests
bundledModulePath: PsesHostFactory.BundledModulePath));
[Fact]
- public async Task CanLoadPSScriptAnalyzer()
+ public async Task CanLoadPSScriptAnalyzerAsync()
{
- PssaCmdletAnalysisEngine engine = analysisService.InstantiateAnalysisEngine();
- Assert.NotNull(engine);
- ScriptFileMarker[] violations = await engine.AnalyzeScriptAsync("function Get-Widgets {}").ConfigureAwait(true);
+ ScriptFileMarker[] violations = await analysisService
+ .AnalysisEngine
+ .AnalyzeScriptAsync(script)
+ .ConfigureAwait(true);
+
Assert.Collection(violations,
(actual) =>
{
@@ -54,5 +58,23 @@ public async Task CanLoadPSScriptAnalyzer()
Assert.Equal("PSScriptAnalyzer", actual.Source);
});
}
+
+ [Fact]
+ public async Task DoesNotDuplicateScriptMarkersAsync()
+ {
+ ScriptFile scriptFile = workspaceService.GetFileBuffer("untitled:Untitled-1", script);
+ ScriptFile[] scriptFiles = { scriptFile };
+
+ await analysisService
+ .DelayThenInvokeDiagnosticsAsync(scriptFiles, CancellationToken.None)
+ .ConfigureAwait(true);
+ Assert.Single(scriptFile.DiagnosticMarkers);
+
+ // This is repeated to test that the markers are not duplicated.
+ await analysisService
+ .DelayThenInvokeDiagnosticsAsync(scriptFiles, CancellationToken.None)
+ .ConfigureAwait(true);
+ Assert.Single(scriptFile.DiagnosticMarkers);
+ }
}
}