Implement schema statements autocompletion in Active Record migrations #669
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.
Active Record migrations define
method_missingthat delegates any unknown methods to the underlying connection adapter. That means that implementing autocompletion of schema statements is mostly achieved by completing connection adapter methods.Because Active Record migrations inherit from
ActiveRecord::Migration[<version>], which is not a direct class reference, I couldn't useNodeContext#nesting, as that returns strings. I had to inspect the nesting nodes in Prism, which is available via the@nesting_nodesvariable. Maybe we could define a publicNodeContext#nesting_nodesattribute reader?I implemented a server call that returns database configurations, so that I can map the migration directory to the corresponding connection adapter, in case multiple database adapters are used.
ActiveRecord::Migrationimplements a few additional methods (e.g.reversible), and it would be nice to haveTableDefinition/AlterTablecompletion increate_table/change_tableblocks at some point, but I wanted to first tackle the primary functionality.Closes #444