Skip to content

Commit 447b447

Browse files
committed
Include PSScriptAnalyzer rule name in marker message
This change adds the PSScriptAnalyzer rule name to any marker messages that are returned so that it's easy to know which rule to suppress or disable in settings. It also makes the rule source more clear in marker messages, distinguishing between PowerShell syntax markers and PSScriptAnalyzer's semantic markers. Resolves PowerShell/vscode-powershell#781.
1 parent f9fc163 commit 447b447

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
2828
public class LanguageServer : LanguageServerBase
2929
{
3030
private static CancellationTokenSource existingRequestCancellation;
31-
private readonly static string DiagnosticSourceName = "PowerShellEditorServices";
3231

3332
private bool profilesLoaded;
3433
private bool consoleReplStarted;
@@ -1119,8 +1118,7 @@ protected async Task HandleCodeActionRequest(
11191118
{
11201119
foreach (var diagnostic in codeActionParams.Context.Diagnostics)
11211120
{
1122-
if (string.Equals(diagnostic.Source, DiagnosticSourceName, StringComparison.CurrentCultureIgnoreCase) &&
1123-
!string.IsNullOrEmpty(diagnostic.Code) &&
1121+
if (!string.IsNullOrEmpty(diagnostic.Code) &&
11241122
markerIndex.TryGetValue(diagnostic.Code, out correction))
11251123
{
11261124
codeActionCommands.Add(
@@ -1482,8 +1480,8 @@ private static Diagnostic GetDiagnosticFromMarker(ScriptFileMarker scriptFileMar
14821480
{
14831481
Severity = MapDiagnosticSeverity(scriptFileMarker.Level),
14841482
Message = scriptFileMarker.Message,
1485-
Code = Guid.NewGuid().ToString(),
1486-
Source = DiagnosticSourceName,
1483+
Code = scriptFileMarker.Source + Guid.NewGuid().ToString(),
1484+
Source = scriptFileMarker.Source,
14871485
Range = new Range
14881486
{
14891487
Start = new Position

src/PowerShellEditorServices/Workspace/ScriptFileMarker.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public class ScriptFileMarker
7878
/// </summary>
7979
public MarkerCorrection Correction { get; set; }
8080

81+
/// <summary>
82+
/// Gets or sets the name of the marker's source like "PowerShell"
83+
/// or "PSScriptAnalyzer".
84+
/// </summary>
85+
public string Source { get; set; }
86+
8187
#endregion
8288

8389
#region Public Methods
@@ -91,7 +97,8 @@ internal static ScriptFileMarker FromParseError(
9197
{
9298
Message = parseError.Message,
9399
Level = ScriptFileMarkerLevel.Error,
94-
ScriptRegion = ScriptRegion.Create(parseError.Extent)
100+
ScriptRegion = ScriptRegion.Create(parseError.Extent),
101+
Source = "PowerShell"
95102
};
96103
}
97104
private static string GetIfExistsString(PSObject psobj, string memberName)
@@ -153,10 +160,11 @@ internal static ScriptFileMarker FromDiagnosticRecord(PSObject psObject)
153160

154161
return new ScriptFileMarker
155162
{
156-
Message = diagnosticRecord.Message as string,
163+
Message = $"{diagnosticRecord.Message as string} ({ruleName})",
157164
Level = GetMarkerLevelFromDiagnosticSeverity((diagnosticRecord.Severity as Enum).ToString()),
158165
ScriptRegion = ScriptRegion.Create(diagnosticRecord.Extent as IScriptExtent),
159-
Correction = correction
166+
Correction = correction,
167+
Source = "PSScriptAnalyzer"
160168
};
161169
}
162170

0 commit comments

Comments
 (0)