MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / with_file_content

Method with_file_content

src/server.rs:1381–1408  ·  view source on GitHub ↗

Fetch the open-file content for `uri`, run `f` inside a panic guard, and return the result. Returns `None` when the file is not open or when `f` panics. Most LSP handlers follow the pattern "get content, run handler with panic protection, return result" — this helper captures that boilerplate in one place.

(
        &self,
        handler_name: &str,
        uri: &str,
        position: Option<Position>,
        f: impl FnOnce(&str, Option<Position>) -> T,
    )

Source from the content-addressed store, hash-verified

1379 /// with panic protection, return result" — this helper captures
1380 /// that boilerplate in one place.
1381 pub(crate) fn with_file_content<T>(
1382 &self,
1383 handler_name: &str,
1384 uri: &str,
1385 position: Option<Position>,
1386 f: impl FnOnce(&str, Option<Position>) -> T,
1387 ) -> Option<T> {
1388 let mut content = self.get_file_content(uri)?;
1389 let mut pos = position;
1390
1391 // If this is a Blade file, use the virtual PHP content and translate the position.
1392 if self.is_blade_file(uri)
1393 && let Some(virtual_content) = self.blade_virtual_content.read().get(uri)
1394 {
1395 content = virtual_content.clone();
1396 if let Some(p) = position {
1397 pos = Some(self.translate_blade_to_php(uri, p));
1398 }
1399 }
1400
1401 // Activate the chain resolution cache so that shared chain prefixes
1402 // (e.g. `$model->where(...)` in `$model->where(...)->orderBy(...)`)
1403 // are resolved once and reused across all LSP handlers, not just
1404 // diagnostics. The guard is re-entrant safe: if a diagnostic pass
1405 // already activated the cache, this is a no-op.
1406 let _chain_guard = crate::completion::resolver::with_chain_resolution_cache();
1407 crate::util::catch_panic_unwind_safe(handler_name, uri, pos, || f(&content, pos))
1408 }
1409
1410 /// Position-based handler helper. Extracts the URI and position from
1411 /// the params, fetches file content, runs the closure inside a panic

Callers 3

inlay_hint_requestMethod · 0.80
handle_with_positionMethod · 0.80
handle_with_uriMethod · 0.80

Calls 7

catch_panic_unwind_safeFunction · 0.85
get_file_contentMethod · 0.80
is_blade_fileMethod · 0.80
cloneMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected