-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
49 lines (44 loc) · 2.14 KB
/
extension.ts
File metadata and controls
49 lines (44 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Author: Nikolay Dvurechensky
* Site: https://dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 21 апреля 2026 07:09:21
* Version: 1.0.245
*/
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.languages.registerColorProvider(
{ scheme: 'file', language: '*' },
{
provideDocumentColors(document: vscode.TextDocument) {
const colors: vscode.ColorInformation[] = [];
const regex = /color\s*=\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})/g;
for (let i = 0; i < document.lineCount; i++) {
const line = document.lineAt(i);
const match = regex.exec(line.text);
if (match) {
const r = Number(match[1]) / 255;
const g = Number(match[2]) / 255;
const b = Number(match[3]) / 255;
const startPos = line.range.start.translate(0, match.index);
const endPos = startPos.translate(0, match[0].length);
const range = new vscode.Range(startPos, endPos);
const color = new vscode.Color(r, g, b, 1);
colors.push(new vscode.ColorInformation(range, color));
}
}
return colors;
},
provideColorPresentations(color: vscode.Color, context: { document: vscode.TextDocument; range: vscode.Range }) {
// Преобразуем цвет обратно в "color = R, G, B"
const r = Math.round(color.red * 255);
const g = Math.round(color.green * 255);
const b = Math.round(color.blue * 255);
const label = `color = ${r}, ${g}, ${b}`;
return [new vscode.ColorPresentation(label)];
}
}
)
);
}