Limit web-tree-sitter to max # of files to parse

This commit is contained in:
Saoud Rizwan
2024-07-31 08:17:10 -04:00
parent d93a08af5d
commit 3fc300273d
3 changed files with 8 additions and 12 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "claude-dev", "name": "claude-dev",
"version": "1.0.64", "version": "1.0.65",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "claude-dev", "name": "claude-dev",
"version": "1.0.64", "version": "1.0.65",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@anthropic-ai/sdk": "^0.24.3", "@anthropic-ai/sdk": "^0.24.3",

View File

@@ -2,7 +2,7 @@
"name": "claude-dev", "name": "claude-dev",
"displayName": "Claude Dev", "displayName": "Claude Dev",
"description": "Autonomous software engineer right in your IDE, capable of reading/writing files, executing commands, and more with your permission every step of the way.", "description": "Autonomous software engineer right in your IDE, capable of reading/writing files, executing commands, and more with your permission every step of the way.",
"version": "1.0.62", "version": "1.0.65",
"icon": "icon.png", "icon": "icon.png",
"engines": { "engines": {
"vscode": "^1.84.0" "vscode": "^1.84.0"

View File

@@ -3,16 +3,16 @@ import { globby } from "globby"
import * as path from "path" import * as path from "path"
import { LanguageParser, loadRequiredLanguageParsers } from "./languageParser" import { LanguageParser, loadRequiredLanguageParsers } from "./languageParser"
// TODO: implement caching behavior to avoid having to keep analyzing project for new tasks.
async function analyzeProject(dirPath: string): Promise<string> { async function analyzeProject(dirPath: string): Promise<string> {
let result = ""
// Get all files (not gitignored) // Get all files (not gitignored)
const allFiles = await getAllProjectFiles(dirPath) const allFiles = await getAllProjectFiles(dirPath)
let result = `Project: ${path.basename(dirPath)} (${allFiles.length.toLocaleString()} files)\n\n`
// Separate files to parse and remaining files // Separate files to parse and remaining files
const { filesToParse, remainingFiles } = separateFiles(allFiles) const { filesToParse, remainingFiles } = separateFiles(allFiles)
// Load only the necessary language parsers
const languageParsers = await loadRequiredLanguageParsers(filesToParse) const languageParsers = await loadRequiredLanguageParsers(filesToParse)
// Parse specific files we have language parsers for // Parse specific files we have language parsers for
@@ -20,9 +20,6 @@ async function analyzeProject(dirPath: string): Promise<string> {
for (const file of filesToParse) { for (const file of filesToParse) {
const definitions = await parseFile(file, languageParsers) const definitions = await parseFile(file, languageParsers)
if (definitions) { if (definitions) {
if (!result) {
result += "# Source code definitions:\n\n"
}
result += `${path.relative(dirPath, file)}\n${definitions}\n` result += `${path.relative(dirPath, file)}\n${definitions}\n`
} else { } else {
filesWithoutDefinitions.push(file) filesWithoutDefinitions.push(file)
@@ -30,7 +27,6 @@ async function analyzeProject(dirPath: string): Promise<string> {
} }
// List remaining files' paths // List remaining files' paths
result += "# Unparsed files:\n\n"
filesWithoutDefinitions filesWithoutDefinitions
.concat(remainingFiles) .concat(remainingFiles)
.sort() .sort()
@@ -98,8 +94,8 @@ function separateFiles(allFiles: string[]): { filesToParse: string[]; remainingF
"php", "php",
"swift", "swift",
].map((e) => `.${e}`) ].map((e) => `.${e}`)
const filesToParse = allFiles.filter((file) => extensions.includes(path.extname(file))) const filesToParse = allFiles.filter((file) => extensions.includes(path.extname(file))).slice(0, 50) // 50 files max
const remainingFiles = allFiles.filter((file) => !extensions.includes(path.extname(file))) const remainingFiles = allFiles.filter((file) => !filesToParse.includes(file))
return { filesToParse, remainingFiles } return { filesToParse, remainingFiles }
} }