funcfinder

command module
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 6 Imported by: 0

README

funcfinder

Go Version License Platform

Production-grade code analysis factory for multi-language codebases

funcfinder is not just a parser—it's a universal code analysis factory that automatically detects languages, extracts functions/classes/types, and scales from single files to entire repositories. Built on a state-machine sanitizer (not regex), it handles C# verbatim strings, Python docstrings, and nested comments correctly where simple regex fails.

⚡ Performance: 763,000 lines/sec parsing · Parallel processing with worker pools · Processes 100K lines in ~130ms

✨ What Makes It Different

🏭 Factory Architecture, Not Simple Regex
  • Language Factory: Auto-detects 15+ languages by extension
  • Parser Factory: Switches between brace-based (Go/Java) and indent-based (Python) parsers
  • Enhanced Sanitizer: State machine that correctly handles edge cases regex can't (C# @"...", Python """, nested comments)
  • Multiple Finders: Function finder, struct finder, combined mode—all through unified API
🚀 Production Features
  • 📁 Directory Mode ⭐ NEW: --dir ./project scans entire repositories with automatic language detection
  • Parallel Processing: --workers 8 for 4-8x speedup on large codebases
  • 🎯 Smart Filtering: Automatic .gitignore support, skip node_modules, vendor, etc.
  • 🔍 Three Analysis Modes:
    • --map (default): Find all functions
    • --struct: Find only classes/structs/types
    • --all: Both functions and types
  • 📊 Output Formats: grep-style, JSON, tree, tree-full, extract bodies
  • 🎨 Multi-language: Single command analyzes mixed Go/Python/C++/Java projects
  • 🪟 Cross-platform: Linux, macOS, Windows—zero dependencies
📈 Real-World Performance
# Small project (21 files, mixed languages)
funcfinder -dir test_examples --all --map
→ 273 functions + 438 types in ~30-45ms

# Medium project (25 Go files)
funcfinder -dir internal --all --json
→ 228 functions + 69 classes in ~40ms

# Parallel speedup
--workers 1: 45ms  →  --workers 4: 29ms (1.55x faster)

🌐 Core Capabilities

  • 🔍 Single File Analysis: --inp file.go --map for targeted extraction
  • 📁 Directory Scanning: --dir ./src --all for entire codebases
  • 🏗️ Type Extraction: --struct finds classes, structs, interfaces, enums
  • 🔄 Combined Analysis: --all gets both functions and types in one pass
  • 🗺️ Codebase Mapping: --tree shows hierarchical structure
  • 📏 Precise Extraction: --lines 50:100 for specific code ranges
  • 📤 Body Extraction: --extract pulls complete function bodies
  • 📊 JSON Export: --json for programmatic processing
  • Performance: 763K lines/sec sanitizer, parallel worker pools
  • 🎯 Zero Dependencies: Single static binary

🌐 Supported Languages (15)

  • Go
  • C
  • C++
  • C#
  • Java
  • D
  • JavaScript (including async functions, generator functions, arrow functions)
  • TypeScript (including async functions, generator functions, arrow functions, generics)
  • Python (including async/await, decorators, generators, class methods)
  • Rust (including pub/async functions, structs, traits, enums, impl blocks)
  • Swift (including classes, structs, protocols, enums, static functions)
  • Kotlin ⭐ NEW (including suspend functions, data classes, sealed classes, objects)
  • PHP ⭐ NEW (including classes, traits, interfaces, visibility modifiers)
  • Ruby ⭐ NEW (including modules, class methods, methods with ? and !)
  • Scala ⭐ NEW (including case classes, traits, objects, pattern matching)

📦 Installation

go install github.com/ruslano69/funcfinder@latest
Pre-built Binaries

Download from Releases:

# Linux
wget https://github.com/ruslano69/funcfinder/releases/download/v1.6.0/funcfinder-linux-amd64.tar.gz
tar -xzf funcfinder-linux-amd64.tar.gz
sudo mv funcfinder /usr/local/bin/

# macOS
wget https://github.com/ruslano69/funcfinder/releases/download/v1.6.0/funcfinder-darwin-amd64.tar.gz
tar -xzf funcfinder-darwin-amd64.tar.gz
sudo mv funcfinder /usr/local/bin/

# Windows
# Download funcfinder-windows-amd64.zip and add to PATH
From Source
git clone https://github.com/ruslano69/funcfinder.git
cd funcfinder

# Linux/macOS: Build all utilities (funcfinder, stat, deps, complexity)
./build.sh

# Windows (PowerShell): Build all utilities
.\build.ps1

# Or build funcfinder only
go build  # Now works! ✅

✅ Fixed: go build now works without errors! Other utilities use build tags and are built via build.sh/build.ps1.

For Windows-specific instructions, see docs/WINDOWS.md.

🚀 Quick Start

Directory Mode (⭐ Most Powerful)
# Scan entire project (auto-detects languages)
funcfinder --dir ./myproject --map --tree

# Find all functions + classes in repository
funcfinder --dir ./src --all --json > codebase.json

# Fast parallel scan with 8 workers
funcfinder --dir . --map --workers 8

# Only structs/classes (skip functions)
funcfinder --dir ./models --struct --map

# Output:
# INFO: Scanning directory: ./src (mode=all, workers=8, gitignore=true)
# └── src
# ├── main.go
# │   ├── def main (line 10)
# │   └── class Server (line 25)
# ├── handler.py
# │   ├── def process (line 5)
# │   └── class Handler (line 20)
# INFO: Processed 15 files, found 45 functions, 12 classes/types
Single File Mode
Check version
funcfinder --version
# Output: funcfinder version 1.6.0
Map all functions in a file
funcfinder --inp main.go --source go --map
# Output: main: 10-25; Handler: 45-78; helper: 65-72;
Find specific functions
funcfinder --inp api.go --source go --func Handler,Middleware
# Output: Handler: 45-78; Middleware: 80-95;
JSON output for AI
funcfinder --inp api.go --source go --map --json
{
  "Handler": {"start": 45, "end": 78},
  "Middleware": {"start": 80, "end": 95}
}
Extract function body
funcfinder --inp api.go --source go --func Handler --extract
// Handler: 45-78
func Handler(w http.ResponseWriter, r *http.Request) {
    // function body...
}
Find structs/classes/types (NEW in v1.5.0)
# Map all types in a Go file
funcfinder --inp models.go --source go --struct --map
# Output: User: 10-15; fields: ID, Name, Email Address: 20-25; fields: Street, City, Zip

# Find specific types
funcfinder --inp models.go --source go --struct --type User,Address
# Output: User: 10-15; fields: ID, Name, Email Address: 20-25; fields: Street, City, Zip

# JSON output for types
funcfinder --inp models.py --source py --struct --map --json
{
  "filename": "models.py",
  "types": [
    {
      "name": "User",
      "kind": "class",
      "start": 5,
      "end": 12,
      "fields": [
        {"name": "id", "type": "int", "line": 6},
        {"name": "name", "type": "str", "line": 7}
      ]
    }
  ]
}
Combined mode: functions + structs (NEW in v1.5.0)
# Get complete file structure in one call
funcfinder --inp service.go --source go --all --map

# Output:
# === FUNCTIONS ===
# NewService: 30-35; Process: 40-55; Validate: 60-70;
#
# === TYPES ===
# Service: 10-15; fields: db, cache Config: 20-25; fields: Host, Port

# JSON output with both functions and types
funcfinder --inp api.go --source go --all --json
{
  "filename": "api.go",
  "functions": [
    {"name": "NewService", "start": 30, "end": 35},
    {"name": "Process", "start": 40, "end": 55}
  ],
  "types": [
    {
      "name": "Service",
      "kind": "struct",
      "start": 10,
      "end": 15,
      "fields": [
        {"name": "db", "type": "*sql.DB", "line": 11},
        {"name": "cache", "type": "Cache", "line": 12}
      ]
    }
  ]
}

