-
Notifications
You must be signed in to change notification settings - Fork 1
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
NEW (Extension) @W-13992309@ Remove duplicate suppress violations prompts on the same line #92
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,13 @@ export class Fixer implements vscode.CodeActionProvider { | |
* @returns All actions corresponding to diagnostics in the specified range of the target document. | ||
*/ | ||
public provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext): vscode.CodeAction[] { | ||
const processedLines = new Set<number>(); | ||
// Iterate over all diagnostics. | ||
return context.diagnostics | ||
// Throw out diagnostics that aren't ours, or are for the wrong line. | ||
.filter(diagnostic => messages.diagnostics.source && messages.diagnostics.source.isSource(diagnostic.source) && diagnostic.range.isEqual(range)) | ||
// Get and use the appropriate fix generator. | ||
.map(diagnostic => this.getFixGenerator(document, diagnostic).generateFixes()) | ||
.map(diagnostic => this.getFixGenerator(document, diagnostic).generateFixes(processedLines)) | ||
// Combine all the fixes into one array. | ||
.reduce((acc, next) => [...acc, ...next], []); | ||
} | ||
|
@@ -72,15 +73,16 @@ abstract class FixGenerator { | |
* Abstract template method for generating fixes. | ||
* @abstract | ||
*/ | ||
public abstract generateFixes(): vscode.CodeAction[]; | ||
public abstract generateFixes(processedLines: Set<number>): vscode.CodeAction[]; | ||
} | ||
|
||
/** | ||
* FixGenerator to be used by default when no FixGenerator exists for a given engine. Does nothing. | ||
* @private Must be exported for testing purposes, but shouldn't be used publicly, hence the leading underscore. | ||
*/ | ||
export class _NoOpFixGenerator extends FixGenerator { | ||
public generateFixes(): vscode.CodeAction[] { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
public generateFixes(processedLines: Set<number>): vscode.CodeAction[] { | ||
return []; | ||
} | ||
} | ||
|
@@ -94,10 +96,16 @@ export class _PmdFixGenerator extends FixGenerator { | |
* Generate an array of fixes, if possible. | ||
* @returns | ||
*/ | ||
public generateFixes(): vscode.CodeAction[] { | ||
public generateFixes(processedLines: Set<number>): vscode.CodeAction[] { | ||
const fixes: vscode.CodeAction[] = []; | ||
if (this.documentSupportsLineLevelSuppression()) { | ||
fixes.push(this.generateLineLevelSuppression()); | ||
// We only check for the start line and not the entire range because irrespective of the range of a specific violation, | ||
// we add the NOPMD tag only on the first line of the violation. | ||
const lineNumber = this.diagnostic.range.start.line; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main change. Even if we have multiple violations on a single line, we show only one "suppress violation" and that would add the "// NOPMD" tag. |
||
if (!processedLines.has(lineNumber)) { | ||
fixes.push(this.generateLineLevelSuppression()); | ||
processedLines.add(lineNumber); | ||
} | ||
} | ||
return fixes; | ||
} | ||
|
@@ -127,9 +135,9 @@ export class _PmdFixGenerator extends FixGenerator { | |
action.edit.insert(this.document.uri, endOfLine, " // NOPMD"); | ||
action.diagnostics = [this.diagnostic]; | ||
action.command = { | ||
command: Constants.COMMAND_REMOVE_SINGLE_DIAGNOSTIC, | ||
command: Constants.COMMAND_DIAGNOSTICS_IN_RANGE, | ||
title: 'Clear Single Diagnostic', | ||
arguments: [this.document.uri, this.diagnostic] | ||
arguments: [this.document.uri, this.diagnostic.range] | ||
}; | ||
return action; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For a better user experience, we should remove all diagnostics on a given line (or even a set of lines). That's because "// NOPMD" is generic and not specific to a rule. So, a line could have both apexdoc and unused var error and both should go away with the "// NOPMD" tag. This wasn't specifically called out in the acceptance criteria or anywhere else, but I think this is the right thing to do.