Skip to content

Commit

Permalink
Merge pull request #31 from codybrom/v4
Browse files Browse the repository at this point in the history
v1.4 refactor and rename
  • Loading branch information
codybrom authored Jan 6, 2025
2 parents 36166d1 + 4d143c1 commit 392ae80
Show file tree
Hide file tree
Showing 32 changed files with 1,649 additions and 980 deletions.
24 changes: 0 additions & 24 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dependabot configuration for GPT Context Generator VSCode plugin
# Dependabot configuration for LLM Context Generator VSCode plugin

version: 2
updates:
Expand Down
16 changes: 0 additions & 16 deletions .prettierrc

This file was deleted.

4 changes: 1 addition & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
"recommendations": ["dbaeumer.vscode-eslint"]
}
12 changes: 3 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
},
{
Expand All @@ -25,9 +21,7 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
]
Expand Down
16 changes: 8 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"files.exclude": {
"out": false
},
"search.exclude": {
"out": true
},
"typescript.tsc.autoDetect": "off",
"prettier.configPath": ".prettierrc"
"files.exclude": {
"out": false
},
"search.exclude": {
"out": true
},
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": ["codybrom", "dqbd", "tiktoken", "unmark", "yarnrc"]
}
7 changes: 5 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ src/**
.gitignore
.yarnrc
**/tsconfig.json
**/.eslintrc.json
.eslint*

# Ignore source map files
**/*.map
**/*.map

