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

fix: support find require xxx.rb in local workspace. #722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions lib/solargraph/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/solargraph/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/solargraph/yard_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading