-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.html
More file actions
335 lines (306 loc) · 11.4 KB
/
Copy pathexample.html
File metadata and controls
335 lines (306 loc) · 11.4 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monaco Error Lens - Working Example</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 20px;
background: #f8f9fa;
color: #212529;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
margin-bottom: 20px;
}
.editor-container {
height: 600px;
border: 1px solid #dee2e6;
border-radius: 6px;
overflow: hidden;
}
.controls {
margin-top: 15px;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
button {
background: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background: #0056b3;
}
button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.status {
margin-top: 10px;
padding: 10px;
background: #e9ecef;
border-radius: 4px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
color: #495057;
}
.info {
margin-bottom: 15px;
padding: 10px;
background: #d4edda;
border-left: 4px solid #28a745;
border-radius: 4px;
}
.success {
color: #155724;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔍 Monaco Error Lens - Working Example</h1>
<div class="info">
<span class="success">✅ Using Real Package:</span> This example uses the actual built Monaco Error Lens package from <code>./dist/index.js</code>
</div>
</div>
<div class="editor-container" id="editor-container"></div>
<div class="controls">
<button onclick="addErrors()">Add Sample Errors</button>
<button onclick="addWarnings()">Add Warnings</button>
<button onclick="addMixed()">Add Mixed Diagnostics</button>
<button onclick="clearMarkers()">Clear All</button>
<button onclick="toggleErrorLens()">Toggle Error Lens</button>
<button onclick="toggleTheme()">Toggle Theme</button>
<button onclick="testOptions()">Test Configuration</button>
</div>
<div class="status" id="status">
Ready - Click "Add Sample Errors" to see Error Lens in action!
</div>
</div>
<!-- Monaco Editor -->
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.44.0/min/vs/loader.js"></script>
<script type="module">
// Import the actual Monaco Error Lens package
import { MonacoErrorLens, setupErrorLens } from './dist/index.js';
let editor, errorLens;
let isDarkTheme = false;
// Load Monaco Editor
require.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.44.0/min/vs' } });
require(['vs/editor/editor.main'], function () {
initializeEditor();
});
function initializeEditor() {
// Sample TypeScript code with intentional issues
const sampleCode = `// Sample TypeScript code with various issues
function calculateTotal(items: any[]) {
let total = 0;
for (const item of items) {
if (item.price) {
total += item.price; // Missing type safety
}
}
return total; // Missing semicolon in some configs
}
const items = [
{ name: "Item 1", price: 10 },
{ name: "Item 2", price: undefined }, // Potential issue
{ name: "Item 3" } // Missing price property
];
const result = calculateTotal(items);
console.log("Total:", result);
// Unused variable
const unusedVar = "This variable is never used";
// Function with any type
function processData(data: any) {
return data.someProperty; // Unsafe property access
}`;
// Create Monaco Editor
editor = monaco.editor.create(document.getElementById('editor-container'), {
value: sampleCode,
language: 'typescript',
theme: 'vs',
glyphMargin: true, // Enable gutter icons
lineNumbers: 'on',
automaticLayout: true,
minimap: { enabled: false },
fontSize: 14,
lineHeight: 20,
});
// Initialize Error Lens using the real package
errorLens = setupErrorLens(editor, monaco, {
enableInlineMessages: true,
enableLineHighlights: true,
enableGutterIcons: true,
followCursor: 'allLines',
messageTemplate: '💬 {message}',
maxMessageLength: 100,
updateDelay: 150
});
updateStatus('Monaco Editor loaded with real Monaco Error Lens package!');
// Expose to global scope for button handlers
window.errorLens = errorLens;
window.monaco = monaco;
window.updateStatus = updateStatus;
}
function updateStatus(message) {
const status = document.getElementById('status');
const timestamp = new Date().toLocaleTimeString();
status.textContent = `[${timestamp}] ${message}`;
}
// Expose utility functions to global scope for buttons
window.addErrors = function() {
const markers = [
{
startLineNumber: 6,
startColumn: 13,
endLineNumber: 6,
endColumn: 28,
message: "Unsafe assignment to 'total'. Variable 'item.price' could be undefined.",
severity: monaco.MarkerSeverity.Error,
source: 'typescript'
},
{
startLineNumber: 21,
startColumn: 5,
endLineNumber: 21,
endColumn: 24,
message: "Variable 'unusedVar' is declared but never used.",
severity: monaco.MarkerSeverity.Error,
source: 'eslint'
},
{
startLineNumber: 24,
startColumn: 21,
endLineNumber: 24,
endColumn: 32,
message: "Parameter 'data' implicitly has an 'any' type.",
severity: monaco.MarkerSeverity.Error,
source: 'typescript'
}
];
monaco.editor.setModelMarkers(editor.getModel(), 'demo', markers);
updateStatus(`Added ${markers.length} error markers using real Error Lens`);
};
window.addWarnings = function() {
const markers = [
{
startLineNumber: 2,
startColumn: 31,
endLineNumber: 2,
endColumn: 36,
message: "Parameter should be typed more specifically than 'any[]'.",
severity: monaco.MarkerSeverity.Warning,
source: 'eslint'
},
{
startLineNumber: 16,
startColumn: 28,
endLineNumber: 16,
endColumn: 37,
message: "Property 'price' is undefined for this item.",
severity: monaco.MarkerSeverity.Warning,
source: 'typescript'
},
{
startLineNumber: 25,
startColumn: 17,
endLineNumber: 25,
endColumn: 29,
message: "Property 'someProperty' does not exist on type 'any'.",
severity: monaco.MarkerSeverity.Warning,
source: 'typescript'
}
];
monaco.editor.setModelMarkers(editor.getModel(), 'demo', markers);
updateStatus(`Added ${markers.length} warning markers`);
};
window.addMixed = function() {
const markers = [
{
startLineNumber: 2,
startColumn: 31,
endLineNumber: 2,
endColumn: 36,
message: "Consider using a more specific type than 'any[]'",
severity: monaco.MarkerSeverity.Info,
source: 'suggestion'
},
{
startLineNumber: 6,
startColumn: 13,
endLineNumber: 6,
endColumn: 28,
message: "Potential null pointer exception",
severity: monaco.MarkerSeverity.Error,
source: 'static-analysis'
},
{
startLineNumber: 9,
startColumn: 5,
endLineNumber: 9,
endColumn: 11,
message: "Missing semicolon",
severity: monaco.MarkerSeverity.Warning,
source: 'eslint'
},
{
startLineNumber: 12,
startColumn: 1,
endLineNumber: 12,
endColumn: 2,
message: "Add a blank line before this statement",
severity: monaco.MarkerSeverity.Hint,
source: 'style'
},
{
startLineNumber: 21,
startColumn: 7,
endLineNumber: 21,
endColumn: 16,
message: "Variable is declared but never used",
severity: monaco.MarkerSeverity.Warning,
source: 'eslint'
}
];
monaco.editor.setModelMarkers(editor.getModel(), 'demo', markers);
updateStatus(`Added ${markers.length} mixed severity markers`);
};
window.clearMarkers = function() {
monaco.editor.setModelMarkers(editor.getModel(), 'demo', []);
updateStatus('Cleared all markers');
};
window.toggleErrorLens = function() {
const enabled = errorLens.toggle();
updateStatus(`Error Lens ${enabled ? 'enabled' : 'disabled'}`);
};
window.toggleTheme = function() {
isDarkTheme = !isDarkTheme;
monaco.editor.setTheme(isDarkTheme ? 'vs-dark' : 'vs');
updateStatus(`Switched to ${isDarkTheme ? 'dark' : 'light'} theme`);
};
window.testOptions = function() {
// Test different configuration options
errorLens.updateOptions({
followCursor: 'activeLine',
messageTemplate: '🚨 [{source}] {message}',
maxMessageLength: 80
});
updateStatus('Updated Error Lens configuration - now following cursor only');
};
</script>
</body>
</html>