* The current projects source code index.
| 47 | * The current projects source code index. |
| 48 | */ |
| 49 | class CodeIndex { |
| 50 | /** |
| 51 | * Creates a new 'CodeIndex' instance. |
| 52 | * @param folderPath Optional. The path to the folder containing the index. Defaults to '.codepilot'. |
| 53 | */ |
| 54 | constructor(folderPath = '.codepilot') { |
| 55 | this._folderPath = folderPath; |
| 56 | } |
| 57 | /** |
| 58 | * Gets the current code index configuration. |
| 59 | */ |
| 60 | get config() { |
| 61 | return this._config; |
| 62 | } |
| 63 | /** |
| 64 | * Gets the path to the folder containing the index. |
| 65 | */ |
| 66 | get folderPath() { |
| 67 | return this._folderPath; |
| 68 | } |
| 69 | /** |
| 70 | * Gets the current OpenAI keys. |
| 71 | */ |
| 72 | get keys() { |
| 73 | return this._keys; |
| 74 | } |
| 75 | // LLM-REGION |
| 76 | /** |
| 77 | * Adds sources and extensions to the index. |
| 78 | * @param config The configuration containing the sources and extensions to add. |
| 79 | */ |
| 80 | add(config) { |
| 81 | return __awaiter(this, void 0, void 0, function* () { |
| 82 | if (!(yield this.isCreated())) { |
| 83 | throw new Error('Index has not been created yet. Please run `codepilot create` first.'); |
| 84 | } |
| 85 | // Ensure config loaded |
| 86 | const configPath = path.join(this.folderPath, 'config.json'); |
| 87 | if (!this._config) { |
| 88 | this._config = JSON.parse(yield fs.readFile(configPath, 'utf-8')); |
| 89 | } |
| 90 | // Clone config |
| 91 | const newConfig = Object.assign({}, this._config); |
| 92 | // Add sources |
| 93 | if (Array.isArray(config.sources)) { |
| 94 | config.sources.forEach(source => { |
| 95 | if (!newConfig.sources.includes(source)) { |
| 96 | newConfig.sources.push(source); |
| 97 | } |
| 98 | }); |
| 99 | } |
| 100 | // Add extensions |
| 101 | if (Array.isArray(config.extensions)) { |
| 102 | if (!newConfig.extensions) { |
| 103 | newConfig.extensions = []; |
| 104 | } |
| 105 | config.extensions.forEach(extension => { |
| 106 | if (!newConfig.extensions.includes(extension)) { |
nothing calls this directly
no outgoing calls
no test coverage detected