From 6bd90cbd9663fcd8591d0f802d438167ff37641d Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 2 Feb 2024 14:45:16 -0500 Subject: [PATCH] Prevent workspace dependencies from failing on missing bundle --- lib/ruby_lsp/executor.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/ruby_lsp/executor.rb b/lib/ruby_lsp/executor.rb index 642c5bff99..c97535fd16 100644 --- a/lib/ruby_lsp/executor.rb +++ b/lib/ruby_lsp/executor.rb @@ -223,15 +223,7 @@ def run(request) 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| - { - name: spec.name, - version: spec.version, - path: spec.full_gem_path, - dependency: dep_keys.include?(spec.name), - } - end + workspace_dependencies else VOID end @@ -262,6 +254,21 @@ def did_change_watched_files(changes) VOID end + 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