# Ignore dependencies
node_modules/**
115 changes: 71 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,96 @@
# GPT Context Generator
# LLM Context Generator

[![Code Style Airbnb](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)
[![VS Marketplace Version](https://badgen.net/vs-marketplace/v/codybrom.gpt-context-generator)](https://marketplace.visualstudio.com/items?itemName=codybrom.gpt-context-generator)
[![VS Marketplace Installs](https://badgen.net/vs-marketplace/i/codybrom.gpt-context-generator)](https://marketplace.visualstudio.com/items?itemName=codybrom.gpt-context-generator)
[![VS Marketplace Rating](https://badgen.net/vs-marketplace/d/codybrom.gpt-context-generator)](https://marketplace.visualstudio.com/items?itemName=codybrom.gpt-context-generator)

This Visual Studio Code extension helps you generate context for .js/.jsx and .ts/.tsx files, making
it easier to collaborate with AI models like OpenAI's GPT-4. The extension generates context by
pulling in local dependencies such as API pages that are referenced in your code. It also respects
`.gitignore` rules to avoid including unnecessary files.
This Visual Studio Code extension helps you generate LLM-ready context from your workspace files, making it easier to collaborate with AI models. The extension can automatically reference local code dependencies and respects your `.gitignore` rules to avoid including unnecessary files.

## Features

- Generate GPT-compatible multi-file context from the currently open file and local imports
- Generate GPT-compatible multi-file context of the entire VS Code workspace
- Generate GPT-compatible multi-file context for marked files
- Mark/Unmark files for inclusion in generated context
- Estimate the number of OpenAI tokens in the generated context
- Generate LLM-ready context from the currently open file and its imports, your entire VS Code workspace or marked files
- Mark or unmark open files via Command Palette, or individual files and folders via the Explorer context menu
- Automatic file tracking updates marked files when they're moved or deleted
- Token count estimation for generated context
- Automatic support for multiple programming languages and file types

## Usage

### Generate context for the currently open file and its local imports
### Mark Files for Context

1. Open a file in Visual Studio Code.
2. Press `Ctrl+Shift+P` (Windows) or `Cmd+Shift+P` (Mac) to open the Command Palette.
3. Type `Generate GPT Context (Current File + Imports)` and select the command from the list.
4. The generated context, including dependencies, will be displayed in a new editor tab or copied to the clipboard based on your configuration.
1. **Via Explorer**:
- Right-click on one or more files or folders in the Explorer
- Select "Mark for LLM Context"
- Files appear in the Marked Files view
- Marking a folder includes all compatible files within it

### Generate context for the entire workspace
2. **Via Command Palette**:
- Open a file
- Press `Ctrl+Shift+P` (Windows) or `Cmd+Shift+P` (Mac)
- Select "Mark/Unmark File for LLM Context"

1. Open a workspace in Visual Studio Code.
2. Press `Ctrl+Shift+P` (Windows) or `Cmd+Shift+P` (Mac) to open the Command Palette.
3. Type `Generate GPT Context (Workspace)` and select the command from the list.
4. The generated context will be displayed in a new editor tab or copied to the clipboard based on your configuration.
### Generate Context

### Generate context for marked files
Three ways to generate context:

1. Open a file in Visual Studio Code.
2. Press `Ctrl+Shift+P` (Windows) or `Cmd+Shift+P` (Mac) to open the Command Palette.
3. Type `Mark/Unmark File for Inclusion` and select the command to mark the file for inclusion.
4. Repeat steps 1-3 for all files you want to include in the context.
5. Press `Ctrl+Shift+P` (Windows) or `Cmd+Shift+P` (Mac) to open the Command Palette.
6. Type `Generate GPT Context (Marked Files)` and select the command from the list.
7. The generated context for marked files will be displayed in a new editor tab or copied to the clipboard based on your configuration.
1. **Current File + Imports**:
- Open a file
- Command Palette → "Generate LLM Context (Current File + Imports)"

2. **Workspace**:
- Open a workspace
- Command Palette → "Generate LLM Context (Workspace)"

3. **Marked Files**:
- Mark desired files
- Command Palette → "Generate LLM Context (Marked Files)"

The generated context will be copied to your clipboard or opened in a new window, based on your settings.

## Token Count Estimation

When generating context, the extension will also display an information message with an estimated
number of OpenAI tokens in the generated text. This information can be helpful when working with AI
models that have token limitations.
After generating context, you'll see an estimated token count. This helps you stay within AI model token limits. A warning appears if the context exceeds 8,000 tokens.

## Configuration

From settings, you can configure the extension to work as you prefer.

- **Output method**
- Copy to Clipboard (_default_)
- New Window
- **Output language** (only applies when 'outputMethod' is set to 'newWindow')
- Plaintext (_default_)
- Markdown
- **Include package.json in open-file context** (_default: true_)
- **Set File Extensions to Include in Workspace Context**
- _defaults: js, jsx, ts, tsx, mdx, json_
Configure the extension in VS Code settings:

- **Detected File Extensions**
- Customize which file types to include
- Supports many languages and formats:
- JavaScript/TypeScript (js, jsx, ts, tsx, etc.)
- Python (py, pyi, pyw, ipynb)
- Ruby (rb, rake, erb, etc.)
- PHP (php, phtml)
- Swift/Objective-C (swift, m, h, etc.)
- Systems (c, cpp, rs, go, etc.)
- Web (html, css, scss, etc.)
- Mobile (java, kt, dart, etc.)
- Configuration (json, yaml, toml, etc.)
- And more...

- **Ignore Files**
- Files containing ignore patterns (like .gitignore)
- Default: `.gitignore`, `.dockerignore`
- Patterns from each file are used to exclude matching files from context
- Files are processed in order, and missing files are safely skipped

- **Token Warning Threshold**
- Token count threshold for showing warnings
- Default: `8000`

- **Output Method**
- `clipboard`: Copy to clipboard (default)
- `newWindow`: Open in new editor

- **Output Format** (for newWindow only)
- `plaintext`: Plain text (default)
- `markdown`: Markdown formatting

- **Include package.json** (for open file context only)
- Include package.json when generating context for open file
- Default: `true`

## License

This extension is released under the MIT License.
Released under the MIT License.
11 changes: 11 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('esbuild')
.build({
entryPoints: ['src/extension.ts'],
bundle: true,
outdir: 'out',
platform: 'node',
format: 'cjs',
sourcemap: true,
external: ['vscode'],
})
.catch(() => process.exit(1));
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* ESLint configuration for the project.
*
* See https://eslint.style and https://typescript-eslint.io for additional linting options.
*/
// @ts-check
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import stylistic from '@stylistic/eslint-plugin';

export default tseslint.config(
{
ignores: ['out', 'dist', '**/*.d.ts'],
},
js.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
plugins: {
'@stylistic': stylistic,
},
rules: {
curly: 'warn',
'@stylistic/semi': ['warn', 'always'],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'import',
format: ['camelCase', 'PascalCase'],
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
},
],
},
},
);
4 changes: 4 additions & 0 deletions images/clear-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/clear-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 392ae80

Please sign in to comment.