Super interesting project! I like that you're exposing the structure of the git repo to GPT, and helping it understand and access the code in a semantically meaningful way via the function definition APIs.<p>I've been working on similar things with GPT, but in a language agnostic way. That makes things a bit trickier, having to parse arbitrary source code languages.<p>I was curious how you were parsing/lexing the files to pull out functions. I asked GPT about your repo, to see if I might find some useful tools for my project. It provided the helpful summary below.<p>Looks like you're using typescript-estree to parse the code?<p><pre><code> $ git clone https://github.com/kesor/chatgpt-code-plugin.git
$ cd chatgpt-code-plugin
$ aider
Using git repo: .git
Use /help to see in-chat commands.
>>> how does this package find and index all the functions?
This package finds and indexes all the functions using the following process:
1 It starts by getting a list of all the files in the project using the getFileList function in src/function-utils.ts. This function recursively traverses the directories and returns an array
of file paths.
2 For each file in the list, the getFunctionList function in src/function-utils.ts is called. This function reads the file content and parses it into an Abstract Syntax Tree (AST) using a
TypeScript parser.
3 The findFunctionsInFile function in src/function-utils.ts is then called with the AST as an argument. This function traverses the AST and identifies function declarations, function
expressions, and class methods. It collects information about each function, such as its name, start and end positions, and stores it in an array.
4 Finally, the package returns an array of objects containing information about all the functions found in the project. This array can be used to index the functions and perform further
operations, such as retrieving the function's code or analyzing its structure.
>>> does it use any pre-built packages for this? or is it all homebrew?
Yes, this package uses some pre-built packages to achieve its functionality. Here are the main ones:
1 @typescript-eslint/typescript-estree: This package is used to parse TypeScript code into an Abstract Syntax Tree (AST). It is used in the getFunctionList function to parse the file content
and generate an AST.
2 fs: This is a built-in Node.js module for working with the file system. It is used to read directories, read file content, and check file stats.
3 ignore: This package is used to filter out files and directories based on the rules specified in the .gitignore file. It is used in the getFileList function to exclude files and directories
that should not be processed.
4 path: This is a built-in Node.js module for working with file and directory paths. It is used to join and resolve paths, and to get relative paths.
These pre-built packages are combined with custom code to find and index all the functions in the project.</code></pre>