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

Add a basic RubyLSP dependencies custom request #1346

Merged
merged 3 commits into from
Feb 5, 2024
Merged

Conversation

paracycle
Copy link
Member

@paracycle paracycle commented Feb 1, 2024

Motivation

In order to support the "Dependencies" view in VSCode, we need to add a custom request in Ruby LSP to gather and return a list of dependencies of the current project.

Implementation

Discover all direct dependencies using Bundler.definition.locked_deps and then convert all of the specs in the Bundler.definition into a list of spec name, version, path and if the spec is a direct dependency or not. The last property is useful for either sorting the view based on direct dependency vs transitive dependency, and, in the future, will also allow us to show "Remove" buttons next to direct dependencies.

Automated Tests

No tests yet

Manual Tests

Can't manually test it except for making the LSP request.

@@ -222,6 +222,16 @@ def run(request)
workspace_symbol(request.dig(:params, :query))
when "rubyLsp/textDocument/showSyntaxTree"
show_syntax_tree(uri, request.dig(:params, :range))
when "rubyLsp/workspace/dependencies"
dep_keys = Bundler.definition.locked_deps.keys.to_set
Bundler.definition.specs.map do |spec|
Copy link
Member

Choose a reason for hiding this comment

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

I think we had a few cases where definition.to_spec returns nil (e.g. #1326). Can definition.specs also contain nil?

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 don't think so, since definition.specs should map directly to the list of specs in the GEM section of a Gemfile.lock.

Btw, the issue you mention is a RubyGems issue, not a Bundler issue, whereas the calls we are making here are purely to Bundler.

@vinistock vinistock force-pushed the uk-add-bundler-view branch from 6bd90cb to a1da8a6 Compare February 2, 2024 19:47
@vinistock vinistock requested a review from st0012 February 5, 2024 15:45
@vinistock vinistock merged commit 0ac440e into main Feb 5, 2024
30 checks passed
@vinistock vinistock deleted the uk-add-bundler-view branch February 5, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants