-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for running Rails generators from the UI #2257
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it works well in Rails projects. But I wouldn't expect the dropdown to show in IRB, which won't be able to run either commands anyway.
Since we now also have addon information, can we raise a warning when the Rails generate/destroy commands got triggered, but the addons list doesn't include Ruby LSP Rails
?
![Screenshot 2024-07-04 at 21 59 22](https://private-user-images.githubusercontent.com/5079556/345950480-7acd11b7-326e-4fca-b836-d291d78f2c88.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAzODkxMDEsIm5iZiI6MTcyMDM4ODgwMSwicGF0aCI6Ii81MDc5NTU2LzM0NTk1MDQ4MC03YWNkMTFiNy0zMjZlLTRmY2EtYjgzNi1kMjkxZDc4ZjJjODgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDdUMjE0NjQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTgyNGNmNTQ5MmFiNGJlMzkyMzFhNmQxMGI2YjY2NmUxMjExYTk5Yzc4MDkxOWU5OGFhYWNhYzJlOTQ4NDFkMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.ndhOdXXubOP2Dau--t0Dtv_Gp4943da8PBNPzBtkw5E)
Similar to what @st0012 mentioned, it is a bit awkward that we'll be showing these commands for non-Rails codebases, especially if we add more Rails commands in future. I'm looking at the available things we can do in the https://code.visualstudio.com/api/references/when-clause-contexts |
When generate a
|
a56eac7
to
ba85b4f
Compare
I thought that if you try run a generator where some files already exist, Rails would interactively prompt to ask whether to overwrite each file, but I can't seem to trigger it. Maybe the behaviour changed in a more recent Rails version. |
Fixed it! Thanks for pointing that out. Regarding not showing the button, that will become pretty complex given that you could have one workspace that is a Rails app and another one that isn't. There's no when clause that will tell you which workspace explorer view you are hovering over as far as I know. So I propose we do something different. We always show the button, but then hide the Rails commands if the workspace is not a Rails app (which is significantly more straight forward). To start out, so that we don't show an empty quick pick to users, I can follow up with a PR to add a This is common in IDEs, so it would be a nice feature to have and then we can move forward with a much simpler approach that won't require trying to figure out which workspace folder is being hovered over. Thoughts? |
Motivation
This PR adds a Rails class to our VS Code extension capable of running generators from the UI. This is useful on its own, but it is also necessary for other functionality that may want to invoke generators programatically.
Implementation
I split the work into two commits:
Rails
class with agenerate
anddestroy
command and associate both with commandsRuby file operations
command, where we can aggregate all of these under the same menu item. Then expose it in the explorer title and menu contextAutomated Tests
Added tests.
Manual Tests
Screen.Recording.2024-07-04.at.4.01.24.PM.mov