Skip to content
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

Various gem RBI LSP runner refactors #2177

Merged
merged 6 commits into from
Jan 29, 2025
Merged

Various gem RBI LSP runner refactors #2177

merged 6 commits into from
Jan 29, 2025

Conversation

paracycle
Copy link
Member

Improves the codebase

@paracycle paracycle requested a review from a team as a code owner January 29, 2025 19:39

sig { returns(Pathname) }
def lockfile
@lockfile ||= T.let(Pathname(project_path).join("Gemfile.lock"), T.nilable(Pathname))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get Bundler.with_original_env { Bundler.default_lockfile } to work in tests. If I do a Dir.chdir(@project.absolute_path) in tests, then it works fine, but the whole idea was to be cwd-independent, so not sure if we can use it or not.

At least I've extracted the method that sets up the lockfile path, so that the change can be isolated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it's not cleaning up orphaned RBIs. Did it succeed for you in core?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I don't understand, this doesn't change anything from the old code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it could be a problem with the old version. I'm just trying to make sure we aren't introducing a regression while refactoring. I'll do more tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem was that we only cleanup orphan RBIs if the lockfile hasn't changed. Which isn't correct. Not a regression.

@paracycle paracycle added refactor Code refactor with no behaviour change chore and removed refactor Code refactor with no behaviour change labels Jan 29, 2025
end

private

attr_reader :project_path

sig { returns(T::Boolean) }
sig { returns(T.nilable(T::Boolean)) }
Copy link
Contributor

@andyw8 andyw8 Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this shouldn't return a nil. The caller only needs to know if it's true or false. Feels like this is leaking an implementation detail of Process::Status.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does know if it is true or false, just not true or false.

Ruby is a simple language: Only nil and false are false values, everything else is true. That's why there is no concept of a "Boolean" in Ruby.

So, a predicate method can return any value that evaluates to true.

For example, what do you think of this code?

def valid?
  user.name && user.age
end

This is very idiomatic Ruby code, since the value value doesn't matter, as long as both booleans are satisfied, the method returns a true value. But it doesn't necessarily return true. For example, for a valid user with a name and an age, this will return the age value as the result of valid?, which is perfectly fine, since it is a true value.

Finally, I am just returning the result of status.success? which itself returns true or false or nil. If predicate methods aren't supposed to return nil, then why did Ruby choose to do that for Process::Status#success? and how is this method any different?


sig { returns(Pathname) }
def lockfile
@lockfile ||= T.let(Pathname(project_path).join("Gemfile.lock"), T.nilable(Pathname))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem was that we only cleanup orphan RBIs if the lockfile hasn't changed. Which isn't correct. Not a regression.

@paracycle paracycle merged commit baaa579 into main Jan 29, 2025
18 checks passed
@paracycle paracycle deleted the uk-improve-gem-lsp branch January 29, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants