Skip to content
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

Ability to hide Info and Warning Messages as a User Setting #30

Merged
merged 2 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
"type": "boolean",
"default": true,
"description": "Gain insight into the validation process via a popup window in the lower right corner."
},
"webvalidator.showInfo": {
"type": "boolean",
"default": true,
"description": "Set to false to hide info related validation rules (i.e. Trailing slash)"
},
"webvalidator.showWarning": {
"type": "boolean",
"default": true,
"description": "Set to false to hide warning related validation rules"
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/IssueDiagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@ export default class IssueDiagnostic {
this.diagnostic = IssueDiagnostic.getVSCodeDiagnosticFromMessage(message);
this.lineRange = lineRange;
this.lineIntialContent = document.getText(lineRange);
IssueDiagnostic.issueDiagnostics.push(this);
if(!IssueDiagnostic.isHiddenMessage(this.diagnostic)){
IssueDiagnostic.issueDiagnostics.push(this);
}
}

/**
* Decide if a message should be hidden from the user
*/
static isHiddenMessage(diagnostic: vscode.Diagnostic): boolean{
const hideInformationMessage = !vscode.workspace.getConfiguration('webvalidator').showInfo && diagnostic.severity == vscode.DiagnosticSeverity.Information;
const hideWarningMessage = !vscode.workspace.getConfiguration('webvalidator').showWarning && diagnostic.severity == vscode.DiagnosticSeverity.Warning;
return hideInformationMessage || hideWarningMessage;
}


/**
* Clear all the diagnostics on the workspace that are related to the validation
*/
Expand Down Expand Up @@ -79,6 +91,9 @@ export default class IssueDiagnostic {
severity = vscode.DiagnosticSeverity.Error;
break;
case 'info':
severity = vscode.DiagnosticSeverity.Information;
break;
case 'warning':
severity = vscode.DiagnosticSeverity.Warning;
break;
}
Expand Down
62 changes: 57 additions & 5 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,56 @@ suite('Extension Test Suite', () => {
type: 'error'
};

const sampleWarningData: extension.IMessage = {
extract: 'bonsoir',
firstColumn: 10,
hiliteLength: 20,
hiliteStart: 2,
lastColumn: 10,
lastLine: 3,
message: 'Consider adding a lang attribute to the html start tag to declare the language of this document',
type: 'warning'
};

const sampleInfoData: extension.IMessage = {
extract: 'bonsoir',
firstColumn: 10,
hiliteLength: 20,
hiliteStart: 2,
lastColumn: 10,
lastLine: 3,
message: 'Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.',
type: 'info'
};

/**
* Test of getVSCodeDiagnosticFromMessage()
*/
test('getVSCodeDiagnosticFromMessage()', () => {
const diagnostic: vscode.Diagnostic = IssueDiagnostic.getVSCodeDiagnosticFromMessage(sampleData);
assert.strictEqual(diagnostic.message, sampleData.message);
assert.strictEqual(diagnostic.severity, vscode.DiagnosticSeverity.Error);
assert.strictEqual(diagnostic.code, 'W3C_validation');
assert.strictEqual(diagnostic.source, sampleData.type);
test('error type', ()=>{
const diagnostic: vscode.Diagnostic = IssueDiagnostic.getVSCodeDiagnosticFromMessage(sampleData);
assert.strictEqual(diagnostic.message, sampleData.message);
assert.strictEqual(diagnostic.severity, vscode.DiagnosticSeverity.Error);
assert.strictEqual(diagnostic.code, 'W3C_validation');
assert.strictEqual(diagnostic.source, sampleData.type);
});

test('warning type', ()=>{
const diagnostic: vscode.Diagnostic = IssueDiagnostic.getVSCodeDiagnosticFromMessage(sampleWarningData);
assert.strictEqual(diagnostic.message, sampleWarningData.message);
assert.strictEqual(diagnostic.severity, vscode.DiagnosticSeverity.Warning);
assert.strictEqual(diagnostic.code, 'W3C_validation');
assert.strictEqual(diagnostic.source, sampleWarningData.type);
});

test('info type', ()=>{
const diagnostic: vscode.Diagnostic = IssueDiagnostic.getVSCodeDiagnosticFromMessage(sampleInfoData);
assert.strictEqual(diagnostic.message, sampleInfoData.message);
assert.strictEqual(diagnostic.severity, vscode.DiagnosticSeverity.Information);
assert.strictEqual(diagnostic.code, 'W3C_validation');
assert.strictEqual(diagnostic.source, sampleInfoData.type);
});

});

/**
Expand All @@ -85,4 +126,15 @@ suite('Extension Test Suite', () => {
assert.strictEqual(range, undefined);
});




/**
* Test of isHiddenMessage()
*/
// test('isHiddenMessage()', async () => {
// const result = IssueDiagnostic.isHiddenMessage(sampleWarningData.type);
// assert.strictEqual(result, true);
// });
Comment on lines +135 to +138
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should either uncomment or delete this test. :)


});
11 changes: 8 additions & 3 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ const createIssueDiagnosticsList = (requestMessages: IMessage[], document: vscod

let errorCount = 0;
let warningCount = 0;
let infoCount = 0;

//For each request response, we create a new instance of the IssueDiagnostic class
//We also count the warning and error count, ot will then be displayed.
requestMessages.forEach(element => {
if (element.type === 'error')
errorCount++;
else
else if (element.type === 'info')
infoCount++;
else{
warningCount++;

}
new IssueDiagnostic(element, document);
});

Expand All @@ -132,8 +135,10 @@ const createIssueDiagnosticsList = (requestMessages: IMessage[], document: vscod
});

if (showPopup) {
const infoMessage = vscode.workspace.getConfiguration('webvalidator').showInfo ? `, ${infoCount} infos)` : '';
const warningMessage = vscode.workspace.getConfiguration('webvalidator').showWarning ? `, ${warningCount} warnings` : '';
vscode.window.showErrorMessage(
`This ${document.languageId.toUpperCase()} document is not valid. (${errorCount} errors , ${warningCount} warnings)`,
`This ${document.languageId.toUpperCase()} document is not valid. (${errorCount} errors${warningMessage}${infoMessage}`,
...(warningCount > 0 ? ['Clear all', 'Clear warnings'] : ['Clear all'])
).then(selection => {//Ask the user if diagnostics have to be cleared from window
if (selection === 'Clear all') { clearDiagnosticsListAndUpdateWindow(); }
Expand Down