fix(loaders): keep recording sources across a nested lua-load - #1451
Open
Chiarandini wants to merge 1 commit into
Open
fix(loaders): keep recording sources across a nested lua-load#1451Chiarandini wants to merge 1 commit into
Chiarandini wants to merge 1 commit into
Conversation
`_luasnip_load_file` puts `__luasnip_get_loaded_file_frame_debuginfo` into the global environment before running a snippet-file and set it back to nil afterwards. The function is re-entrant, so the inner call cleared the getter for the outer file as well, and every snippet the outer file defined after that point was stored without a source. Re-entering is ordinary: a snippet-file that requires a module from a plugin loaded on demand runs that plugin's setup mid-file, and a setup that registers its own collection loads a file. The result is that `ls.snippet_source.get` returns nil, so `snip_location` cannot jump to the definition and anything else built on sources sees a gap it cannot explain. Save the previous value and restore it instead of clearing. The getter itself already resolves the right frame by walking the stack for the nearest `_luasnip_load_file`, so nesting needs nothing further.
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.
Problem
With
loaders_store_source = true, snippets defined past a certain point in a lua snippet-file are stored with no source, sols.snippet_source.getreturnsnilandextras.snip_locationcannot jump to their definition. Which file loses its sources varies between runs, which makes it read like flakiness rather than a rule.Cause
_luasnip_load_fileputs__luasnip_get_loaded_file_frame_debuginfointo the global environment before running a snippet-file, and sets it back tonilafterwards. The function is re-entrant, so an inner load clears the getter for the outer file as well, and every snippet the outer file defines after that point is stored without a source.Re-entering is ordinary rather than exotic: a snippet-file that requires a module from a plugin loaded on demand runs that plugin's setup mid-file, and a setup that registers its own collection loads a file.
Fix
Save the previous value and restore it, instead of clearing unconditionally.
get_loaded_file_debuginfoalready resolves the correct frame by walking the stack for the nearest_luasnip_load_file, so nesting needs nothing further.Test
tests/integration/source_spec.luagains a case backed by two fixture collections. The outer file defines a snippet, triggers a load of the inner collection while it is still executing, then defines another. Before the change the second snippet has no source; after it, both do.Fails on
master, passes with the fix, andloaders_specstays at 58/58.🤖 Generated with Claude Code