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

WIP: [Tapioca Addon] Support gem RBI generation #2063

Draft
wants to merge 2 commits into
base: tapioca-addon-feature-branch
Choose a base branch
from

Conversation

alexcrocha
Copy link

WIP

This Draft PR is still a work in progress.

Motivation

To support gem RBI generation, we needed a way to detect changes in Gemfile.lock. Currently, changes to this file cause the Ruby LSP to restart, resulting in loss of access to any previous state information. This limitation prevents monitoring and processing of gem changes.

Implementation

To address this, a snapshot file of Gemfile.lock is created to persist data across server restarts. Upon restart, both the snapshot and the current Gemfile.lock are parsed using Bundler::LockfileParser. If differences are detected, the relevant gem names and specifications are extracted, allowing us to then trigger the gem RBI generation.

This implementation handles gem additions, spec changes, and gem removals.

Tests

@alexcrocha alexcrocha added the enhancement New feature or request label Oct 31, 2024
@vinistock
Copy link
Member

Independent of the code changes themselves, I still have doubts about the UX here. Take this scenario for example:

  1. You are working on a branch developing some feature
  2. Now, you need to rebase your branch on the latest main
  3. The latest main has lockfile changes, but those weren't accompanied by the necessary RBI updates
  4. After the rebase, the LSP will immediately generate gem RBIs that are completely unrelated to your work, resulting in untracked changes

I believe we need to try to come up with a strategy to be able to tell if the current developer made the update to the lockfile vs it being updated by something else (like git pull/switching branches/rebasing). Otherwise, it will result in a pretty annoying experience to constantly get unrelated changes.

Maybe, we could remember the launch timestamp of the add-on. When the lockfile is updated, it will trigger a restart and then the add-on can check if the update to the lockfile happened after the previous launch (which should indicate that the current developer made the update). I don't know, there might be better options on how to achieve this.

@alexcrocha
Copy link
Author

@vinistock, thanks for pointing this out. I agree that the current behaviour could quickly become frustrating, especially when rebasing and getting unrelated gem RBIs.

I appreciate your suggestion about using the launch timestamp of the add-on to distinguish between lockfile updates made by the developer and those from other actions. I'll experiment with that idea and explore other strategies. Your feedback has given me a lot to think about.

Thanks again for your input!

To support gem RBI generation, we needed a way to detect changes in
Gemfile.lock. Currently, changes to this file cause the Ruby LSP to
restart, resulting in loss of access to any previous state information.

By creating a snapshot of Gemfile.lock, we can persist data across
server restarts. Upon restart, we parse both the snapshot and current
Gemfile.lock using Bundler::LockfileParser. If differences are found,
we extract the relevant gem names and specifications, allowing us to
trigger the gem RBI generation.
Skip gem RBI generation by comparing the last modified times of the
Gemfile and Gemfile.lock. If both files are modified within a fraction
of a second of each other, it is likely due to a git operation, and gem
RBI generation can be skipped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants