mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Fix remaining tslint suggestions
This commit is contained in:
parent
4d62cfccbb
commit
62b1b05a0d
15 changed files with 82 additions and 78 deletions
|
@ -9,17 +9,42 @@ export interface Decoration {
|
|||
}
|
||||
|
||||
export class Highlighter {
|
||||
private decorations: { [index: string]: vscode.TextEditorDecorationType };
|
||||
constructor() {
|
||||
this.decorations = {};
|
||||
private static initDecorations(): Map<string, vscode.TextEditorDecorationType> {
|
||||
const decor = (color: string) => vscode.window.createTextEditorDecorationType({ color });
|
||||
|
||||
const decorations: Iterable<[string, vscode.TextEditorDecorationType]> = [
|
||||
['background', decor('#3F3F3F')],
|
||||
['error', vscode.window.createTextEditorDecorationType({
|
||||
borderColor: 'red',
|
||||
borderStyle: 'none none dashed none',
|
||||
})],
|
||||
['comment', decor('#7F9F7F')],
|
||||
['string', decor('#CC9393')],
|
||||
['keyword', decor('#F0DFAF')],
|
||||
['function', decor('#93E0E3')],
|
||||
['parameter', decor('#94BFF3')],
|
||||
['builtin', decor('#DD6718')],
|
||||
['text', decor('#DCDCCC')],
|
||||
['attribute', decor('#BFEBBF')],
|
||||
['literal', decor('#DFAF8F')],
|
||||
];
|
||||
|
||||
return new Map<string, vscode.TextEditorDecorationType>(decorations);
|
||||
}
|
||||
|
||||
private decorations: (Map<string, vscode.TextEditorDecorationType> | null) = null;
|
||||
|
||||
public removeHighlights() {
|
||||
for (const tag in this.decorations) {
|
||||
this.decorations[tag].dispose();
|
||||
if (this.decorations == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.decorations = {};
|
||||
// Decorations are removed when the object is disposed
|
||||
for (const decoration of this.decorations.values()) {
|
||||
decoration.dispose();
|
||||
}
|
||||
|
||||
this.decorations = null;
|
||||
}
|
||||
|
||||
public setHighlights(
|
||||
|
@ -30,18 +55,17 @@ export class Highlighter {
|
|||
//
|
||||
// Note: decoration objects need to be kept around so we can dispose them
|
||||
// if the user disables syntax highlighting
|
||||
if (Object.keys(this.decorations).length === 0) {
|
||||
this.initDecorations();
|
||||
if (this.decorations == null) {
|
||||
this.decorations = Highlighter.initDecorations();
|
||||
}
|
||||
|
||||
const byTag: Map<string, vscode.Range[]> = new Map();
|
||||
for (const tag in this.decorations) {
|
||||
for (const tag of this.decorations.keys()) {
|
||||
byTag.set(tag, []);
|
||||
}
|
||||
|
||||
for (const d of highlights) {
|
||||
if (!byTag.get(d.tag)) {
|
||||
console.log(`unknown tag ${d.tag}`);
|
||||
continue;
|
||||
}
|
||||
byTag.get(d.tag)!.push(
|
||||
|
@ -50,29 +74,9 @@ export class Highlighter {
|
|||
}
|
||||
|
||||
for (const tag of byTag.keys()) {
|
||||
const dec: vscode.TextEditorDecorationType = this.decorations[tag];
|
||||
const dec = this.decorations.get(tag) as vscode.TextEditorDecorationType;
|
||||
const ranges = byTag.get(tag)!;
|
||||
editor.setDecorations(dec, ranges);
|
||||
}
|
||||
}
|
||||
|
||||
private initDecorations() {
|
||||
const decor = (obj: any) => vscode.window.createTextEditorDecorationType({ color: obj });
|
||||
this.decorations = {
|
||||
background: decor('#3F3F3F'),
|
||||
error: vscode.window.createTextEditorDecorationType({
|
||||
borderColor: 'red',
|
||||
borderStyle: 'none none dashed none',
|
||||
}),
|
||||
comment: decor('#7F9F7F'),
|
||||
string: decor('#CC9393'),
|
||||
keyword: decor('#F0DFAF'),
|
||||
function: decor('#93E0E3'),
|
||||
parameter: decor('#94BFF3'),
|
||||
builtin: decor('#DD6718'),
|
||||
text: decor('#DCDCCC'),
|
||||
attribute: decor('#BFEBBF'),
|
||||
literal: decor('#DFAF8F'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue