Skip to content

Commit 6044c6a

Browse files
Olasunkanmi OyinlolaOlasunkanmi Oyinlola
authored andcommitted
refactor(core): Remove file watcher service and related events
1 parent 101fb21 commit 6044c6a

File tree

5 files changed

+202
-213
lines changed

5 files changed

+202
-213
lines changed

src/emitter/interface.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ type AgentEventKeys =
1616
| "onModelChangeSuccess"
1717
| "onHistoryUpdated"
1818
| "onConfigurationChange"
19-
| "onFileCreated"
2019
| "onTextChange"
21-
| "OnSaveText"
22-
| "onFileRenamed"
23-
| "onFileDeleted"
2420
| "onUserPrompt"
2521
| "onClearHistory"
2622
| "onOptimizing"

src/extension.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { EventEmitter } from "./emitter/publisher";
2222
import { Logger, LogLevel } from "./infrastructure/logger/logger";
2323
import { Memory } from "./memory/base";
2424
import { FileUploadService } from "./services/file-upload";
25-
import { FileWatcherService } from "./services/file-watcher";
2625
import { getAPIKeyAndModel, getConfigValue } from "./utils/utils";
2726
import { AnthropicWebViewProvider } from "./webview-providers/anthropic";
2827
import { CodeActionsProvider } from "./webview-providers/code-actions";
@@ -52,7 +51,6 @@ const {
5251
console.log(APP_CONFIG);
5352

5453
const logger = Logger.initialize("extension", { minLevel: LogLevel.DEBUG });
55-
const fileWatcher = FileWatcherService.getInstance();
5654

5755
let quickFixCodeAction: vscode.Disposable;
5856
let agentEventEmmitter: EventEmitter;
@@ -311,9 +309,6 @@ async function restartExtension(context: vscode.ExtensionContext) {
311309
if (orchestrator) {
312310
orchestrator.dispose();
313311
}
314-
if (fileWatcher) {
315-
fileWatcher.dispose();
316-
}
317312

318313
// Show progress and reload window
319314
await vscode.window.withProgress(
@@ -347,7 +342,6 @@ export function deactivate(context: vscode.ExtensionContext) {
347342
quickFixCodeAction.dispose();
348343
agentEventEmmitter.dispose();
349344
orchestrator.dispose();
350-
fileWatcher.dispose();
351345

352346
// Dispose provider manager
353347
const providerManager = WebViewProviderManager.getInstance(context);

src/services/code-indexing.ts

Lines changed: 123 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,130 @@
1-
import { IFunctionData } from "../application/interfaces";
2-
import { Logger } from "../infrastructure/logger/logger";
3-
import { CodeRepository } from "../infrastructure/repository/code";
4-
import { CodeStructureMapper } from "./code-structure.mapper";
5-
import { EmbeddingService } from "./embedding";
6-
import { TypeScriptAtsMapper } from "./typescript-ats.service";
7-
import { getAPIKeyAndModel } from "../utils/utils";
8-
import { LogLevel } from "./telemetry";
1+
// import { IFunctionData } from "../application/interfaces";
2+
// import { Logger } from "../infrastructure/logger/logger";
3+
// import { CodeRepository } from "../infrastructure/repository/code";
4+
// import { CodeStructureMapper } from "./code-structure.mapper";
5+
// import { EmbeddingService } from "./embedding";
6+
// import { TypeScriptAtsMapper } from "./typescript-ats.service";
7+
// import { getAPIKeyAndModel } from "../utils/utils";
8+
// import { LogLevel } from "./telemetry";
99

10-
/**
11-
* Provides a centralized service for managing code indexing, including building function structure maps,
12-
* generating function descriptions, generating embeddings, and inserting function data into a database.
13-
*/
14-
export class CodeIndexingService {
15-
logger: Logger;
16-
embeddingService: EmbeddingService;
17-
codeRepository: CodeRepository | undefined;
18-
private static instance: CodeIndexingService;
19-
constructor() {
20-
this.logger = Logger.initialize("CodeIndexingService", {
21-
minLevel: LogLevel.DEBUG,
22-
});
23-
const { apiKey, model } = getAPIKeyAndModel("gemini");
24-
this.embeddingService = new EmbeddingService(apiKey);
25-
}
10+
// /**
11+
// * Provides a centralized service for managing code indexing, including building function structure maps,
12+
// * generating function descriptions, generating embeddings, and inserting function data into a database.
13+
// */
14+
// export class CodeIndexingService {
15+
// logger: Logger;
16+
// embeddingService: EmbeddingService;
17+
// codeRepository: CodeRepository | undefined;
18+
// private static instance: CodeIndexingService;
19+
// constructor() {
20+
// this.logger = Logger.initialize("CodeIndexingService", {
21+
// minLevel: LogLevel.DEBUG,
22+
// });
23+
// const { apiKey, model } = getAPIKeyAndModel("gemini");
24+
// this.embeddingService = new EmbeddingService(apiKey);
25+
// }
2626

27-
/**
28-
* Creates a singleton instance of the CodeIndexingService class.
29-
* @returns {CodeIndexingService} The CodeIndexingService instance.
30-
*/
31-
public static createInstance(): CodeIndexingService {
32-
if (!CodeIndexingService.instance) {
33-
CodeIndexingService.instance = new CodeIndexingService();
34-
}
35-
return CodeIndexingService.instance;
36-
}
27+
// /**
28+
// * Creates a singleton instance of the CodeIndexingService class.
29+
// * @returns {CodeIndexingService} The CodeIndexingService instance.
30+
// */
31+
// public static createInstance(): CodeIndexingService {
32+
// if (!CodeIndexingService.instance) {
33+
// CodeIndexingService.instance = new CodeIndexingService();
34+
// }
35+
// return CodeIndexingService.instance;
36+
// }
3737

38-
/**
39-
* Retrieves an instance of the CodeRepository, which is used to interact with the database.
40-
* @returns {Promise<void>} A promise that resolves when the repository is initialized.
41-
*/
42-
async getCodeRepository() {
43-
this.codeRepository = await CodeRepository.getInstance();
44-
}
38+
// /**
39+
// * Retrieves an instance of the CodeRepository, which is used to interact with the database.
40+
// * @returns {Promise<void>} A promise that resolves when the repository is initialized.
41+
// */
42+
// async getCodeRepository() {
43+
// this.codeRepository = await CodeRepository.getInstance();
44+
// }
4545

46-
/**
47-
* Builds a function structure map using the TypeScript ATS mapper and CodeStructureMapper services.
48-
* @returns {Promise<Partial<IFunctionData>[]>} A promise that resolves with an array of function data.
49-
*/
50-
async buildFunctionStructureMap(): Promise<Partial<IFunctionData>[]> {
51-
try {
52-
// TODO Get all the typescript project compilers information
53-
const codeATS = await TypeScriptAtsMapper.getInstance();
54-
if (!codeATS) {
55-
throw new Error("Failed to get TypeScriptAtsMapper instance");
56-
}
57-
const mappedCode = await codeATS.buildCodebaseMap();
58-
if (!mappedCode) {
59-
throw new Error("Failed to build codebase map");
60-
}
61-
const ats = Object.values(mappedCode).flatMap((repo) =>
62-
Object.values(repo.modules),
63-
);
64-
const mapper = new CodeStructureMapper(ats);
65-
return mapper.normalizeData();
66-
} catch (error) {
67-
this.logger.error("Error building function structure map:", error);
68-
throw error;
69-
}
70-
}
46+
// /**
47+
// * Builds a function structure map using the TypeScript ATS mapper and CodeStructureMapper services.
48+
// * @returns {Promise<Partial<IFunctionData>[]>} A promise that resolves with an array of function data.
49+
// */
50+
// async buildFunctionStructureMap(): Promise<Partial<IFunctionData>[]> {
51+
// try {
52+
// // TODO Get all the typescript project compilers information
53+
// const codeATS = await TypeScriptAtsMapper.getInstance();
54+
// if (!codeATS) {
55+
// throw new Error("Failed to get TypeScriptAtsMapper instance");
56+
// }
57+
// const mappedCode = await codeATS.buildCodebaseMap();
58+
// if (!mappedCode) {
59+
// throw new Error("Failed to build codebase map");
60+
// }
61+
// const ats = Object.values(mappedCode).flatMap((repo) =>
62+
// Object.values(repo.modules),
63+
// );
64+
// const mapper = new CodeStructureMapper(ats);
65+
// return mapper.normalizeData();
66+
// } catch (error) {
67+
// this.logger.error("Error building function structure map:", error);
68+
// throw error;
69+
// }
70+
// }
7171

72-
/**
73-
* Generates function descriptions using the EmbeddingService.
74-
* @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data.
75-
*/
76-
async generateFunctionDescription(): Promise<IFunctionData[]> {
77-
try {
78-
const functions =
79-
(await this.buildFunctionStructureMap()) as IFunctionData[];
80-
if (!functions?.length) {
81-
throw new Error("failed to generate ATS");
82-
}
83-
return await this.embeddingService.processFunctions(functions);
84-
} catch (error) {
85-
this.logger.error("LLM unable to generate description", error);
86-
throw error;
87-
}
88-
}
72+
// /**
73+
// * Generates function descriptions using the EmbeddingService.
74+
// * @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data.
75+
// */
76+
// async generateFunctionDescription(): Promise<IFunctionData[]> {
77+
// try {
78+
// const functions =
79+
// (await this.buildFunctionStructureMap()) as IFunctionData[];
80+
// if (!functions?.length) {
81+
// throw new Error("failed to generate ATS");
82+
// }
83+
// return await this.embeddingService.processFunctions(functions);
84+
// } catch (error) {
85+
// this.logger.error("LLM unable to generate description", error);
86+
// throw error;
87+
// }
88+
// }
8989

90-
/**
91-
* Generates embeddings for the given functions using the EmbeddingService.
92-
* @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data.
93-
*/
94-
async generateEmbeddings(): Promise<IFunctionData[]> {
95-
const functionsWithDescription = await this.generateFunctionDescription();
96-
functionsWithDescription.forEach((item) => {
97-
if (!item.compositeText) {
98-
item.compositeText = `Description: ${item.description} Function: ${item.name} ${item.returnType} Dependencies: ${(item.dependencies ?? []).join(", ")}`;
99-
}
100-
});
101-
const functionWithEmbeddings = await this.embeddingService.processFunctions(
102-
functionsWithDescription,
103-
true,
104-
);
105-
return functionWithEmbeddings;
106-
}
90+
// /**
91+
// * Generates embeddings for the given functions using the EmbeddingService.
92+
// * @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data.
93+
// */
94+
// async generateEmbeddings(): Promise<IFunctionData[]> {
95+
// const functionsWithDescription = await this.generateFunctionDescription();
96+
// functionsWithDescription.forEach((item) => {
97+
// if (!item.compositeText) {
98+
// item.compositeText = `Description: ${item.description} Function: ${item.name} ${item.returnType} Dependencies: ${(item.dependencies ?? []).join(", ")}`;
99+
// }
100+
// });
101+
// const functionWithEmbeddings = await this.embeddingService.processFunctions(
102+
// functionsWithDescription,
103+
// true,
104+
// );
105+
// return functionWithEmbeddings;
106+
// }
107107

108-
/**
109-
* Inserts function data into the database using the CodeRepository.
110-
* @returns {Promise<ResultSet | undefined>} A promise that resolves with the result set or undefined.
111-
*/
112-
// async insertFunctionsinDB(): Promise<ResultSet | undefined> {
113-
// await this.getCodeRepository();
114-
// if (!this.codeRepository) {
115-
// this.logger.info("Unable to connect to the DB");
116-
// throw new Error("Unable to connect to DB");
117-
// }
118-
// const dataToInsert = await this.generateEmbeddings();
119-
// if (dataToInsert?.length) {
120-
// const valuesString = dataToInsert
121-
// .map(
122-
// (value) =>
123-
// `('${value.className}', '${value.name}', '${value.path}', '${value.processedAt}', vector32('[${(value.embedding ?? []).join(",")}]'))`,
124-
// )
125-
// .join(",");
126-
// const result = await this.codeRepository?.insertFunctions(valuesString);
127-
// return result;
128-
// }
129-
// }
130-
}
108+
// /**
109+
// * Inserts function data into the database using the CodeRepository.
110+
// * @returns {Promise<ResultSet | undefined>} A promise that resolves with the result set or undefined.
111+
// */
112+
// // async insertFunctionsinDB(): Promise<ResultSet | undefined> {
113+
// // await this.getCodeRepository();
114+
// // if (!this.codeRepository) {
115+
// // this.logger.info("Unable to connect to the DB");
116+
// // throw new Error("Unable to connect to DB");
117+
// // }
118+
// // const dataToInsert = await this.generateEmbeddings();
119+
// // if (dataToInsert?.length) {
120+
// // const valuesString = dataToInsert
121+
// // .map(
122+
// // (value) =>
123+
// // `('${value.className}', '${value.name}', '${value.path}', '${value.processedAt}', vector32('[${(value.embedding ?? []).join(",")}]'))`,
124+
// // )
125+
// // .join(",");
126+
// // const result = await this.codeRepository?.insertFunctions(valuesString);
127+
// // return result;
128+
// // }
129+
// // }
130+
// }

src/services/context-retriever.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ import {
55
IFileToolResponse,
66
} from "../application/interfaces/agent.interface";
77
import { Logger } from "../infrastructure/logger/logger";
8-
import { CodeRepository } from "../infrastructure/repository/code";
98
import { getAPIKeyAndModel } from "./../utils/utils";
109
import { EmbeddingService } from "./embedding";
1110
import { LogLevel } from "./telemetry";
1211
import { WebSearchService } from "./web-search-service";
1312

1413
export class ContextRetriever {
15-
private readonly codeRepository: CodeRepository;
14+
// private readonly codeRepository: CodeRepository;
1615
private readonly embeddingService: EmbeddingService;
1716
private static readonly SEARCH_RESULT_COUNT = 2;
1817
private readonly logger: Logger;
1918
private static instance: ContextRetriever;
2019
private readonly webSearchService: WebSearchService;
2120
protected readonly orchestrator: Orchestrator;
2221
constructor() {
23-
this.codeRepository = CodeRepository.getInstance();
22+
// this.codeRepository = CodeRepository.getInstance();
2423
const { apiKey, model } = getAPIKeyAndModel("gemini");
2524
this.embeddingService = new EmbeddingService(apiKey);
2625
this.logger = Logger.initialize("ContextRetriever", {

0 commit comments

Comments
 (0)