Skip to content

Commit

Permalink
feature: add bad characters to the problems pane. closes WengerK#2
Browse files Browse the repository at this point in the history
  • Loading branch information
puka committed Oct 7, 2021
1 parent d7c096b commit 5a6cdf3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function loadConfiguration(): {
// this method is called when vs code is activated
export function activate(context: vscode.ExtensionContext) {
let config = loadConfiguration();
const diagnosticCollection = vscode.languages.createDiagnosticCollection(`bad-characters`);
console.log('highlight-bad-chars decorator is activated with configuration', config);

let timeout: NodeJS.Timeout|null = null;
Expand Down Expand Up @@ -77,6 +78,8 @@ export function activate(context: vscode.ExtensionContext) {
const regEx = new RegExp(config.charRegExp, 'g');
const text = activeEditor.document.getText();
const badChars: vscode.DecorationOptions[] = [];
const errors: vscode.Diagnostic[] = [];
const fileUri = activeEditor.document.uri;

let match;
// tslint:disable-next-line:no-conditional-assignment
Expand All @@ -92,7 +95,13 @@ export function activate(context: vscode.ExtensionContext) {
hoverMessage: `Bad char \\u${codePoint} (${match[0]})`,
};
badChars.push(decoration);
errors.push(createDiagnostic(startPos, endPos));
}
activeEditor.setDecorations(config.badCharDecorationType, badChars);
diagnosticCollection.set(fileUri, errors);
}

function createDiagnostic(start: vscode.Position, end: vscode.Position) {
return new vscode.Diagnostic(new vscode.Range(start, end), `Found an incorrect character`);
}
}

0 comments on commit 5a6cdf3

Please sign in to comment.