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

Function collect_php_files_gitignore

src/util.rs:274–314  ·  view source on GitHub ↗

Recursively collect all `.php` files under a workspace root, respecting `.gitignore` rules (including nested and global gitignore files). Used by Find References which walks the entire workspace root. Unlike [`collect_php_files`], this uses the `ignore` crate's [`WalkBuilder`] so that generated/cached directories listed in `.gitignore` (e.g. `storage/framework/views/`, `var/cache/`, `node_modules

(
    root: &Path,
    vendor_dir_paths: &[PathBuf],
)

Source from the content-addressed store, hash-verified

272/// Hidden files and directories are skipped by default (handled by
273/// the `ignore` crate).
274pub(crate) fn collect_php_files_gitignore(
275 root: &Path,
276 vendor_dir_paths: &[PathBuf],
277) -> Vec<PathBuf> {
278 use ignore::WalkBuilder;
279
280 let mut result = Vec::new();
281 let vendor_paths_owned: Vec<PathBuf> = vendor_dir_paths.to_vec();
282
283 let walker = WalkBuilder::new(root)
284 // Respect .gitignore, .git/info/exclude, global gitignore
285 .git_ignore(true)
286 .git_global(true)
287 .git_exclude(true)
288 // Skip hidden files/dirs (.git, .idea, etc.)
289 .hidden(true)
290 // Read parent .gitignore files
291 .parents(true)
292 // Also respect .ignore files (ripgrep convention)
293 .ignore(true)
294 // Always skip vendor directories, even if not gitignored
295 .filter_entry(move |entry| {
296 if entry.file_type().is_some_and(|ft| ft.is_dir()) {
297 let path = entry.path();
298 if vendor_paths_owned.iter().any(|vp| vp == path) {
299 return false;
300 }
301 }
302 true
303 })
304 .build();
305
306 for entry in walker.flatten() {
307 let path = entry.path();
308 if path.is_file() && path.extension().is_some_and(|ext| ext == "php") {
309 result.push(path.to_path_buf());
310 }
311 }
312
313 result
314}
315
316/// Convert a byte offset in `content` to an LSP `Position` (line, character).
317///

Callers 1

Calls 3

buildMethod · 0.80
iterMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected