MCPcopy
hub / github.com/oraios/serena / request_referencing_symbols

Method request_referencing_symbols

src/solidlsp/ls.py:2338–2494  ·  view source on GitHub ↗

Finds all symbols that reference the symbol at the given location. This is similar to request_references but filters to only include symbols (functions, methods, classes, etc.) that reference the target symbol. :param relative_file_path: The relative path to the fil

(
        self,
        relative_file_path: str,
        line: int,
        column: int,
        include_imports: bool = True,
        include_self: bool = False,
        include_body: bool = False,
        include_file_symbols: bool = False,
    )

Source from the content-addressed store, hash-verified

2336 return factory.create_symbol_body(symbol)
2337
2338 def request_referencing_symbols(
2339 self,
2340 relative_file_path: str,
2341 line: int,
2342 column: int,
2343 include_imports: bool = True,
2344 include_self: bool = False,
2345 include_body: bool = False,
2346 include_file_symbols: bool = False,
2347 ) -> list[ReferenceInSymbol]:
2348 """
2349 Finds all symbols that reference the symbol at the given location.
2350 This is similar to request_references but filters to only include symbols
2351 (functions, methods, classes, etc.) that reference the target symbol.
2352
2353 :param relative_file_path: The relative path to the file.
2354 :param line: The 0-indexed line number.
2355 :param column: The 0-indexed column number.
2356 :param include_imports: whether to also include imports as references.
2357 Unfortunately, the LSP does not have an import type, so the references corresponding to imports
2358 will not be easily distinguishable from definitions.
2359 :param include_self: whether to include the references that is the "input symbol" itself.
2360 Only has an effect if the relative_file_path, line and column point to a symbol, for example a definition.
2361 :param include_body: whether to include the body of the symbols in the result.
2362 :param include_file_symbols: whether to include references that are file symbols. This
2363 is often a fallback mechanism for when the reference cannot be resolved to a symbol.
2364 :return: List of objects containing the symbol and the location of the reference.
2365 """
2366 if not self.server_started:
2367 log.error("request_referencing_symbols called before Language Server started")
2368 raise SolidLSPException("Language Server not started")
2369
2370 # First, get all references to the symbol
2371 references = self.request_references(relative_file_path, line, column)
2372 if not references:
2373 return []
2374
2375 debug_enabled = log.isEnabledFor(logging.DEBUG)
2376 t0_loop = perf_counter() if debug_enabled else 0.0
2377 # For each reference, find the containing symbol
2378 result = []
2379 incoming_symbol = None
2380 for ref in references:
2381 ref_path = ref["relativePath"]
2382 assert ref_path is not None
2383 ref_line = ref["range"]["start"]["line"]
2384 ref_col = ref["range"]["start"]["character"]
2385
2386 with self.open_file(ref_path) as file_data:
2387 body_factory = SymbolBodyFactory(file_data)
2388
2389 # Get the containing symbol for this reference
2390 containing_symbol = self.request_containing_symbol(
2391 ref_path, ref_line, ref_col, include_body=include_body, body_factory=body_factory
2392 )
2393 if containing_symbol is None:
2394 # TODO: HORRIBLE HACK! I don't know how to do it better for now...
2395 # THIS IS BOUND TO BREAK IN MANY CASES! IT IS ALSO SPECIFIC TO PYTHON!

Calls 13

request_referencesMethod · 0.95
open_fileMethod · 0.95
_path_contains_dotsMethod · 0.95
_resolve_file_uriMethod · 0.95
create_symbol_bodyMethod · 0.95
SolidLSPExceptionClass · 0.90
SymbolBodyFactoryClass · 0.85
ReferenceInSymbolClass · 0.85
iter_symbolsMethod · 0.80