Repository navigation
Expand file tree
/
Copy pathdemo_ai_completion.cpp
More file actions
188 lines (151 loc) · 7.2 KB
/
Copy pathdemo_ai_completion.cpp
File metadata and controls
188 lines (151 loc) · 7.2 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
#include <iomanip>
#include <iostream>
#include "bolt/ai/ai_completion_provider.hpp"
#include "bolt/editor/integrated_editor.hpp"
using namespace bolt; // NOLINT(build/namespaces)
void demonstrateAICompletion() {
std::cout << "=== AI Code Completion Integration Demo ===\n\n";
// Get the integrated editor instance
IntegratedEditor& editor = IntegratedEditor::getInstance();
std::cout << "1. Checking AI Completion Status:\n";
std::cout << " AI Completion Ready: " << (editor.isAICompletionReady() ? "YES" : "NO") << "\n";
std::cout << " AI Completion Enabled: " << (editor.isAICompletionEnabled() ? "YES" : "NO") << "\n";
std::cout << " Code Completion Active: " << (editor.isCodeCompletionActive() ? "YES" : "NO") << "\n\n";
// Create a test C++ file
std::cout << "2. Opening test C++ file with content:\n";
std::string testFilePath = "demo.cpp";
// clang-format off
std::string testContent = R"(#include <iostream>
#include <vector>
#include <string>
int main() {
std::
return 0;
})";
// clang-format on
std::cout << " File: " << testFilePath << "\n";
std::cout << " Content:\n";
std::cout << testContent << "\n\n";
editor.openDocument(testFilePath, testContent);
// Test AI completions for std::
std::cout << "3. Getting AI completions for 'std::':\n";
auto completions = editor.getAICompletions(testFilePath, "std::", 5);
if (!completions.empty()) {
std::cout << " Found " << completions.size() << " completions:\n";
for (size_t i = 0; i < completions.size(); ++i) {
std::cout << " " << (i + 1) << ". " << std::left << std::setw(15) << completions[i].label << " ("
<< completions[i].kind << ", score: " << completions[i].score << ")\n";
if (!completions[i].detail.empty()) {
std::cout << " " << completions[i].detail << "\n";
}
}
} else {
std::cout << " No completions found.\n";
}
std::cout << "\n";
// Test triggering completion
std::cout << "4. Triggering code completion:\n";
editor.triggerCodeCompletion(testFilePath, "std::");
std::cout << " Code Completion Active: " << (editor.isCodeCompletionActive() ? "YES" : "NO") << "\n";
if (editor.isCodeCompletionActive()) {
auto selected = editor.getSelectedCompletion();
std::cout << " Selected: " << selected.label << "\n";
std::cout << " Testing navigation...\n";
editor.selectNextCompletion();
selected = editor.getSelectedCompletion();
std::cout << " After next: " << selected.label << "\n";
editor.selectPreviousCompletion();
selected = editor.getSelectedCompletion();
std::cout << " After previous: " << selected.label << "\n";
}
std::cout << "\n";
// Test different prefixes
std::cout << "5. Testing different completion contexts:\n";
// Test for 'class' keyword
auto classCompletions = editor.getAICompletions(testFilePath, "class", 3);
std::cout << " 'class' prefix: " << classCompletions.size() << " completions\n";
for (const auto& comp : classCompletions) {
std::cout << " " << comp.label << "\n";
}
// Test for 'for' keyword
auto forCompletions = editor.getAICompletions(testFilePath, "for", 3);
std::cout << " 'for' prefix: " << forCompletions.size() << " completions\n";
for (const auto& comp : forCompletions) {
std::cout << " " << comp.label << "\n";
}
std::cout << "\n";
// Test AI enable/disable
std::cout << "6. Testing AI enable/disable:\n";
editor.setAICompletionEnabled(false);
std::cout << " AI Disabled - Completions for 'std::': "
<< editor.getAICompletions(testFilePath, "std::", 3).size() << "\n";
editor.setAICompletionEnabled(true);
std::cout << " AI Re-enabled - Completions for 'std::': "
<< editor.getAICompletions(testFilePath, "std::", 3).size() << "\n";
std::cout << "\n";
// Clean up
if (editor.isCodeCompletionActive()) {
editor.cancelCompletion();
}
std::cout << "7. Final state:\n";
std::cout << " Code Completion Active: " << (editor.isCodeCompletionActive() ? "YES" : "NO") << "\n";
std::cout << " AI Completion Enabled: " << (editor.isAICompletionEnabled() ? "YES" : "NO") << "\n";
std::cout << "\n=== Demo Complete ===\n";
}
void demonstrateAIProviderDirectly() {
std::cout << "\n=== Direct AI Provider Demo ===\n\n";
// Test the AI provider directly
MockAICompletionProvider provider;
std::cout << "1. Initializing AI Provider:\n";
std::cout << " Ready before init: " << (provider.isReady() ? "YES" : "NO") << "\n";
provider.initialize();
std::cout << " Ready after init: " << (provider.isReady() ? "YES" : "NO") << "\n\n";
// Test C++ context
std::cout << "2. Testing C++ completion context:\n";
CodeContext cppContext;
cppContext.filePath = "test.cpp";
cppContext.content = "int main() {\n std::\n return 0;\n}";
cppContext.cursorPosition = 20;
cppContext.line = 1;
cppContext.column = 9;
cppContext.language = "cpp";
auto completions = provider.generateCompletions(cppContext, "std::", 5);
std::cout << " Generated " << completions.size() << " completions for 'std::':\n";
for (const auto& comp : completions) {
std::cout << " " << comp.label << " (" << comp.kind << ")\n";
}
std::cout << "\n";
// Test different context
std::cout << "3. Testing different contexts:\n";
cppContext.content = "class MyClass {\n \n};";
cppContext.cursorPosition = 16;
completions = provider.generateCompletions(cppContext, "for", 3);
std::cout << " 'for' in class context: " << completions.size() << " completions\n";
completions = provider.generateCompletions(cppContext, "", 3);
std::cout << " Empty prefix: " << completions.size() << " completions\n";
provider.shutdown();
std::cout << " Ready after shutdown: " << (provider.isReady() ? "YES" : "NO") << "\n";
std::cout << "\n=== AI Provider Demo Complete ===\n";
}
int main() {
std::cout << "Bolt C++ AI Code Completion Integration Demo\n";
std::cout << "============================================\n\n";
try {
demonstrateAICompletion();
demonstrateAIProviderDirectly();
std::cout << "\n✅ All demonstrations completed successfully!\n";
std::cout << "\nAI Code Completion has been successfully integrated with the editor.\n";
std::cout << "Features available:\n";
std::cout << " - AI-powered code completions with context awareness\n";
std::cout << " - Language-specific suggestions (C++, Python, JavaScript)\n";
std::cout << " - Keyboard shortcuts (Ctrl+Space to trigger)\n";
std::cout << " - Navigation through suggestions (Up/Down arrows)\n";
std::cout << " - Accept (Enter) and Cancel (Escape) operations\n";
std::cout << " - Enable/disable AI completions\n";
std::cout << " - Mock AI provider ready for real AI integration\n";
return 0;
} catch (const std::exception& e) {
std::cerr << "❌ Error during demonstration: " << e.what() << "\n";
return 1;
}
}