Locate a Swift symbol's source declaration
swiftGetSymbolDefinitionLocate the file and line where a Swift symbol is declared using regex and SourceKit-LSP, returning the position even when LSP fails. Navigate from class names in memory graphs to source files.
Instructions
[mg.code] Find the file:line where a Swift symbol (class, struct, enum, protocol, func, var, etc.) is declared. Pre-scans candidatePaths (or hint.filePath) with a fast regex first, then asks SourceKit-LSP for jump-to-definition. Returns the position even when LSP can't follow through. Use after findRetainers / classifyCycle surface a class name from a memgraph cycle to land in the actual source file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbolName | Yes | Name of the Swift symbol to locate (class, struct, enum, protocol, func, var, etc.). | |
| hint | No | Optional hint to speed up the search. `filePath` skips the project scan; `module` is reserved for future multi-module work. | |
| projectRoot | No | Override the project root. Default discovers the nearest Package.swift / .xcodeproj / .xcworkspace from the cwd. | |
| candidatePaths | No | If provided, search these files for the symbol declaration before asking SourceKit-LSP. Speeds up location when the agent already has a guess (e.g. from `findSymbolReferences` or `swift_search_pattern`). |