-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.js
More file actions
210 lines (210 loc) · 7.23 KB
/
Copy pathdecorator.js
File metadata and controls
210 lines (210 loc) · 7.23 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"use strict";
// ## Decorator Module
// Creates and applies VS Code text decorations for each comment type.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommentDecorator = void 0;
const vscode = __importStar(require("vscode"));
const THEMES = {
dark: {
h1: '#cba6f7', h2: '#89dceb', h3: '#89b4fa',
bold: '#f5c2e7', para: '#bac2de',
noteBg: '#0d2137', noteFg: '#74c7ec',
warnBg: '#2d1e00', warnFg: '#f9e2af',
dangerBg: '#2d0000', dangerFg: '#f38ba8',
todo: '#fab387', done: '#a6e3a1',
depr: '#585b70', divider: '#45475a',
param: '#94e2d5', returns: '#a6e3a1',
},
minimal: {
h1: '#e0e0e0', h2: '#bbbbbb', h3: '#999999',
bold: '#dddddd', para: '#aaaaaa',
noteBg: '#111a11', noteFg: '#88bb88',
warnBg: '#1a1500', warnFg: '#ccaa55',
dangerBg: '#1a0000', dangerFg: '#cc6666',
todo: '#aaaaaa', done: '#777777',
depr: '#555555', divider: '#444444',
param: '#888888', returns: '#888888',
},
vibrant: {
h1: '#ff79c6', h2: '#8be9fd', h3: '#bd93f9',
bold: '#ff6e6e', para: '#f8f8f2',
noteBg: '#003366', noteFg: '#8be9fd',
warnBg: '#4d3000', warnFg: '#ffb86c',
dangerBg: '#5d0000', dangerFg: '#ff5555',
todo: '#ffb86c', done: '#50fa7b',
depr: '#6272a4', divider: '#6272a4',
param: '#50fa7b', returns: '#8be9fd',
},
};
// --- Decoration Type Factory ---
class CommentDecorator {
constructor(theme) {
this.decorations = new Map();
this.theme = theme;
this.buildDecorationTypes();
}
// Merges theme defaults with any per-tag user overrides from settings
colors() {
const base = THEMES[this.theme] ?? THEMES.dark;
const cfg = vscode.workspace.getConfiguration('commentstyle.colors');
const overrides = {};
for (const key of Object.keys(base)) {
const val = cfg.get(key);
if (val)
overrides[key] = val;
}
return { ...base, ...overrides };
}
buildDecorationTypes() {
this.disposeAll();
const c = this.colors();
const reg = (type, opts) => this.decorations.set(type, vscode.window.createTextEditorDecorationType(opts));
reg('h1', {
color: c.h1,
fontWeight: 'bold',
fontSize: '1.35em',
borderBottom: `1px solid ${c.h1}44`,
after: { contentText: '', borderBottom: `1px solid ${c.h1}` },
});
reg('h2', {
color: c.h2,
fontWeight: 'bold',
fontSize: '1.15em',
});
reg('h3', {
color: c.h3,
fontWeight: '600',
fontStyle: 'normal',
});
reg('bold', {
color: c.bold,
fontWeight: 'bold',
});
reg('paragraph_start', {
color: c.para,
fontStyle: 'italic',
borderLeft: `3px solid ${c.divider}`,
marginLeft: '4px',
});
reg('paragraph_mid', {
color: c.para,
fontStyle: 'italic',
borderLeft: `3px solid ${c.divider}`,
});
reg('paragraph_end', {
color: c.para,
fontStyle: 'italic',
borderLeft: `3px solid ${c.divider}`,
});
reg('note', {
backgroundColor: c.noteBg,
color: c.noteFg,
borderLeft: `3px solid ${c.noteFg}`,
before: { contentText: 'ℹ ', color: c.noteFg },
});
reg('warning', {
backgroundColor: c.warnBg,
color: c.warnFg,
fontWeight: 'bold',
before: { contentText: '⚠ ', color: c.warnFg },
});
reg('danger', {
backgroundColor: c.dangerBg,
color: c.dangerFg,
fontWeight: 'bold',
before: { contentText: '🔴 ', color: c.dangerFg },
});
reg('todo', {
color: c.todo,
before: { contentText: '☐ ', color: c.todo },
});
reg('done', {
color: c.done,
textDecoration: 'line-through',
before: { contentText: '✓ ', color: c.done },
});
reg('deprecated', {
color: c.depr,
textDecoration: 'line-through',
});
reg('divider', {
color: c.divider,
borderTop: `1px dashed ${c.divider}`,
fontStyle: 'italic',
});
reg('param', {
color: c.param,
before: { contentText: '↳ param ', color: c.divider, fontStyle: 'italic' },
});
reg('returns', {
color: c.returns,
before: { contentText: '↩ returns ', color: c.divider, fontStyle: 'italic' },
});
}
// @param editor vscode.TextEditor
// @param parsedLines ParsedLine[]
applyDecorations(editor, parsedLines) {
// Group lines by type
const groups = new Map();
for (const pl of parsedLines) {
if (!groups.has(pl.type))
groups.set(pl.type, []);
const lineLen = editor.document.lineAt(pl.line).text.length;
groups.get(pl.type).push(new vscode.Range(pl.line, 0, pl.line, lineLen));
}
// Apply each decoration type
for (const [type, decType] of this.decorations) {
editor.setDecorations(decType, groups.get(type) ?? []);
}
}
clearDecorations(editor) {
for (const decType of this.decorations.values()) {
editor.setDecorations(decType, []);
}
}
// @param theme string - 'dark' | 'minimal' | 'vibrant'
updateTheme(theme) {
this.theme = theme;
this.buildDecorationTypes();
}
disposeAll() {
for (const d of this.decorations.values())
d.dispose();
this.decorations.clear();
}
}
exports.CommentDecorator = CommentDecorator;
//# sourceMappingURL=decorator.js.map