find_symbol
Search and retrieve symbols like classes or methods within a single file using a name path pattern. Specify depth to include children and restrict searches with paths, file/directory filters, or symbol kinds.
Instructions
Retrieves information on all symbols/code entities (classes, methods, etc.) based on the given name_path
,
which represents a pattern for the symbol's path within the symbol tree of a single file.
The returned symbol location can be used for edits or further queries.
Specify depth > 0
to retrieve children (e.g., methods of a class).
The matching behavior is determined by the structure of name_path
, which can
either be a simple name (e.g. "method") or a name path like "class/method" (relative name path)
or "/class/method" (absolute name path). Note that the name path is not a path in the file system
but rather a path in the symbol tree within a single file. Thus, file or directory names should never
be included in the name_path
. For restricting the search to a single file or directory,
the within_relative_path
parameter should be used instead. The retrieved symbols' name_path
attribute
will always be composed of symbol names, never file or directory names.
Key aspects of the name path matching behavior:
- Trailing slashes in
name_path
play no role and are ignored. - The name of the retrieved symbols will match (either exactly or as a substring)
the last segment of
name_path
, while other segments will restrict the search to symbols that have a desired sequence of ancestors. - If there is no starting or intermediate slash in
name_path
, there is no restriction on the ancestor symbols. For example, passingmethod
will match against symbols with name paths likemethod
,class/method
,class/nested_class/method
, etc. - If
name_path
contains a/
but doesn't start with a/
, the matching is restricted to symbols with the same ancestors as the last segment ofname_path
. For example, passingclass/method
will match againstclass/method
as well asnested_class/class/method
but notmethod
. - If
name_path
starts with a/
, it will be treated as an absolute name path pattern, meaning that the first segment of it must match the first segment of the symbol's name path. For example, passing/class
will match only against top-level symbols likeclass
but not againstnested_class/class
. Passing/class/method
will match againstclass/method
but notnested_class/class/method
ormethod
. Returns JSON string: a list of symbols (with locations) matching the name.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
depth | No | Depth to retrieve descendants (e.g., 1 for class methods/attributes). | |
exclude_kinds | No | Optional. List of LSP symbol kind integers to exclude. Takes precedence over `include_kinds`. | |
include_body | No | If True, include the symbol's source code. Use judiciously. | |
include_kinds | No | Optional. List of LSP symbol kind integers to include. (e.g., 5 for Class, 12 for Function). Valid kinds: 1=file, 2=module, 3=namespace, 4=package, 5=class, 6=method, 7=property, 8=field, 9=constructor, 10=enum, 11=interface, 12=function, 13=variable, 14=constant, 15=string, 16=number, 17=boolean, 18=array, 19=object, 20=key, 21=null, 22=enum member, 23=struct, 24=event, 25=operator, 26=type parameter. | |
max_answer_chars | No | Max characters for the JSON result. If exceeded, no content is returned. | |
name_path | Yes | The name path pattern to search for, see above for details. | |
relative_path | No | Optional. Restrict search to this file or directory. If None, searches entire codebase. If a directory is passed, the search will be restricted to the files in that directory. If a file is passed, the search will be restricted to that file. If you have some knowledge about the codebase, you should use this parameter, as it will significantly speed up the search as well as reduce the number of results. | |
substring_matching | No | If True, use substring matching for the last segment of `name`. |