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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ 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"
workspace_dependencies
else
VOID
end
Expand Down Expand Up @@ -252,6 +254,22 @@ def did_change_watched_files(changes)
VOID
end

sig { returns(T::Array[T::Hash[Symbol, T.untyped]]) }
def workspace_dependencies
definition = Bundler.definition
dep_keys = definition.locked_deps.keys.to_set
definition.specs.map do |spec|
{
name: spec.name,
version: spec.version,
path: spec.full_gem_path,
dependency: dep_keys.include?(spec.name),
}
end
rescue Bundler::GemfileNotFound
[]
end

sig { void }
def perform_initial_indexing
# The begin progress invocation happens during `initialize`, so that the notification is sent before we are
Expand Down
14 changes: 14 additions & 0 deletions test/executor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,20 @@ def test_initialize_sets_client_name
assert_equal("Foo", @store.client_name)
end

def test_workspace_dependencies
result = @executor.execute({
method: "rubyLsp/workspace/dependencies",
params: {},
})

result.response.each do |gem_info|
assert_instance_of(String, gem_info[:name])
assert_instance_of(Gem::Version, gem_info[:version])
assert_instance_of(String, gem_info[:path])
assert(gem_info[:dependency].is_a?(TrueClass) || gem_info[:dependency].is_a?(FalseClass))
end
end

private

def with_uninstalled_rubocop(&block)
Expand Down
Loading