Skip to main content
POST
/
tools
/
get_references
Get References
curl --request POST \
  --url https://api.example.com/tools/get_references
{
  "locations": [
    {
      "uri": "<string>",
      "range": {
        "start": {},
        "end": {}
      }
    }
  ],
  "totalCount": 123
}

Overview

Find every place in your workspace where a symbol (function, class, variable, etc.) is referenced. This is essential for understanding symbol usage, refactoring, and impact analysis.

Request

uri
string
required
File URI (e.g., file:///workspace/main.py)
line
number
required
Line number (0-indexed)
character
number
required
Character position (0-indexed)
includeDeclaration
boolean
default:"true"
Include the declaration/definition in results

Response

locations
array
Array of all reference locations
totalCount
number
Total number of references found

Example Request

curl -X POST https://api.pylancemcp.dev/v1/tools/call \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "get_references",
    "arguments": {
      "uri": "file:///workspace/app/utils.py",
      "line": 8,
      "character": 4,
      "includeDeclaration": true
    }
  }'

Example Response

{
  "locations": [
    {
      "uri": "file:///workspace/app/utils.py",
      "range": {
        "start": { "line": 8, "character": 4 },
        "end": { "line": 8, "character": 19 }
      }
    },
    {
      "uri": "file:///workspace/app/views.py",
      "range": {
        "start": { "line": 42, "character": 12 },
        "end": { "line": 42, "character": 27 }
      }
    },
    {
      "uri": "file:///workspace/app/views.py",
      "range": {
        "start": { "line": 87, "character": 8 },
        "end": { "line": 87, "character": 23 }
      }
    },
    {
      "uri": "file:///workspace/tests/test_utils.py",
      "range": {
        "start": { "line": 15, "character": 16 },
        "end": { "line": 15, "character": 31 }
      }
    }
  ],
  "totalCount": 4
}

Use Cases

Before Refactoring

# Find all uses of calculate_total before renaming or modifying it
def calculate_total(items: List[Item]) -> float:
#   ^^^^^^^^^^^^^^
# Get references: Find 47 uses across 12 files

# Now you can safely refactor knowing the impact

Understand Function Usage

# Where is this helper function actually used?
def format_currency(amount: float) -> str:
    return f"${amount:.2f}"

# Get references: Shows it's used in 3 different views

Find Unused Code

# Is this function still needed?
def legacy_calculation(data: dict) -> int:
    pass

# Get references: 0 results
# Safe to delete!

Track Variable Usage

# Where is this configuration used?
MAX_RETRIES = 5
# ^^^^^^^^^^^
# Get references: Used in retry logic across 8 files

Reference Types

References are found in various contexts:
ContextExample
Function callscalculate_total(items)
Importsfrom utils import calculate_total
Assignmentsfunc = calculate_total
Type hintsdef process(calc: Callable = calculate_total)
Decorators@calculate_total
String referencesNot included (only code references)

Filtering Results

Results are ordered by file path, then by line number within each file.

Include/Exclude Declaration

# With includeDeclaration: true
# Results include:
# 1. def calculate_total(...) [definition]
# 2. calculate_total(items)   [usage 1]
# 3. calculate_total(data)    [usage 2]

# With includeDeclaration: false
# Results include:
# 1. calculate_total(items)   [usage 1]
# 2. calculate_total(data)    [usage 2]

Performance Tips

Large Projects: First reference search may take 1-2 seconds while indexing workspace
Cache Results: Reference locations don’t change unless code changes
Use Filters: Exclude test files if you only care about production usage

Analyzing Results

Group references by file to understand impact:
from collections import defaultdict

references_by_file = defaultdict(list)
for location in references.locations:
    file_path = location.uri.split('/')[-1]
    references_by_file[file_path].append(location)

# Show which files use this symbol most
for file, refs in sorted(references_by_file.items(), 
                         key=lambda x: len(x[1]), 
                         reverse=True):
    print(f"{file}: {len(refs)} references")

Error Responses

CodeReasonSolution
FILE_NOT_FOUNDFile doesn’t existVerify file path
INVALID_POSITIONPosition out of boundsCheck line/character values
NO_SYMBOL_FOUNDNo symbol at positionPosition cursor on a valid symbol
WORKSPACE_NOT_INDEXEDWorkspace still indexingWait for indexing to complete
TIMEOUTSearch took too longTry narrowing search scope

Rate Limits

TierRequests/HourRequests/DayMax Results
Free1050100
Hobby2502,5001,000
Pro2,50025,00010,000
EnterpriseUnlimitedUnlimitedUnlimited
Large projects may return thousands of references. Consider pagination for better performance.