-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
86 lines (69 loc) · 2.59 KB
/
extension.js
File metadata and controls
86 lines (69 loc) · 2.59 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
const vscode = require('vscode');
let decorationType;
function activate(context) {
decorationType = vscode.window.createTextEditorDecorationType({
textDecoration: 'underline',
color: 'yellow',
cursor: 'pointer',
});
console.log('Extension activated!');
// Apply decorations to the current open editor
const editor = vscode.window.activeTextEditor;
if (editor) {
decorateEditor(editor);
}
// Listen for changes in the active editor
const activeEditorChangeListener = vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor && editor.document.fileName.endsWith('.log')) {
decorateEditor(editor);
}
});
// Listen for newly opened documents
const documentOpenListener = vscode.workspace.onDidOpenTextDocument(document => {
if (document.fileName.endsWith('.log')) {
const editor = vscode.window.visibleTextEditors.find(e => e.document === document);
if (editor) {
decorateEditor(editor);
}
}
});
// Register the command
const disposable = vscode.commands.registerCommand('ddpaths.openlink', function () {
console.log('Starting disposable');
vscode.window.showInformationMessage('Hello World from ddpaths!');
});
context.subscriptions.push(disposable, activeEditorChangeListener, documentOpenListener);
}
function decorateEditor(editor) {
if (!editor) return;
const text = editor.document.getText();
const decorations = [];
const timestampRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \b[A-Z]{2,5}\b/;
let lineNumber;
text.split('\n').forEach((line, lineIndex) => {
const number = line.match(/\(([^ ]+)/);
const match2 = String(number).match(/:(\d+)$/);
if (match2) {
lineNumber = match2[1];
}
const match = line.match(/\(([^:]+)/);
if (timestampRegex.test(line) && match) {
const clickableSection = match[0].split(' ')[0].slice(1);
const start = line.indexOf(match[0]);
const range = new vscode.Range(
new vscode.Position(lineIndex, start),
new vscode.Position(lineIndex, start + match[0].length)
);
decorations.push({
range,
hoverMessage: `Go to the repo https://github.com/DataDog/datadog-agent/blob/main/${clickableSection}#L${lineNumber}`,
});
}
});
editor.setDecorations(decorationType, decorations);
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};