-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
105 lines (77 loc) · 4.44 KB
/
extension.js
File metadata and controls
105 lines (77 loc) · 4.44 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
const vscode = require('vscode');
const {codeSuggestion} = require('./utils/codeSuggestion');
const {setCodeSuggestionFlag} = require('./utils/setCodeSuggestionFlag');
const { shareCode, receiveCode, showInformationMessageToAddAPIKey, transformEntireFile, insertAtCursor, fixSelectedCode, fixEntireCode, askUserForAPIKey } = require('./utils/index')
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
vscode.commands.executeCommand('setContext', 'myContext', `value`);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
'codequick',
{
resolveWebviewView: async (webviewView) => {
const extensionUri = context.extensionUri;
console.log("ExtensionUri", extensionUri)
const fileUri = vscode.Uri.joinPath(extensionUri, 'assets', 'chatbot.html');
console.log("File path", fileUri)
const fileContent = await vscode.workspace.fs.readFile(fileUri);
const configuration = vscode.workspace.getConfiguration('code-quick');
const apiKey = configuration.get('apiKey');
const placeholder = 'Bearer xxxxxxxx';
const index = fileContent.indexOf(placeholder);
let htmlContent = fileContent.toString();
if (index !== -1) {
const apiKeyScript = `Bearer ${apiKey}`;
htmlContent = htmlContent.slice(0, index) + apiKeyScript + htmlContent.slice(index + placeholder.length);
} else {
htmlContent += `<script>const apiKey = '${apiKey}';</script>`;
}
webviewView.webview.options = {
enableScripts: true,
localResourceRoots: [extensionUri]
};
webviewView.webview.html = htmlContent;
}
}
)
);
let statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBar.text = "</>";
statusBar.tooltip = "Code Quick : Code Suggestion"
statusBar.command = 'code-quick.SetCodeSuggestionFlag';
statusBar.show();
let configuration = vscode.workspace.getConfiguration('code-quick');
let apiKey = configuration.get('apiKey');
if (apiKey === undefined || apiKey === "") {
vscode.commands.executeCommand('code-quick.ShowInformationMessageToAddAPIKey');
}
let CodeSuggestion = codeSuggestion();
let SetCodeSuggestionFlag = vscode.commands.registerCommand('code-quick.SetCodeSuggestionFlag', setCodeSuggestionFlag);
let AskUserForAPIKey = vscode.commands.registerCommand('code-quick.AskUserForAPIKey', askUserForAPIKey);
let ShowInformationMessageToAddAPIKey = vscode.commands.registerCommand('code-quick.ShowInformationMessageToAddAPIKey', showInformationMessageToAddAPIKey);
let TransformEntireFile = vscode.commands.registerCommand('code-quick.TransformEntireFile', transformEntireFile);
let InsertAtCursor = vscode.commands.registerCommand('code-quick.InsertAtCursor', insertAtCursor);
let FixSelectedCode = vscode.commands.registerCommand('code-quick.FixSelectedCode', fixSelectedCode);
let FixEntireCode = vscode.commands.registerCommand('code-quick.FixEntireCode', fixEntireCode);
let ShareCode = vscode.commands.registerCommand('code-quick.ShareCode', shareCode);
let ReceiveCode = vscode.commands.registerCommand('code-quick.ReceiveCode', receiveCode);
// context.subscriptions.push(...[TransformEntireFile, AskUserForAPIKey, ReceiveCode, ShareCode, InsertAtCursor, ShowInformationMessageToAddAPIKey, FixEntireCode, FixSelectedCode, CodeSuggestion, SetCodeSuggestionFlag]);
context.subscriptions.push(TransformEntireFile);
context.subscriptions.push(AskUserForAPIKey);
context.subscriptions.push(ReceiveCode);
context.subscriptions.push(ShareCode);
context.subscriptions.push(InsertAtCursor);
context.subscriptions.push(ShowInformationMessageToAddAPIKey);
context.subscriptions.push(FixEntireCode);
context.subscriptions.push(FixSelectedCode);
// context.subscriptions.push(CodeSuggestion);
context.subscriptions.push(SetCodeSuggestionFlag);
}
// This method is called when your extension is deactivated
function deactivate() { }
module.exports = {
activate,
deactivate
}