diff --git a/lib/solargraph/library.rb b/lib/solargraph/library.rb index dff701cb..4dd9b9ba 100644 --- a/lib/solargraph/library.rb +++ b/lib/solargraph/library.rb @@ -267,10 +267,15 @@ def locate_ref location return if map.nil? pin = map.requires.select { |p| p.location.range.contain?(location.range.start) }.first return nil if pin.nil? + return_if_match = proc do |full| + if source_map_hash.key?(full) + return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0)) + end + end workspace.require_paths.each do |path| - full = Pathname.new(path).join("#{pin.name}.rb").to_s - next unless source_map_hash.key?(full) - return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0)) + full = File.join path, pin.name + return_if_match.(full) + return_if_match.(full << ".rb") end nil rescue FileNotFoundError @@ -481,10 +486,12 @@ def source_map_external_require_hash def find_external_requires source_map new_set = source_map.requires.map(&:name).to_set # return if new_set == source_map_external_require_hash[source_map.filename] + _filenames = nil + filenames = ->{ _filenames ||= workspace.filenames.to_set } source_map_external_require_hash[source_map.filename] = new_set.reject do |path| workspace.require_paths.any? do |base| - full = Pathname.new(base).join("#{path}.rb").to_s - workspace.filenames.include?(full) + full = File.join(base, path) + filenames[].include?(full) or filenames[].include?(full << ".rb") end end @external_requires = nil diff --git a/lib/solargraph/workspace.rb b/lib/solargraph/workspace.rb index 7efadf6f..c8ab2ed4 100644 --- a/lib/solargraph/workspace.rb +++ b/lib/solargraph/workspace.rb @@ -104,7 +104,8 @@ def source filename # @return [Boolean] def would_require? path require_paths.each do |rp| - return true if File.exist?(File.join(rp, "#{path}.rb")) + full = File.join rp, path + return true if File.exist?(full) or File.exist?(full << ".rb") end false end diff --git a/lib/solargraph/yard_map.rb b/lib/solargraph/yard_map.rb index 89208a2b..6b118764 100755 --- a/lib/solargraph/yard_map.rb +++ b/lib/solargraph/yard_map.rb @@ -120,8 +120,9 @@ def require_reference path # @type [Gem::Specification] spec = spec_for_require(path) spec.full_require_paths.each do |rp| - file = File.join(rp, "#{path}.rb") - next unless File.file?(file) + file = File.join(rp, path) + file = [file, file + ".rb"].find { |file| File.file?(file) } + next unless file return Solargraph::Location.new(file, Solargraph::Range.from_to(0, 0, 0, 0)) end nil