feat: exclude globs and extra PHP extensions for indexing - #311
Open
syntlyx wants to merge 3 commits into
Open
Conversation
Scanned file paths are canonicalized while the vendor directory was stored raw-only, so on a workspace whose real path goes through a symlink (macOS /var -> /private/var, link-farm checkouts) vendor files never prefix-matched the vendor directory. Hover lost the package provenance badge, completion ranked vendor classes as project symbols, and vendor service providers were scanned as if they were user code. add_vendor_dir now records the canonical path alongside the raw one, mirroring what the vendor URI prefixes already do. The analyse CLI had the mirror-image bug: it canonicalized each walked entry but compared against the raw vendor path, so analyse descended into the whole vendor tree. The skip list is now canonicalized too.
Add `[indexing] exclude` and `[indexing] extensions` to `.phpantom.toml`. Exclude patterns use gitignore semantics relative to the workspace root and are honored by every workspace walker (the fallback full scan, PSR-4 and vendor scans, the Drupal web-root scan, the preload and go-to-implementation walkers) and by the file watcher, so generated code and test fixtures stay out of the index. Extra extensions let non-.php PHP source (e.g. Drupal's .module, .inc, .theme) be discovered by background scans outside the Drupal-specific directories, with matching file watchers so those files refresh the index on change. Patterns compile once into classmap_scanner::IndexFilters, cached on the Backend and invalidated on config reload, so no glob compilation happens per file. Gitignore matching (GitignoreBuilder) was chosen over the ignore crate's Override, whose whitelist-first semantics would invert an exclude list containing `!` re-includes. This ships the server side of backlog item X9; the item now tracks the remaining client-side work of forwarding the editor's files.exclude / files.associations settings to the server. Refs PHPantom-dev#48
The Drupal web-root scanner skipped every directory named tests/ or Tests/ to avoid duplicate fixture classes. But module tests extend base classes that live under core/tests/ (Drupal\Tests\UnitTestCase, Drupal\KernelTests\KernelTestBase, ...) and reference test modules under */tests/modules/, and the gitignore-aware workspace scan never reaches core/ either, so every module test file reported "Class 'Drupal\Tests\UnitTestCase' not found". Index test directories by default: the classmap's first-wins merge already handles duplicate fixture FQNs, and projects that want a smaller index can trim it with the new [indexing] exclude setting instead of a hardcoded name filter. Refs PHPantom-dev#48
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each commit is one logical change and carries its own description:
fix: classify vendor files correctly under a symlinked workspace rootfeat: exclude globs and extra PHP extensions for indexingfix: index Drupal test directories so test base classes resolveSummary
Ships the server side of backlog item X9 (
docs/todo/indexing.md): user-configurable file filters for workspace discovery.exclude— patterns in gitignore syntax relative to the workspace root: a bare name matches at any depth, a pattern containing/anchors to the root, a trailing/restricts to directories, a leading!re-includes. Honored by every workspace walker (fallback full scan, PSR-4/vendor scans, the Drupal web-root scan, preload, go-to-implementation) and by the file watcher, so events for excluded paths are dropped too. Excludes apply to background discovery only — files opened in the editor are always served.extensions— extra file extensions (without the dot) treated as PHP source, e.g. Drupal's.module/.inc/.themeoutside the auto-detected web root. Each gets its owndidChangeWatchedFileswatcher so edits refresh the index.Implementation notes
classmap_scanner::IndexFilters(backed byignore::gitignore::GitignoreBuilder), cached on theBackend, invalidated on config reload — no glob compilation on any per-file path. Empty config is a singleOptionbranch in the walkers, so the default configuration costs nothing.GitignoreBuilderwas chosen overignore'sOverride:Override's whitelist-first semantics would invert the meaning of an exclude list containing!re-includes.[[diagnostics.ignore]]), never failing config load.config-schema.jsonanddocs/configuration.mdupdated; changelog entry added.files.exclude/files.associationsfrom the editor extensions to the server (initializationOptions/workspace/configuration), which needs client-side work.Bundled fixes (separate commits)
Drupal test base classes resolve. The Drupal web-root scanner skipped every directory named
tests/Tests, but module tests extend base classes that live undercore/tests/(Drupal\Tests\UnitTestCase,Drupal\KernelTests\KernelTestBase, …), and the gitignore-aware workspace scan never reachescore/either — so on a real Drupal project every module test reportedClass 'Drupal\Tests\UnitTestCase' not found(very visible now that workspace-wide diagnostics are on by default). Test directories are indexed by default; the classmap's first-wins merge handles duplicate fixture FQNs, and[indexing] excludereplaces the hardcoded name filter for projects that want a smaller index.Vendor classification under a symlinked workspace root. Pre-existing bug reproducible on clean
main: on a workspace whose real path goes through a symlink (macOS/var→/private/var, link-farm checkouts), vendor files were classified as project code — hover lost the package provenance badge, vendor providers were scanned as user code, and theanalyseCLI walked the entire vendor tree. Scanned paths are canonicalized but the vendor dir was stored raw-only;add_vendor_dirnow records the canonical form alongside the raw one (mirroring what the vendor URI prefixes already do), andanalyse's skip list is canonicalized. Fixes 4 tests that fail on any macOS checkout ofmain.Testing
!re-includes, invalid-pattern skip, extension normalization)..modulefiles discovered viaextensions.cargo clippy -D warnings,cargo fmt, and the full test suite pass; both commits build and pass independently (bisect-safe).Refs #48
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,examples/)config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.