Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Python Function ReferencesNew to Visual Studio Code? Get it now.
Python Function References

Python Function References

Onur Berk Töre

| (0) | Free
Shows reference counts for Python functions with hover details
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Python Function References

A VS Code/Cursor extension that analyzes Python functions and displays reference counts with detailed hover information.

Features

  • Function Reference Counting: Automatically scans all Python files in your workspace and counts how many times each function is referenced
  • Inline Decorations: Shows reference counts directly next to function definitions
  • Hover Details: Hover over function definitions to see exactly where they are called
  • Real-time Updates: Automatically refreshes when Python files are saved
  • Workspace-wide Analysis: Recursively searches all Python files in your workspace

How It Works

  1. The extension scans all .py files in your workspace recursively
  2. It identifies function definitions using regex pattern matching
  3. For each function, it searches for references (function calls) across all Python files
  4. Reference counts are displayed inline next to function definitions
  5. Hover over a function definition to see detailed information about where it's called

Usage

Automatic Analysis

  • The extension automatically activates when you open a Python file
  • It will scan your entire workspace and display reference counts
  • Reference counts update automatically when you save Python files

Manual Commands

  • Refresh References: Use Ctrl+Shift+P → "Refresh Python Function References" to manually refresh
  • Toggle Extension: Use Ctrl+Shift+P → "Toggle Python Function References" to enable/disable

Visual Indicators

  • Reference counts appear in gray text after function definitions
  • Green text indicates functions with references
  • Gray text indicates functions with no references
  • Hover over any function definition to see detailed reference locations

Configuration

Access settings via File > Preferences > Settings and search for "Python Function References":

  • pythonFunctionRefs.enabled: Enable/disable the extension (default: true)
  • pythonFunctionRefs.refreshOnSave: Auto-refresh when Python files are saved (default: true)

Installation for Local Testing

  1. Clone/Download this extension to your local machine
  2. Install Dependencies:
    npm install
    
  3. Compile TypeScript:
    npm run compile
    
  4. Install Extension:
    • Open VS Code/Cursor
    • Go to Extensions view (Ctrl+Shift+X)
    • Click the ... menu and select "Install from VSIX..."
    • Or use Command Palette (Ctrl+Shift+P) → "Extensions: Install from VSIX..."
    • Navigate to the extension folder and select the generated .vsix file (after packaging)

Development

Building the Extension

# Install dependencies
npm install

# Compile TypeScript
npm run compile

# Watch for changes during development
npm run watch

Packaging for Distribution

# Install vsce globally
npm install -g vsce

# Package the extension
vsce package

This will create a .vsix file that can be shared and installed.

Testing

  1. Open the extension folder in VS Code/Cursor
  2. Press F5 to launch a new Extension Development Host window
  3. Open a Python project in the new window
  4. The extension should automatically activate and show function reference counts

How It Identifies Functions

The extension uses regex pattern matching to identify Python function definitions:

  • Matches def function_name( patterns
  • Ignores private functions starting with _ (except special methods like __init__)
  • Captures function name, file location, and line number

How It Counts References

Reference counting uses simple pattern matching:

  • Searches for function_name( patterns across all Python files
  • Excludes the line where the function is defined
  • Stores reference location (file, line, context) for hover display

Limitations

  • Uses regex-based parsing (not AST), so may have edge cases with complex code
  • Only detects direct function calls, not dynamic calls or imports
  • Private functions (starting with _) are ignored by default
  • May not handle all Python syntax edge cases

Contributing

Feel free to submit issues and enhancement requests!

License

MIT License - see LICENSE file for details.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft