-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
79 lines (68 loc) · 2.11 KB
/
extension.js
File metadata and controls
79 lines (68 loc) · 2.11 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
const vscode = require("vscode");
const { SuggestionController } = require("./src/SuggestionController");
const {
AutoClosingBracketsManager,
} = require("./src/AutoClosingBracketsManager");
let controller;
let bracketsManager;
function activate(context) {
console.log("FaultyAI extension activated!");
controller = new SuggestionController();
bracketsManager = new AutoClosingBracketsManager();
// Programmatically set workspace and Java-language auto-closing brackets to "never".
// Do NOT push the returned Promise into context.subscriptions (it's not a Disposable).
bracketsManager.applyWorkspaceSettings();
// Hover provider for showing full suggestion
context.subscriptions.push(
vscode.languages.registerHoverProvider(
{ scheme: "file", language: "java" },
{
provideHover(document, position) {
if (!controller.pendingSuggestion) return;
const lineNumber = position.line;
if (lineNumber === controller.pendingSuggestion.line) {
return new vscode.Hover(
`**FaultyAI Suggestion** (Press Tab to accept)\n\`\`\`java\n${controller.pendingSuggestion.text}\n\`\`\``,
);
}
},
},
),
);
// Text change listener
context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument((event) =>
controller.handleTextChange(event),
),
);
// Editor focus change
context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor((newEditor) => {
if (!newEditor) {
controller.removeSuggestion(vscode.window.activeTextEditor);
}
}),
);
// Accept suggestion command
context.subscriptions.push(
vscode.commands.registerCommand("faultyai.acceptSuggestion", () => {
const editor = vscode.window.activeTextEditor;
if (editor) {
controller.acceptSuggestion(editor);
}
}),
);
}
function deactivate() {
if (controller) {
controller.removeSuggestion(vscode.window.activeTextEditor);
}
if (bracketsManager) {
bracketsManager.restoreWorkspaceSettings();
}
}
//hello!
module.exports = {
activate,
deactivate,
};