Skip to content

Commit

Permalink
Added logic for descending to dependant files
Browse files Browse the repository at this point in the history
  • Loading branch information
codemakerai-dev committed Dec 6, 2023
1 parent 4e2e339 commit b83eade
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"test": "node ./out/test/runTest.js"
},
"dependencies": {
"codemaker-sdk": "^2.3.0"
"codemaker-sdk": "^2.4.0"
},
"devDependencies": {
"@types/glob": "^8.1.0",
Expand Down
28 changes: 18 additions & 10 deletions src/service/codemakerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from 'vscode';
import * as path from 'node:path';
import * as fs from 'node:fs';
import { TextDecoder, TextEncoder } from 'util';
import { Client, ProcessRequest, CompletionRequest, PredictRequest, Language, Mode, Modify, DiscoverContextRequest, CreateContextRequest, RegisterContextRequest, SourceContext } from 'codemaker-sdk';
import { Client, ProcessRequest, CompletionRequest, PredictRequest, Language, Mode, Modify, DiscoverContextRequest, CreateContextRequest, RegisterContextRequest, SourceContext, DiscoverContextResponse } from 'codemaker-sdk';
import { Configuration } from '../configuration/configuration';
import { langFromFileExtension } from '../utils/languageUtils';
import { CodeSnippetContext } from 'codemaker-sdk';
Expand All @@ -14,6 +14,8 @@ import { CodeSnippetContext } from 'codemaker-sdk';
*/
class CodemakerService {

private static readonly maximumSourceGraphDepth = 16;

private readonly client;

private readonly decoder;
Expand Down Expand Up @@ -148,11 +150,14 @@ class CodemakerService {
return async (filePath: vscode.Uri): Promise<void> => {
const lang = langFromFileExtension(filePath.path);

const paths: vscode.Uri[] = await this.discoverContext(filePath, lang);
if (depth < 1) {
for (let path of paths) {
await this.generateSourceGraphCode(path, depth + 1);
}
if (depth < CodemakerService.maximumSourceGraphDepth) {
const discoverContextResponse = await this.discoverContext(filePath, lang);
if (discoverContextResponse.requiresProcessing) {
const paths: vscode.Uri[] = this.matchContextPaths(discoverContextResponse, filePath);
for (let path of paths) {
await this.generateSourceGraphCode(path, depth + 1);
}
}
}

const contextId = await this.registerContext(lang, filePath, Mode.code);
Expand Down Expand Up @@ -200,18 +205,21 @@ class CodemakerService {
}
}

private async discoverContext(filePath: vscode.Uri, language: Language) {
const baseDir = path.dirname(filePath.fsPath);
private async discoverContext(filePath: vscode.Uri, language: Language) {
const source = await this.readFile(filePath);
return await this.client.discoverContext(this.createDiscoverContextRequest(language, source, filePath.path));
}

const discoverContextResponse = await this.client.discoverContext(this.createDiscoverContextRequest(language, source, filePath.path));
private matchContextPaths(discoverContextResponse: DiscoverContextResponse, filePath: vscode.Uri) {
const baseDir = path.dirname(filePath.fsPath);
return discoverContextResponse.requiredContexts.map(context => path.resolve(baseDir, path.relative(path.basename(filePath.fsPath), context.path)))
.filter(p => fs.existsSync(p))
.map(p => vscode.Uri.file(p));
}

private async resolveContext(filePath: vscode.Uri, language: Language) {
const paths: vscode.Uri[] = await this.discoverContext(filePath, language);
const discoverContextResponse = await this.discoverContext(filePath, language);
const paths: vscode.Uri[] = this.matchContextPaths(discoverContextResponse, filePath);

const sourceContexts = [];
for (let p of paths) {
Expand Down

0 comments on commit b83eade

Please sign in to comment.