-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorTreeDataProvider.js
More file actions
94 lines (81 loc) · 3.15 KB
/
ErrorTreeDataProvider.js
File metadata and controls
94 lines (81 loc) · 3.15 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
import * as vscode from 'vscode';
export class ErrorTreeDataProvider {
_onDidChangeTreeData = new vscode.EventEmitter();
onDidChangeTreeData = this._onDidChangeTreeData.event;
constructor() {
this.errors = [];
}
refresh(errors = []) {
this.errors = errors;
this._onDidChangeTreeData.fire(undefined);
}
getTreeItem(element) {
return element;
}
getChildren(element) {
if (!element) {
return this.errors.map(errorInfo => {
const item = new vscode.TreeItem(
errorInfo.diagnostic.message,
vscode.TreeItemCollapsibleState.Collapsed
);
item.description = `L${errorInfo.diagnostic.range.start.line + 1}`;
item.tooltip = "Expand to get an AI solution";
item.errorInfo = errorInfo;
return item;
});
}
const errorInfo = element.errorInfo;
const children = [];
if (errorInfo.solution) {
// Show one TreeItem that opens Webview for formatted solution
const solutionItem = new vscode.TreeItem(
"🤖 Click to see Explanation",
vscode.TreeItemCollapsibleState.None
);
solutionItem.command = {
command: 'ai-error-helper.showSolutionWebview',
title: 'Show AI Solution',
arguments: [errorInfo.solution]
};
solutionItem.tooltip = "Click to directly listen to the explanation";
children.push(solutionItem);
// 🔊 Add Voice Explanation option
const voiceItem = new vscode.TreeItem(
"🔊 Voice Explanation",
vscode.TreeItemCollapsibleState.None
);
voiceItem.command = {
command: 'ai-error-helper.playVoiceExplanation',
title: 'Play Voice Explanation',
arguments: [errorInfo.solution]
};
voiceItem.tooltip = "Click to listen Explanation";
children.push(voiceItem);
} else {
const getSolutionItem = new vscode.TreeItem(
"🤖 Get Error Explanation",
vscode.TreeItemCollapsibleState.None
);
getSolutionItem.command = {
command: 'ai-error-helper.getExplanation',
title: 'Get AI Explanation',
arguments: [errorInfo]
};
getSolutionItem.tooltip = "Click to get Error Explanation.";
children.push(getSolutionItem);
const voiceItem = new vscode.TreeItem(
"🔊 Voice Explanation",
vscode.TreeItemCollapsibleState.None
);
voiceItem.command = {
command: 'ai-error-helper.playVoiceExplanation',
title: 'Play Voice Explanation',
arguments: [errorInfo] // still pass errorInfo, can fetch + speak
};
voiceItem.tooltip = "Click to directly listen to the explanation";
children.push(voiceItem);
}
return children;
}
}