Skip to content

Commit

Permalink
fix:java sample code (#77)
Browse files Browse the repository at this point in the history
* fix:java sample code

Signed-off-by: Aditya-eddy <[email protected]>

* chore: add size of parser

Signed-off-by: shivamsouravjha <[email protected]>

---------

Signed-off-by: Aditya-eddy <[email protected]>
Signed-off-by: shivamsouravjha <[email protected]>
Co-authored-by: shivamsouravjha <[email protected]>
  • Loading branch information
Aditya-eddy and shivamsouravjha authored Oct 15, 2024
1 parent 52f6637 commit aae9c1a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

8 changes: 6 additions & 2 deletions src/Utg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,20 @@ async function Utg(context: vscode.ExtensionContext , additional_prompts?:string

// Define the test file name by appending 'Test' to the original class name
const originalClassName = path.basename(sourceFilePath, '.java');
const testFileName = `${originalClassName}Test.java`;
const testFileName = `${originalClassName}Tests.java`;
const testFilePath = path.join(fullTestDir, testFileName);
const JavaClassName = `${originalClassName}Tests`

Check warning on line 150 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 150 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 150 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon

testFilePaths.push(testFilePath);

if (!fs.existsSync(testFilePath)) {
vscode.window.showInformationMessage("Test doesn't exist", testFilePath);

// **Create Test File Content with Proper Package and JUnit Imports**
const testFileContent = `package ${packageName};`;
const testFileContent = `package ${packageName};\n\n
class ${JavaClassName} {\n
}\n`;

fs.writeFileSync(testFilePath, testFileContent);
vscode.window.showInformationMessage(`Created test file: ${testFilePath}`);
console.log(`🐰 Created test file with package name: ${testFilePath}`);
Expand Down
13 changes: 11 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
if (
fileName.endsWith('.test.js') ||
fileName.endsWith('.test.ts') ||
fileName.endsWith('Tests.java') || // Check for Java test file ending
fileName.endsWith('Test.java') || // Check for Java test file ending
fileName.includes('/Test') || // Check for Java test file prefix in the path
fileName.includes('/test/') || // Skip files in a "tests" directory
Expand Down Expand Up @@ -296,7 +297,11 @@ async function findTestCasesForFunction(functionName: string, fileExtension: str
continue;
}

const tree = parser.parse(text);
const options: TreeSitter.Options = {
bufferSize: 1024 * 1024,
};

const tree = parser.parse(text, undefined, options); // Parse the document text
const cursor = tree.walk();
let found = false;

Expand Down Expand Up @@ -414,8 +419,12 @@ async function getAllFunctionsInFile(
console.log('🐰 Unsupported file type:', filePath);
throw new Error("Unsupported file type");
}
const options: TreeSitter.Options = {
bufferSize: 1024 * 1024,
};

const tree = parser.parse(text, undefined, options); // Parse the document text

const tree = parser.parse(text);
const cursor = tree.walk();
const functionNames: string[] = [];

Expand Down

0 comments on commit aae9c1a

Please sign in to comment.