Skip to content

Code Intelligence Resource

The codeIntelligence: resource provides structured code navigation using LSP (Language Server Protocol) for semantic accuracy, with automatic fallback to ripgrep (rg) when no LSP server is available. Supports Go, Python, Rust, TypeScript/JavaScript, C/C++, Ruby, and Java.

How it works

text
kdeps receives codeIntelligence request
  -> detects language from file extension
    -> tries to start LSP server (gopls, pyright, rust-analyzer, etc.)
      -> SUCCESS: sends LSP request, returns semantic results
      -> FAILURE: falls back to rg for text-based grep results

Where it runs

Both workflow mode and agent mode. In agent mode, it is also available as built-in tools — no YAML required:

ToolOperationExample
code_searchsymbolSearchcode_search(query="parseInput", path="/src")
code_definitiondefinitioncode_definition(symbol="Config", path="/src/main.go")
code_referencesreferencescode_references(symbol="Config", path="/src/main.go")
code_symbolsdocumentSymbolscode_symbols(path="/src/main.go")
code_hoverhovercode_hover(symbol="main", path="/src/main.go")
code_diagnosticsdiagnosticscode_diagnostics(path="/src/main.go")

Configuration Options

OptionOperationDescription
operationallThe code-intelligence operation (required)
pathallFile or directory to search
querysymbolSearchSymbol name or search pattern
symboldefinition, references, hoverSpecific symbol name
languageIdallExplicit LSP language ID: go, python, rust, typescript, javascript, c, cpp, ruby, java. Auto-detected from file extension if omitted.
patternallGlob filter e.g. "*.go" (rg fallback only)
languageallrg --type value (rg fallback only)
contextallLines of context before/after match (rg fallback only)
limitallMaximum results, 0 = unlimited (rg fallback only)
includeallrg --include patterns (rg fallback only)
excludeallrg --exclude patterns (rg fallback only)
recursiveallSearch subdirectories (rg fallback only)

Requirements

LSP servers are optional but recommended for semantic accuracy:

LanguageLSP ServerInstall
Gogoplsgo install golang.org/x/tools/gopls@latest
Pythonpyrightnpm install -g pyright
Rustrust-analyzerrustup component add rust-analyzer
TypeScript/JStypescript-language-servernpm install -g typescript-language-server
C/C++clangdOS package manager
Rubysolargraphgem install solargraph

ripgrep (rg) is required for the fallback path:

bash
brew install ripgrep       # macOS
sudo apt install ripgrep   # Ubuntu/Debian

Operations

Searches for a symbol or pattern across files. Uses LSP workspace/symbol for semantic search, or rg regex as fallback.

yaml
codeIntelligence:
  operation: symbolSearch
  query: "parseInput"
  path: /path/to/project
  pattern: "*.go"
  limit: 20

Output:

json
{
  "success": true,
  "symbols": [
    {"name": "parseInput", "kind": 12, "file": "/path/to/project/src/main.go"}
  ],
  "count": 1
}

Definition

Finds the definition of a symbol. Uses LSP textDocument/definition for semantic precision (no false positives on comments or similar names).

yaml
codeIntelligence:
  operation: definition
  symbol: "ParseConfig"
  path: /path/to/project/main.go

References

Finds all references to a symbol across the codebase. LSP returns cross-file results with type-level accuracy.

yaml
codeIntelligence:
  operation: references
  symbol: "ParseConfig"
  path: /path/to/project/main.go
  pattern: "*.go"

Document Symbols

Lists all symbols in a file with nesting (methods inside classes, etc.). LSP returns structured DocumentSymbol[] with children.

yaml
codeIntelligence:
  operation: documentSymbols
  path: /path/to/project/main.go

Output (LSP, Go):

json
{
  "success": true,
  "symbols": [
    {"name": "main", "kind": "function"},
    {"name": "Greeter", "kind": "struct"},
    {"name": "Greet", "kind": "method"}
  ],
  "count": 3
}

Hover

Retrieves documentation and type information for a symbol. LSP returns real doc comments and type signatures.

yaml
codeIntelligence:
  operation: hover
  symbol: "ProcessData"
  path: /path/to/project/main.go

Diagnostics

Runs compiler/linter diagnostics on a file. LSP returns errors and warnings from the language server (e.g., gopls for Go, pyright for Python). Falls back to go vet for Go files when no LSP server is available.

yaml
codeIntelligence:
  operation: diagnostics
  path: /path/to/project/main.go

Output:

json
{
  "success": true,
  "diagnostics": [
    {"message": "unused variable x", "severity": "2", "source": "compiler"}
  ],
  "count": 1
}

Best Practices

  1. Install LSP servers for semantic accuracy — avoids regex false positives
  2. Use languageId to override auto-detection when the file extension is ambiguous
  3. Use pattern to narrow searches with the rg fallback
  4. Agent mode tools are zero-config — LLM can call them without YAML

See Also

Released under the Apache 2.0 License.