MCPcopy Index your code
hub / github.com/Stevenic/codepilot / add

Method add

lib/CodeIndex.js:80–115  ·  view source on GitHub ↗

* Adds sources and extensions to the index. * @param config The configuration containing the sources and extensions to add.

(config)

Source from the content-addressed store, hash-verified

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)) {
107 newConfig.extensions.push(extension);
108 }
109 });
110 }
111 // Write config
112 yield fs.writeFile(configPath, JSON.stringify(newConfig));
113 this._config = newConfig;
114 });
115 }
116 // LLM-REGION
117 /**
118 * Creates a new code index.

Callers 1

runFunction · 0.95

Calls 1

isCreatedMethod · 0.95

Tested by

no test coverage detected