-
Notifications
You must be signed in to change notification settings - Fork 156
Skip gem RBI check when sorbet/rbi/gems does not exist #2330
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
Open
alexcrocha
wants to merge
2
commits into
main
Choose a base branch
from
ar/skip-run-rbi-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,26 @@ class RunGemRbiCheckSpec < SpecWithProject | |
|
|
||
| assert_project_file_exist("sorbet/rbi/gems/[email protected]") | ||
| end | ||
|
|
||
| it "respects custom gem directory" do | ||
| FileUtils.mkdir_p("#{@project.absolute_path}/custom/gem/dir") | ||
|
|
||
| foo = mock_gem("foo", "0.0.1") do | ||
| write!("lib/foo.rb", FOO_RB) | ||
| end | ||
| @project.require_mock_gem(foo) | ||
| @project.bundle_install! | ||
|
|
||
| FileUtils.touch("#{@project.absolute_path}/custom/gem/dir/[email protected]") | ||
|
|
||
| check = ::RubyLsp::Tapioca::RunGemRbiCheck.new(@project.absolute_path, "custom/gem/dir") | ||
| check.run | ||
|
|
||
| refute_project_file_exist("custom/gem/dir/[email protected]") | ||
| assert_project_file_exist("custom/gem/dir/[email protected]") | ||
|
|
||
| @project.remove!("custom") | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
Oops, something went wrong.
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.
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 am not sure I understand why this method is needed? The CLI command should be transparently get the correct value of the gem rbi directory as part of the CLI command
options. That needs to be passed down here, not read the config from scratch.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.
This is triggered by the Ruby LSP through the activate method. At this point we haven't shelled out to the Tapioca gem command yet, and the config hasn't been parsed by CLI.
Before we shell out, we need to do some cleanup. When we detect deleted or lingering RBIs (through git commands) we either restore them or delete the new ones, source.
We can either duplicate the config processing here in the add-on, or move this cleanup to the Tapioca gem command to be triggered optionally in add-on mode.
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.
The gem RBI command does that kind of clean up automatically anyway, so I am not even sure what these git operations are trying to do.
I think doing this outside of the gem RBI command is asking for trouble. I don't think we should be doing any config parsing, or relying on constant values to assume anything about where RBI files live, or which ones should be cleaned up, etc.
All that logic already exists. Please tell me what's missing that all this is needed.
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.
The tapioca gem command only runs when we detect lockfile differences. However, consider this scenario:
bundle installtapioca gem <gems>doesn't run, leaving orphaned RBI files or missing previously deleted onesThis is where the git operations come in: they clean up orphaned RBIs and restore deleted ones. While I understand the concern about duplicating logic, the add-on and CLI run in separate processes, so we must read the configuration independently.
We did consider the alternative of running
tapioca gemon every activation to simplify this. However, we decided against it due to the potential negative impact on developer experience. For instance, if a developer pullsmainand the latest commit didn't include updated gem RBIs, the add-on would immediately generate gem RBIs for files they didn't touch, polluting their workspace. We felt it was better to avoid this.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.
But the gem command can clean up stale RBI files and create RBI files that should exist as well. I still don't understand why this level of detection needs to happen outside of the normal Tapioca gem RBI generation. We should be able to find a way to make the gem RBI generation to be smarter about this.
I don't think we want to try to duplicate the logic of configuration files, etc, outside of that flow. That won't scale.
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.
This scenario is exactly why the git based detection is not a great idea in the first place, and not a good reason to add more complexity to this. There is no good way to synchronize the state of RBI files with the state of the lockfile changes.