feat(laravel): go-to-definition for view, route, and translation keys#101
Merged
Merged
Conversation
…upport Change resolve_definition (and the underlying resolve_from_symbol / resolve_laravel_string_key) from Option<Location> to Vec<Location> so go-to-definition can point to multiple files — required by translation keys that live in one file per locale. All existing features (Variable, Member, Class, Config …) are adapted to wrap their single result in vec![]; behaviour is unchanged. server.rs now returns GotoDefinitionResponse::Scalar for one result, ::Array for many, and None for zero.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #101 +/- ##
==========================================
- Coverage 86.58% 86.57% -0.02%
==========================================
Files 168 171 +3
Lines 108128 108531 +403
==========================================
+ Hits 93622 93956 +334
- Misses 14506 14575 +69 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add go-to-definition and find-references for three Laravel string-key
navigation patterns:
- view('name') / View::make('name') / View::exists('name')
→ jumps to the Blade template file
- route('name') / Route::group(['as'=>'prefix.'], ...)
→ jumps to the route() / ->name() declaration, including nested group
prefix resolution (both fluent chain and array form)
- __('key') / trans('key') / trans_choice('key') / Lang::get('key')
→ jumps to every locale file that defines the key (multiple results
via the Vec<Location> foundation from the previous PR)
Implementation follows the established LaravelStringKind pattern:
extraction in symbol_map/extraction.rs, resolution in dedicated
view_names/route_names/trans_keys modules, find-references reusing
find_string_key_usages() over the pre-built symbol map (zero re-parse).
2f9616f to
67b009e
Compare
Collaborator
This ons is particularly nice imo |
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.
Summary
Adds Go-to-Definition for Laravel view names, route names, and translation keys, plus Find References for translation keys across all locale files. Users can now
Ctrl+Clickonview('admin.users.index'),route('admin.users.create'),__('auth.failed'), etc. and jump directly to the corresponding Blade template, route declaration, or translation array entry.Changes
view()/View::make()— resolves dot-notation names to.blade.phpfiles underresources/views/route()— scans route files, resolves->name('...')declarations including nested route group name prefixes (both fluent->name('prefix.')chains andRoute::group(['as' => ...])static arrays)__()/trans()/trans_choice()/Lang::get()— maps dot-notation keys to the exact array entry in translation files, falling back to line 0 when key is absentresolve_definition()return type fromOption<Location>toVec<Location>to support multi-target jumpsLaravelStringKindenum withView,Route, andTransvariants; extraction now records these spans at parse time alongside the existingConfigvariantHow It Works
Extraction (parse time) —
extraction.rsrecognises call expressions likeview(...),route(...),__()and tags them asSymbolKind::LaravelStringKey { kind, key }spans in the symbol map. No work is done at request time.Go-to-Definition —
resolve_definition()matchesLaravelStringKey→ delegates tolaravel::resolve_laravel_string_key(backend, kind, key)→ dispatches to the appropriate module:view_names::resolve_view_definitions— converts'admin.users.index'→resources/views/admin/users/index.blade.php, scans symbol map for matching file suffixroute_names::resolve_route_definitions— walks route file ASTs, tracks accumulated group name prefix via recursivescan_group_body()/chain_name_prefix(), matches when prefix + local name equals the targettrans_keys::resolve_trans_definitions— parses translation PHP files, walks nested array assignments, collects dot-joined key paths, returns the line of the matching entryFind References —
find_laravel_string_key_references()scans pre-builtsymbol_map.spansforLaravelStringKey { kind, key }entries. Zero file re-parses per call, consistent with the cross-file scanner rule.Route group prefix resolution —
route_names.rshandles both forms:Route::prefix('/admin')->name('admin.')->middleware(...)->group(fn() { ... })Route::group(['as' => 'admin.', 'prefix' => '/admin'], fn() { ... })Why Core Library Was Modified
resolve_definition()return type changed fromOption<Location>toVec<Location>insrc/definition/resolve.rs. This was needed because a view name can resolve to multiple file paths (e.g., both.blade.phpand.phpvariants), and route group structures can in principle yield multiple declaration sites. All existing call sites were updated to handle theVec— existing single-target definitions (class, method, config) simply wrap their result invec![...].Tests
tests/integration/definition_laravel.rs— new test functions:test_goto_definition_laravel_view_simple—view('welcome')→resources/views/welcome.blade.phptest_goto_definition_laravel_view_nested—view('admin.users.index')→ nested directory pathtest_goto_definition_laravel_view_facade—View::make('dashboard')facade formtest_goto_definition_laravel_route_simple—route('home')→->name('home')declarationtest_goto_definition_laravel_route_dotted—route('admin.users.create')with dotted nametest_goto_definition_laravel_route_group_name_prefix— fluent->name('prefix.')group chaintest_goto_definition_laravel_route_nested_group_prefix— two levels of nested groupstest_goto_definition_laravel_route_static_group_call—Route::group(fn() { ... })without prefixtest_goto_definition_laravel_route_static_group_with_as_prefix—Route::group(['as' => 'admin.'])array formtest_goto_definition_laravel_route_in_subdirectory— route file located underroutes/api/test_goto_definition_laravel_trans_basic—__('messages.welcome')→ array entry inlang/en/messages.phptest_goto_definition_laravel_trans_lang_facade—Lang::get('auth.failed')facade formtest_goto_definition_laravel_trans_nested_key— nested array key'errors.required'tests/integration/references_laravel_trans.rs:test_find_references_laravel_trans_lists_all_locales—__('auth.failed')find-references returns usages from bothenandzh-TWlocale PHP files without re-parsing