Skip to content

Commit d2ac4a2

Browse files
committed
Fix Language Model Tools and add esbuild bundling
- Fix direction enum mismatch (dependents → importedBy) in package.json - Add handleToolError() for graceful cancellation handling - Make reference search optional with 5s timeout via includeReferences param - Improve prepareInvocation messages with proper defaults - Add esbuild bundling to resolve vscode-languageclient module error - Create build script (scripts/build.sh) for development workflow - Add server-side related tests handler with graph-based discovery - Fix formatRelatedTests tests to match actual response structure - Fix Rust clippy warnings (needless borrows) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 59e743c commit d2ac4a2

16 files changed

+1528
-298
lines changed

.vscodeignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# Source files (compiled output is in out/)
1+
# Source files (bundled output is in out/extension.js)
22
src/**
33
!src/**/*.d.ts
44

5+
# TypeScript compiled files (we use esbuild bundle instead)
6+
out/**
7+
!out/extension.js
8+
59
# Rust source (binary is pre-built)
610
server/src/**
711
server/Cargo.toml
@@ -45,6 +49,7 @@ tsconfig.json
4549
vitest.config.*
4650
vsforge.config.json
4751
.gitignore
52+
esbuild.js
4853

4954
# Scripts (not needed at runtime)
5055
scripts/**

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
[workspace.package]
99
edition = "2021"
1010
license = "Apache-2.0"
11-
repository = "https://github.com/codegraph/codegraph-vscode"
11+
repository = "https://github.com/anvanster/codegraph-vscode"
1212
authors = ["CodeGraph Team"]
1313

1414
[workspace.dependencies]

bin/codegraph-lsp-darwin-arm64

17.4 KB
Binary file not shown.

docs/AI_TOOL_EXAMPLES.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CodeGraph tools provide **semantic understanding** rather than text matching. Th
3333
"uri": "file:///path/to/file.ts", // Required: file to analyze
3434
"depth": 3, // Optional: traversal depth (1-10)
3535
"includeExternal": false, // Optional: include node_modules
36-
"direction": "both" // Optional: "imports", "dependents", or "both"
36+
"direction": "both" // Optional: "imports", "importedBy", or "both"
3737
}
3838
```
3939

@@ -441,24 +441,27 @@ test('user can complete payment', async ({ page }) => {
441441

442442
### 6. `codegraph_get_symbol_info`
443443

444-
**Purpose:** Get metadata about a symbol — its type, signature, documentation, and usage statistics.
444+
**Purpose:** Get metadata about a symbol — its type, signature, documentation, and optionally usage statistics.
445445

446446
**When to use:**
447447
- Quick symbol lookup
448448
- Understanding function signatures
449449
- Finding documentation
450-
- Assessing symbol usage
450+
- Assessing symbol usage (with `includeReferences: true`)
451451

452452
**Parameters:**
453453
```json
454454
{
455455
"uri": "file:///path/to/file.ts", // Required: file containing symbol
456456
"line": 45, // Required: line number (0-indexed)
457-
"character": 0 // Optional: character position
457+
"character": 0, // Optional: character position
458+
"includeReferences": false // Optional: include all references (can be slow)
458459
}
459460
```
460461

461-
**Example — "What is calculateDiscount?"**
462+
**Performance note:** Reference search can be slow on large workspaces. By default, references are not included. Set `includeReferences: true` only when you need usage statistics. For dependency analysis, consider using `codegraph_analyze_impact` instead.
463+
464+
**Example — "What is calculateDiscount?" (fast, no references)**
462465

463466
```
464467
Tool: codegraph_get_symbol_info
@@ -489,6 +492,34 @@ function calculateDiscount(total: number, tier: CustomerTier): number
489492
## Definition
490493
- /project/src/pricing/discounts.ts:35
491494

495+
## References
496+
_References not included. Set `includeReferences: true` to find usages (may be slow)._
497+
```
498+
499+
**Example — "Where is calculateDiscount used?" (with references)**
500+
501+
```
502+
Tool: codegraph_get_symbol_info
503+
Input: {
504+
"uri": "file:///project/src/pricing/discounts.ts",
505+
"line": 34,
506+
"character": 15,
507+
"includeReferences": true
508+
}
509+
```
510+
511+
**Output (with references):**
512+
```markdown
513+
# Symbol Information
514+
515+
Location: file:///project/src/pricing/discounts.ts:35:16
516+
517+
## Documentation & Type Information
518+
[...same as above...]
519+
520+
## Definition
521+
- /project/src/pricing/discounts.ts:35
522+
492523
## References (12 usages)
493524
- **CheckoutService.ts** (3 references)
494525
Line 45, Line 89, Line 123

docs/autonomous_ai_integration_plan.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ The VS Code Language Model Tools API is **stable and available** in VS Code 1.90
7373
},
7474
"direction": {
7575
"type": "string",
76-
"enum": ["imports", "dependents", "both"],
77-
"description": "Direction to analyze: 'imports' (what this file uses), 'dependents' (what uses this file), or 'both'",
76+
"enum": ["imports", "importedBy", "both"],
77+
"description": "Direction to analyze: 'imports' (what this file uses), 'importedBy' (what uses this file), or 'both'",
7878
"default": "both"
7979
}
8080
},
@@ -517,9 +517,9 @@ export class CodeGraphToolManager {
517517
let output = '# Dependency Graph\n\n';
518518
output += `Found ${nodes.length} files/modules with ${edges.length} dependencies.\n\n`;
519519

520-
// Group by import vs dependent
521-
const imports = edges.filter(e => e.type === 'imports');
522-
const dependents = edges.filter(e => e.type === 'dependents');
520+
// Group by import vs importedBy
521+
const imports = edges.filter(e => e.type === 'import');
522+
const importedBy = edges.filter(e => e.type === 'importedBy');
523523

524524
if (imports.length > 0) {
525525
output += `## Imports (${imports.length})\n`;
@@ -531,9 +531,9 @@ export class CodeGraphToolManager {
531531
output += '\n';
532532
}
533533

534-
if (dependents.length > 0) {
535-
output += `## Dependents (${dependents.length})\n`;
536-
dependents.forEach(edge => {
534+
if (importedBy.length > 0) {
535+
output += `## Imported By (${importedBy.length})\n`;
536+
importedBy.forEach(edge => {
537537
const source = nodes.find(n => n.id === edge.source);
538538
const target = nodes.find(n => n.id === edge.target);
539539
output += `- ${source?.label || edge.source} ← ${target?.label || edge.target}\n`;

esbuild.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const esbuild = require('esbuild');
2+
3+
const production = process.argv.includes('--production');
4+
const watch = process.argv.includes('--watch');
5+
6+
/**
7+
* @type {import('esbuild').Plugin}
8+
*/
9+
const esbuildProblemMatcherPlugin = {
10+
name: 'esbuild-problem-matcher',
11+
setup(build) {
12+
build.onStart(() => {
13+
console.log('[watch] build started');
14+
});
15+
build.onEnd((result) => {
16+
result.errors.forEach(({ text, location }) => {
17+
console.error(`✘ [ERROR] ${text}`);
18+
console.error(` ${location.file}:${location.line}:${location.column}:`);
19+
});
20+
console.log('[watch] build finished');
21+
});
22+
},
23+
};
24+
25+
async function main() {
26+
const ctx = await esbuild.context({
27+
entryPoints: ['src/extension.ts'],
28+
bundle: true,
29+
format: 'cjs',
30+
minify: production,
31+
sourcemap: !production,
32+
sourcesContent: false,
33+
platform: 'node',
34+
outfile: 'out/extension.js',
35+
external: ['vscode'],
36+
logLevel: 'silent',
37+
plugins: [
38+
/* add to the end of plugins array */
39+
esbuildProblemMatcherPlugin,
40+
],
41+
});
42+
if (watch) {
43+
await ctx.watch();
44+
} else {
45+
await ctx.rebuild();
46+
await ctx.dispose();
47+
}
48+
}
49+
50+
main().catch((e) => {
51+
console.error(e);
52+
process.exit(1);
53+
});

0 commit comments

Comments
 (0)