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

Function build_throws_import_edits

src/completion/phpdoc/generation.rs:1861–1904  ·  view source on GitHub ↗

Build additional text edits for auto-importing exception types referenced in `@throws` tags.

(
    content: &str,
    position: Position,
    use_map: &HashMap<String, String>,
    file_namespace: &Option<String>,
    context: &DocblockContext,
    class_loader: &dyn Fn(&str) -> Option<Arc<Cl

Source from the content-addressed store, hash-verified

1859/// Build additional text edits for auto-importing exception types
1860/// referenced in `@throws` tags.
1861fn build_throws_import_edits(
1862 content: &str,
1863 position: Position,
1864 use_map: &HashMap<String, String>,
1865 file_namespace: &Option<String>,
1866 context: &DocblockContext,
1867 class_loader: &dyn Fn(&str) -> Option<Arc<ClassInfo>>,
1868 function_loader: FunctionLoader<'_>,
1869) -> Vec<TextEdit> {
1870 if !matches!(context, DocblockContext::FunctionOrMethod) {
1871 return Vec::new();
1872 }
1873
1874 let throws_ctx = ThrowsContext {
1875 class_loader,
1876 function_loader,
1877 use_map,
1878 file_namespace,
1879 };
1880 let uncaught = throws_analysis::find_uncaught_throw_types_with_context(
1881 content,
1882 position,
1883 Some(&throws_ctx),
1884 );
1885 if uncaught.is_empty() {
1886 return Vec::new();
1887 }
1888
1889 let use_block = analyze_use_block(content);
1890 let mut edits = Vec::new();
1891
1892 for exc in &uncaught {
1893 // Exception types are already resolved to FQNs by
1894 // `find_uncaught_throw_types_with_context` — do not re-resolve.
1895 let fqn = exc.to_string();
1896 if !throws_analysis::has_use_import(content, &fqn)
1897 && let Some(edit) = build_use_edit(&fqn, &use_block, file_namespace)
1898 {
1899 edits.extend(edit);
1900 }
1901 }
1902
1903 edits
1904}
1905
1906// ─── Tests ──────────────────────────────────────────────────────────────────
1907

Callers 2

try_generate_docblockFunction · 0.85

Calls 6

analyze_use_blockFunction · 0.85
has_use_importFunction · 0.85
build_use_editFunction · 0.85
extendMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected