Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 2d62da9

Browse files
add issue tracking to SuppressIssueContextAction, remove entry for suppressing an issue once and make it default
1 parent b5312c6 commit 2d62da9

1 file changed

Lines changed: 12 additions & 26 deletions

File tree

  • src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ Task<IContextAction[]> IContextActionProvider.GetAvailableActionsAsync(EditorRef
345345
result.AddRange(tag.Actions);
346346
string issueName;
347347
if (CanSuppress(tag, out issueName)) {
348-
result.Add(new SuppressIssueContextAction(issueName, SuppressType.Once));
349-
result.Add(new SuppressIssueContextAction(issueName, SuppressType.Always));
348+
result.Add(new SuppressIssueContextAction(issueName));
350349
}
351350
}
352351
}
@@ -363,21 +362,14 @@ bool CanSuppress(InspectionTag tag, out string issueName)
363362
return true;
364363
}
365364

366-
enum SuppressType {
367-
Once,
368-
Always
369-
}
370-
371365
[ContextAction("Suppress issue", Description = "Suppresses an issue.")]
372366
class SuppressIssueContextAction : ContextAction
373367
{
374368
string issueName;
375-
SuppressType type;
376369

377-
public SuppressIssueContextAction(string issueName, SuppressType type)
370+
public SuppressIssueContextAction(string issueName)
378371
{
379372
this.issueName = issueName;
380-
this.type = type;
381373
}
382374

383375
public override Task<bool> IsAvailableAsync(EditorRefactoringContext context, CancellationToken cancellationToken)
@@ -387,27 +379,21 @@ public override Task<bool> IsAvailableAsync(EditorRefactoringContext context, Ca
387379

388380
public override string DisplayName
389381
{
390-
get {
391-
string fmt;
392-
if (type == SuppressType.Once)
393-
fmt = "Suppress '{0}' once";
394-
else
395-
fmt = "Suppress '{0}'";
396-
return string.Format(fmt, issueName);
397-
}
382+
get { return string.Format("Suppress '{0}'", issueName); }
398383
}
399384

400385
public override void Execute(EditorRefactoringContext context)
401386
{
402-
var myContext = SDRefactoringContext.Create(context.Editor, default(CancellationToken));
403-
var currentNode = myContext.RootNode.GetNodeAt<Statement>(context.CaretLocation);
404-
if (currentNode == null)
405-
return;
406-
using (var script = myContext.StartScript()) {
407-
script.InsertBefore(currentNode, new Comment(string.Format(" disable{1}{0}", issueName, type == SuppressType.Once ? " once " : " ")));
408-
}
387+
SD.AnalyticsMonitor.TrackFeature(typeof(SuppressIssueContextAction), issueName);
388+
var lineNo = context.CaretLocation.Line;
389+
var document = context.Editor.Document;
390+
391+
var line = document.GetLineByNumber(lineNo);
392+
string indentation = DocumentUtilities.GetIndentation(document, lineNo);
393+
string newLine = DocumentUtilities.GetLineTerminator(document, lineNo);
394+
document.Insert(line.Offset, indentation + "// disable once " + issueName + newLine);
409395
}
410396
}
411-
#endregion
412397
}
398+
#endregion
413399
}

0 commit comments

Comments
 (0)