Skip to content
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
11 changes: 9 additions & 2 deletions lib/ruby_lsp/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ def load_addons(global_state, outgoing_queue, include_project_addons: true)
addon_files = Gem.find_files("ruby_lsp/**/addon.rb")

if include_project_addons
bundle_path = Bundler.bundle_path.to_s
bundle_path = begin
Bundler.bundle_path.to_s
rescue Bundler::GemfileNotFound
nil
end

project_addons = Dir.glob("#{global_state.workspace_path}/**/ruby_lsp/**/addon.rb")
project_addons.reject! { |path| path.start_with?(bundle_path) || gem_installation_path?(path) }
project_addons.reject! do |path|
(bundle_path && path.start_with?(bundle_path)) || gem_installation_path?(path)
end

addon_files.concat(project_addons)
end
Expand Down
33 changes: 33 additions & 0 deletions test/addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,39 @@ def version
end
end

def test_loading_project_addons_when_the_project_has_no_gemfile
Dir.mktmpdir do |dir|
addon_dir = File.join(dir, "lib", "ruby_lsp", "test_addon")
FileUtils.mkdir_p(addon_dir)
File.write(File.join(addon_dir, "addon.rb"), <<~RUBY)
class NoGemfileProjectAddon < RubyLsp::Addon
def activate(global_state, outgoing_queue)
end

def name
"No Gemfile Project Addon"
end

def version
"0.1.0"
end
end
RUBY

@global_state.apply_options({
workspaceFolders: [{ uri: URI::Generic.from_path(path: dir).to_s }],
})

# Projects without a Gemfile have no bundle path at all and asking Bundler for one raises
Bundler.stubs(:bundle_path).raises(Bundler::GemfileNotFound)

Addon.load_addons(@global_state, @outgoing_queue)

addon = Addon.get("No Gemfile Project Addon", "0.1.0")
assert_equal("No Gemfile Project Addon", addon.name)
end
end

def test_loading_project_addons_ignores_bundle_path
Dir.mktmpdir do |dir|
addon_dir = File.join(dir, "vendor", "bundle", "ruby_lsp", "test_addon")
Expand Down
Loading