🏗️ Architecture: Why Not Just Regex?

The Problem with Simple Regex Parsers

Most code parsers use naive regex patterns and fail on edge cases:

// ❌ Simple regex breaks here:
string path = @"C:\Users\Test";  // C# verbatim string
string msg = @"He said ""Hello""";  // Escaped quotes in verbatim

// ❌ Regex truncates this:
query := `SELECT * FROM users // not a comment`  // Go raw string

// ❌ Regex sees 6 quotes, not 1 docstring:
"""This is a Python docstring"""
funcfinder's Solution: Factory + State Machine
Input File → Language Factory → Parser Factory → Enhanced Sanitizer → Pattern Matching
     │              │                  │                    │                  │
  file.go      GoConfig          Finder           State Machine         Find Functions
  file.py    PythonConfig    PythonFinder     (763K lines/sec)         Extract Bodies
  file.cs      CSharpConfig       Finder       Handles verbatim            Output

Key Components:

  1. Language Factory (languages.json)

    • Auto-detects language by extension
    • Loads correct parser config (brace-based vs indent-based)
    • Supports 15+ languages with language-specific features
  2. Enhanced Sanitizer (State Machine, not regex)

    • 7 states: Normal, LineComment, BlockComment, String, RawString, CharLiteral, MultiLineString
    • Correctly handles: C# @"...", Python """, Go `...`, nested comments
    • Performance: 763,000 lines/sec
    • Technical deep-dive
  3. Parser Factory

    • CreateFinder() → Brace-based (Go, Java, C++) or Indent-based (Python)
    • CreateStructFinder() → Type extraction with field parsing
    • Unified API regardless of language
  4. Directory Processor

    • Worker pool for parallel processing
    • .gitignore pattern matching
    • Language detection per file
    • Result aggregation

Result: Handles production code that breaks simple regex parsers.

Proof: Test Results
# C# verbatim strings (broken in most tools)
funcfinder --inp test.cs --source cs --map
✅ Correctly handles @"C:\Users" and @"He said ""Hello"""

# Python docstrings (often counted as 6 separate strings)
funcfinder --inp test.py --source py --map
✅ Treats """...""" as single multiline string

# Go raw strings with comment-like content
funcfinder --inp test.go --source go --map
✅ `SELECT // not comment` parsed correctly

See STAT_FIX_COMPLETED.md for detailed comparison.

🤖 AI Agent Integration

mini-SWE-agent Support

funcfinder provides perfect CLI tools for mini-SWE-agent - a minimalist AI coding agent that uses only bash commands.

Why perfect match:

  • ✅ Pure bash interface (no special tool-calling)
  • ✅ Stateless execution (each command independent)
  • ✅ JSON output everywhere (--json flag)
  • ✅ 99% token reduction vs reading full files

Quick Example:

# Agent workflow: Fix bug in auth/middleware.go

# 1. Get COMPLETE structure - functions + types (50 tokens vs 5000) ⭐ NEW
funcfinder --inp auth/middleware.go --source go --all --json

# 2. Extract buggy function (150 tokens vs 5000)
funcfinder --inp auth/middleware.go --source go --func ValidateToken --extract

# 3. Check related types (understand data structures)
funcfinder --inp auth/middleware.go --source go --struct --type TokenData --extract

# 4. Check complexity
complexity auth/middleware.go -j | jq '.functions[] | select(.name=="ValidateToken")'

# 5. Make targeted fix with 99% token savings! 🎉

Why --all is perfect for AI agents:

  • ✅ One call = complete context (functions + data structures)
  • ✅ Understand both behavior (functions) and state (types)
  • ✅ Minimal tokens for maximum insight
  • ✅ Perfect for code understanding and refactoring tasks

See: Complete Integration Guide | Example Workflows

💡 Use Cases

AI-Driven Development

Problem: AI reading 10,000 lines when it needs 250

Solution:

# 1. Get file structure (minimal tokens)
funcfinder --inp large_file.go --source go --map --json

# 2. AI selects needed function from map

# 3. Extract only that function (97.5% token savings!)
funcfinder --inp large_file.go --source go --func ProcessData --extract
Code Navigation
# Find all methods in a C# file
funcfinder --inp Controller.cs --source cs --map --json > functions.json

# Extract specific method for review
funcfinder --inp Controller.cs --source cs --func CreateUser --extract
JavaScript/TypeScript Support
# Find all functions in a JavaScript file
funcfinder --inp app.js --source js --map --json

# Extract async function from TypeScript
funcfinder --inp api.ts --source ts --func fetchUser --extract

# Find generator functions
funcfinder --inp generators.js --source js --func simpleGenerator --extract

# Extract arrow functions
funcfinder --inp utils.js --source js --func arrowFunc,asyncArrow --extract

# Find React component methods
funcfinder --inp Component.jsx --source js --func render,componentDidMount
Python Support with Decorators
# Map all functions in Python file
funcfinder --inp api.py --source py --map

# Extract function with decorators
funcfinder --inp api.py --source py --func cached_function --extract

# JSON output includes decorators
funcfinder --inp api.py --source py --func get_user --json
{
  "get_user": {
    "decorators": [
      "@require_auth",
      "@validate_input"
    ],
    "end": 42,
    "start": 35
  }
}

# Find async functions and generators
funcfinder --inp utils.py --source py --func async_generator,fibonacci --extract
Struct/Type Finding (NEW in v1.5.0)
# Find all types in a Go file
funcfinder --inp models.go --source go --struct --map
# Output: User: 10-20; fields: ID, Name, Email Config: 25-30; fields: Host, Port

# Find specific structs/classes
funcfinder --inp models.py --source py --struct --type User,Product --extract

# Get complete file structure (functions + types)
funcfinder --inp service.go --source go --all --json
{
  "functions": [{"name": "NewService", "start": 35, "end": 45}],
  "types": [
    {
      "name": "Service",
      "kind": "struct",
      "fields": [{"name": "db", "type": "*sql.DB", "line": 12}]
    }
  ]
}

# Find C++ classes and structs
funcfinder --inp widget.cpp --source cpp --struct --map

# Find Java classes and interfaces
funcfinder --inp api.java --source java --struct --map

# Find Python classes with fields
funcfinder --inp models.py --source py --struct --tree
# Output:
# class User (10-25)
#   ├── field id: int (line 11)
#   ├── field name: str (line 12)
#   └── field email: str (line 13)

Why struct finding is useful:

  • 🏗️ Understand data structures before modifying code
  • 🔍 Find type definitions across large codebases
  • 📊 JSON output for AI-powered refactoring
  • 🔄 Combined with functions for complete context
Tree Visualization for Classes
# Display class hierarchy in tree format
funcfinder --inp Calculator.java --source java --tree

# Output:
# class Calculator (1-20)
# ├── method add (5-7)
# ├── method subtract (9-11)
# └── method multiply (13-15)
# class Helper (22-30)
# ├── method assist (23-25)
# └── method process (27-29)

# Tree with full signatures
funcfinder --inp api.ts --source ts --tree-full

# Visualize Python classes (with decorators!)
funcfinder --inp models.py --source py --tree
Line Range Filtering (v1.4.0+)
# Standalone mode: Fast file slicing (works on ANY file, no --source needed)
funcfinder --inp app.log --lines 1000:1100
# Output: Lines 1000-1100 with line numbers

# JSON output for line ranges
funcfinder --inp config.yaml --lines :50 --json

# Filter mode: Narrow function search to specific lines
funcfinder --inp large_file.go --source go --map --lines 500:1000
# Only shows functions within lines 500-1000

# Find function in specific area (much faster for large files)
funcfinder --inp server.js --source js --func handleAPI --lines 100:500 --extract

# Tree view of limited scope
funcfinder --inp Calculator.java --source java --tree --lines 1:100

# Windows-compatible sed alternative (10-50x faster than PowerShell)
funcfinder --inp server.log --lines 5000:   # From line 5000 to EOF
funcfinder --inp debug.txt --lines :1000    # First 1000 lines
funcfinder --inp trace.log --lines 500      # Single line 500

Why --lines is useful:

  • 🪟 Cross-platform: Works on Windows without sed
  • Performance: 10-50x faster than PowerShell alternatives
  • 🎯 Precision: Combine with --map/--func/--tree to narrow search scope
  • 📏 Any file: Standalone mode works on logs, configs, any text file
Integration with Other Tools
# Combine with grep/mgrep for comprehensive analysis
mgrep "authentication" api.go
funcfinder --inp api.go --source go --func AuthHandler --extract

# Get function start line in scripts
START=$(funcfinder --inp api.go --source go --func Handler --json | jq '.Handler.start')

📖 Usage

funcfinder --inp <file> [--source <lang>] [OPTIONS]

Required:
  --inp <file>       Source file to analyze
  --source <lang>    Language: go/c/cpp/cs/java/d/js/ts/py/rust/swift/kotlin/php/ruby/scala
                     (optional when using --lines alone)

Work modes (choose one):
  (default)          Find functions (default behavior)
  --struct           Find structs/classes/types instead of functions ⭐ NEW
  --all              Find both functions and structs ⭐ NEW

Search modes (choose one):
  --func <names>     Find specific functions (comma-separated)
  --type <names>     Find specific types (comma-separated, requires --struct) ⭐ NEW
  --map              Map all functions/types in file
  --tree             Display in tree format (shows class hierarchy)
  --tree-full        Display in tree format with signatures

Filtering:
  --lines <range>    Extract/filter by line range (standalone or with --source)
                     Formats: 100:150, :50, 100:, 100

Output formats:
  (default)          grep-style: name: n1-n2;
  --json             JSON format
  --extract          Extract function/type bodies

Options:
  --raw              Don't ignore raw strings in brace counting
  --version          Print version and exit
Examples of flag combinations:
# Functions (default mode)
funcfinder --inp file.go --source go --map                    # Map all functions
funcfinder --inp file.go --source go --func Handler          # Find specific function

# Structs mode
funcfinder --inp file.go --source go --struct --map          # Map all types
funcfinder --inp file.go --source go --struct --type User    # Find specific type

# Combined mode (--all requires --map, --tree, or --json)
funcfinder --inp file.go --source go --all --map             # Map functions + types
funcfinder --inp file.go --source go --all --json            # JSON with both
funcfinder --inp file.go --source go --all --extract         # Extract both

# Invalid combinations (will error)
funcfinder --inp file.go --source go --struct --all          # Mutually exclusive
funcfinder --inp file.go --source go --func foo --struct     # Can't mix modes
funcfinder --inp file.go --source go --type User             # Need --struct or --all

🎯 Token Reduction Examples

Example 1: Large Codebase Analysis

Traditional approach:

  • AI reads entire codebase: 100,000 lines = 150,000 tokens
  • Cost: $0.45 (at $0.003/1K tokens)
  • Time: Multiple AI requests, ~5-10 seconds

With funcfinder:

# 1. Get structure (280,000 lines/sec)
funcfinder --inp . --source go --map --json
  • Analysis time: 0.36 seconds for 100K lines
  • Tokens sent to AI: ~500 tokens (JSON structure)
  • Cost: $0.0015
  • Token savings: 99.67% | Cost savings: 300x | Time: faster than 1 AI request!
Example 2: Targeted Function Extraction

Traditional approach:

  • AI reads entire file: 5,000 lines = 7,500 tokens

With funcfinder:

# 1. Map functions
funcfinder --inp api.go --source go --map --json

# 2. AI selects function from structure (50 tokens)

# 3. Extract only that function
funcfinder --inp api.go --source go --func ProcessData --extract
  • Tokens used: 50 (structure) + 375 (function body) = 425 tokens
  • Token savings: 94%

🏗️ Architecture

funcfinder Core
funcfinder/
├── main.go             # CLI and coordination
├── config.go           # Unified language configuration (shared)
├── errors.go           # Standard error handling (shared)
├── sanitizer.go        # Comment/string literal handler
├── finder.go           # Function boundary detection
├── python_finder.go    # Python-specific indentation logic
├── finder_factory.go   # Language-specific finder selection
├── formatter.go        # Output formatting (grep/json/extract)
├── tree.go             # Tree visualization for classes
├── decorator.go        # Python decorator detection
└── lines.go            # Line range filtering
Shared Modules
config.go           # Loads languages.json, provides regex cache
errors.go           # FatalError, WarnError, InfoMessage, PrintVersion
languages.json      # Unified patterns for ALL utilities (embedded)
Additional Utilities
stat.go             # Uses config.go + errors.go
deps.go             # Uses config.go + errors.go
complexity.go       # Uses config.go + errors.go + finder.go
analyze.sh          # Orchestrates all utilities for full analysis

🔧 Configuration

Language patterns are defined in languages.json (embedded in binary):

{
  "go": {
    "func_pattern": "^\\s*func\\s+(\\([^)]*\\)\\s+)?(\\w+)\\s*\\(",
    "line_comment": "//",
    "block_comment_start": "/*",
    "block_comment_end": "*/",
    "string_chars": ["\""],
    "raw_string_chars": ["`"],
    "escape_char": "\\"
  }
}

🧪 Testing

Tested on:

  • Go standard library (fmt/print.go)
  • Production C# code (TELB project)
  • Real-world codebases with complex nesting
# Run tests
go test ./...

# Test on sample file
funcfinder --inp config.go --source go --map

🛠️ Additional Utilities

funcfinder поставляется с дополнительными утилитами для полного анализа кода. Все утилиты используют единую архитектуру с общими модулями конфигурации и обработки ошибок.

Quick Start
# Собрать все утилиты
./build.sh

# Полный анализ проекта одной командой
./analyze.sh

# Workflow для AI-агентов
funcfinder --inp api.go --source go --map  # Структура кода
stat api.go -l go -n 10                    # Горячие точки
deps . -l go -j                            # Граф зависимостей
complexity api.go -l go                    # Когнитивная сложность
Утилиты
Утилита Назначение Языки Выход
funcfinder Структура кода (функции, классы, границы) 11 grep/JSON/extract
stat Анализ вызовов функций + метрики файлов 11 текст
deps Анализ зависимостей модулей (stdlib/external/internal) 11 текст/JSON
complexity ⭐ NEW Анализ когнитивной сложности (nesting depth) 11 текст с цветами
🧠 complexity - Анализатор когнитивной сложности

Философия: Глубокая вложенность (nesting depth), а не количество веток — настоящая сложность кода.

⚠️ ВАЖНО: Различайте вложенные циклы (критично для производительности) и вложенные if (читаемость). См. PERFORMANCE.md для деталей.

# Анализ одного файла
complexity main.go -l go

# Анализ директории
complexity . -l go

# JSON выход для автоматизации
complexity api.py -l py --json

# Топ N самых сложных функций
complexity . -l go -n 10

Примеры вывода:

Average max complexity: 8.00
============================================================
Philosophy: Deep nesting (not branch count) is the real complexity
============================================================
#1 finder.go:238 findClassesWithOffset() depth=5 complexity=16 level=VERY_HIGH
  Lines: 44, File: finder.go

#2 finder.go:83 FindFunctionsInLines() depth=4 complexity=8 level=HIGH
  Lines: 104, File: finder.go

#3 config.go:142 GetLanguageConfig() depth=2 complexity=2 level=SIMPLE
  Lines: 7, File: config.go

============================================================
Complexity distribution (by nesting depth):
SIMPLE: 8 ██████████████ (depth ≤ 2)
MODERATE: 2 ████ (depth = 3)
HIGH: 1 ██ (depth ≥ 4)

