line_context
Read meaningful source context around exact file and line locations.
Use line_context for diagnostics, logs, search hits, stack traces, or user-provided file:line references when you need the containing source items and parent hierarchy.
Use when
- You know exact files and 1-based lines but not the containing symbol.
- You need context around up to 32 related locations.
Do not use when
- You already know an exact range; use
smart_read. - You need to resolve a visible identifier; use
jump.
Request
{"locations":[{"file":"/workspace/project/src/lib.rs","line":42},{"file":"/workspace/project/src/api.rs","line":118}]}Batch related locations: an entire failing test run's frames fit in one call.
Parameters
| Field | Required | Default / bounds |
|---|---|---|
locations | yes | 1–32 entries; each line is a 1-based integer ≥ 1. |
locations[].file | yes | Non-empty path (file_path is not the nested field name). |
include_docs | no | false. |
output_mode | no | type_annotated; union: type_annotated, plain_text, both. |
workspace_root | no | Only needed when multiple workspaces are active. |
What it returns
Complete meaningful source items or document sections containing each location, including parent hierarchy. Type-annotated output falls back to plain text with a per-range note when inlay hints are unavailable.
Example
Real output — given only runtime.rs:98, the complete containing function comes back:
saved vs reading full file: 7.3 KB -> 1011 B (87% fewer bytes)
## "context-engine-server/src/connector/runtime.rs" (line 98)
context: impl ConnectorRuntime { ... }
90| pub(crate) fn new(
91| registration: RegisteredConnector,
92| http_client: reqwest::Client,
93| use_legacy_schema: bool,
94| ) -> Self {
95| let (_, request_capability/*: String*/, http_addr/*: SocketAddr*/, lease/*: ConnectorLease*/) = registration.into_parts();
96| let endpoint/*: Arc<str>*/ = endpoint(/*address: */http_addr);
98| let upstream/*: UpstreamClient*/ = UpstreamClient::new(The function boundary is the parser's decision, not a guess — and line 95 shows types the raw source cannot: the element types of a destructured tuple, resolved by the language server.
Common mistakes
- Sending zero-based lines or quoting the line number.
- Sending more than 32 locations in one request.
- Enabling
include_docswhen documentation is not needed.
Related tools
smart_readreads exact ranges when the boundary is already known.jumpresolves identifiers found in the returned context.hoverinspects one identifier without reading its container.outlinemaps the whole file instead of one location.