Уровни сложности:

  • SIMPLE (depth ≤ 2) - Плоский код, легко понять
  • ⚠️ MODERATE (depth = 3) - Один уровень вложенности
  • 🔶 HIGH (depth ≥ 4) - Два+ уровня вложенности
  • 🔴 CRITICAL (depth ≥ 6) - Требуется рефакторинг

Формула: NDC = 2^(maxDepth - 1)

📊 Комплексный анализ с analyze.sh

Автоматический скрипт для полного анализа проекта:

./analyze.sh

Отчет включает:

  • 📈 Статистику по файлам (строки, размер, code/comments/blank ratio)
  • 🔍 Инвентаризацию функций (всего 85 функций в funcfinder)
  • 🔥 Горячие точки вызовов (топ функций по частоте)
  • 📦 Граф зависимостей (stdlib vs external vs internal)
  • 🧠 Распределение сложности (SIMPLE/MODERATE/HIGH/CRITICAL)
  • 💡 Рекомендации по улучшению кода

Пример отчета:

📊 Code Metrics:
  • Total files:      14
  • Total lines:      3,090
  • Total size:       84.9 KB
  • Total functions:  85
  • Avg func/file:    6.0

🎯 Code Quality:
  ✅ Excellent - Low complexity, well-structured code

═══════════════════════════════════════
Overall Complexity Distribution:
═══════════════════════════════════════
✅ SIMPLE:    13 functions (depth ≤ 2)
⚠️  MODERATE:  2 functions (depth = 3)
🔶 HIGH:      1 functions (depth ≥ 4)
🔴 CRITICAL:  0 functions (depth ≥ 6)
🏗️ Унифицированная архитектура (v1.4.0)

Все утилиты используют единые модули (DRY принцип):

funcfinder/
├── config.go          # Унифицированная конфигурация языков
├── errors.go          # Стандартная обработка ошибок
├── languages.json     # Единый источник паттернов (embedded)
├── main.go            # funcfinder CLI
├── stat.go            # Счётчик вызовов + метрики
├── deps.go            # Анализатор зависимостей
├── complexity.go      # Анализатор когнитивной сложности
├── analyze.sh         # Комплексный анализ проекта
└── build.sh           # Сборка всех утилит

Преимущества архитектуры:

  • Нулевые дубликаты - единая конфигурация для всех утилит
  • Консистентность - одинаковые сообщения об ошибках
  • Простота расширения - добавить язык = обновить JSON
  • Нулевые зависимости - все утилиты статические бинарники

Типичные сценарии:

  • 📊 Первичный анализ незнакомого кода
  • 🔍 Поиск узких мест для оптимизации
  • 🔄 Рефакторинг и поиск дублирования
  • 📈 Code review и анализ PR
  • 🤖 AI-агент навигация с минимальными токенами
  • 🧠 Оценка когнитивной сложности перед рефакторингом

🤝 Contributing

Contributions welcome! Please follow these guidelines:

How to contribute:

  • Fork the repository and create a feature branch
  • Write tests for new functionality
  • Follow existing code style and conventions
  • Submit PR with clear description

Areas for contribution:

  • Additional language support
  • Improved regex patterns
  • Performance optimizations
  • Test coverage

📊 Performance

Verified Benchmarks

Parsing throughput: 280,000 lines/sec (3.6 μs per line)

# Real-world performance (verified with benchmark tool)
100,000 lines → 0.36 seconds
280,000 lines → 1.00 second

# This means funcfinder analyzes 100K lines FASTER than a single AI API request! (~500ms)
⚡ The X-Ray and Microscope for AI

What makes funcfinder unique:

  • 🔬 X-ray vision: Scan entire codebase structure in milliseconds
  • 🔍 Microscope precision: Extract exact functions with zero noise
  • 🚀 Faster than AI requests: 100K lines in 360ms vs AI request ~500ms
  • 💰 99.67% token savings: 150,000 tokens → 500 tokens for structure

Why this matters for AI workflows:

Traditional approach (without funcfinder):
├── Read entire file: 150,000 tokens @ $0.003/1K = $0.45
├── Wait for AI processing: ~500-1000ms
└── Get answer with full file context

With funcfinder:
├── Get file structure: 0.36 seconds for 100K lines
├── Send structure to AI: 500 tokens @ $0.003/1K = $0.0015
├── AI selects function: instant
└── Extract function: <1ms
   Total: 0.36s + minimal cost (300x cheaper!)
Technical Details
  • Complexity: O(n) linear with respect to file size
  • Memory: Minimal (streaming line-by-line processing)
  • Binary size: 3MB (static, no external dependencies)
  • Platform: Cross-platform (Linux, macOS, Windows)

🗺️ Roadmap

v1.1.0 ✅
  • JavaScript/TypeScript support
  • --version flag
  • Arrow function support for JS/TS
  • Generator function support
v1.2.0 ✅
  • Python support with decorator detection
  • Async/await function support
  • Improved function detection across all languages
v1.3.0 ✅
  • Tree visualization (--tree and --tree-full)
  • Class hierarchy detection
  • Method-class association for all OOP languages
  • Rust support (structs, traits, enums, impl blocks)
  • Swift support (classes, structs, protocols, enums)
  • Kotlin, PHP, Ruby, Scala support ⭐ NEW
  • 15 languages total (added without Go code changes!)
v1.4.0 ✅
  • --lines flag for line range filtering
  • Cross-platform file slicing (sed alternative)
  • Standalone and filter modes
  • stat utility - function call counter + file metrics (15 languages)
  • deps utility - dependency analyzer (15 languages)
  • complexity utility ⭐ NEW - cognitive complexity analyzer (15 languages)
  • Unified architecture - shared config.go and errors.go (DRY principle)
  • analyze.sh - comprehensive project analysis script
  • Complete code analysis toolkit with zero dependencies
v1.5.0 (Current) ✅
  • --struct flag - Find structs/classes/types/interfaces ⭐ NEW
  • --type flag - Find specific types by name ⭐ NEW
  • --all flag - Combined mode (functions + structs) ⭐ NEW
  • EnhancedSanitizer - Multiline strings, char literals, nested comments
  • Struct pattern support for all 15 languages
  • Field extraction - Extract type fields with names and types
  • Combined JSON output - Functions and types in single response
  • Nested function support - Python, JS, TS, Go, Ruby, Scala
  • Complete code structure analysis (behavior + state)
v1.6.0
  • Configuration file support (.funcfinderrc)
  • Custom patterns via CLI
  • Improved C# regex patterns
  • Function type filters (public/private)
  • Cyclomatic complexity (as alternative to nesting depth)
  • HTML reports for analyze.sh
v2.0.0
  • Tree-sitter integration for precise parsing
  • 30+ language support
  • API server mode
  • IDE integrations

📚 Documentation

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

Built for AI-driven development workflows. Inspired by the need to minimize token usage in large codebases.

📞 Support


funcfinder - Navigate code efficiently, save tokens intelligently 🚀

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
benchmark command
complexity command
complexity.go - Nesting Depth Complexity Analyzer Analyzes code complexity based on NESTING DEPTH, not decision point count Philosophy: Deep nesting is harder to understand than flat code with many branches
complexity.go - Nesting Depth Complexity Analyzer Analyzes code complexity based on NESTING DEPTH, not decision point count Philosophy: Deep nesting is harder to understand than flat code with many branches
deps command
deps.go - Module dependency analyzer Uses shared configuration for multiple languages
deps.go - Module dependency analyzer Uses shared configuration for multiple languages
findstruct command
funcfinder command
stat command
stat.go - Unified function call counter for multiple languages Counts function calls in source files using shared configuration
stat.go - Unified function call counter for multiple languages Counts function calls in source files using shared configuration
config.go - Unified language configuration Loads and manages language patterns for funcfinder, stat, deps, complexity, and findstruct
config.go - Unified language configuration Loads and manages language patterns for funcfinder, stat, deps, complexity, and findstruct
test_structs_go.go - Test file for Go struct detection
test_structs_go.go - Test file for Go struct detection

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL