Skip to content

Commit

Permalink
Library#locate_ref returns nil for unresolved requires (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Nov 5, 2023
1 parent 275da83 commit c19d956
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/solargraph/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def locate_pins location
api_map.locate_pins(location).map { |pin| pin.realize(api_map) }
end

# Match a require reference to a file.
#
# @param location [Location]
# @return [Location, nil]
def locate_ref location
map = source_map_hash[location.filename]
return if map.nil?
Expand All @@ -268,7 +272,7 @@ def locate_ref location
next unless source_map_hash.key?(full)
return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0))
end
# api_map.yard_map.require_reference(pin.name)
nil
rescue FileNotFoundError
nil
end
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/workspace/app.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require 'not_a_file'

thing = Thing.new
thing.do_thing
11 changes: 11 additions & 0 deletions spec/library_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,17 @@ def bar; end
expect(library.current).to be_nil
end

describe '#locate_ref' do
it 'returns nil without a matching reference location' do
workspace = File.absolute_path(File.join('spec', 'fixtures', 'workspace'))
library = Solargraph::Library.load(workspace)
library.map!
location = Solargraph::Location.new(File.join(workspace, 'app.rb'), Solargraph::Range.from_to(0, 8, 0, 8))
found = library.locate_ref(location)
expect(found).to be_nil
end
end

context 'unsynchronized' do
let(:library) { Solargraph::Library.load File.absolute_path(File.join('spec', 'fixtures', 'workspace')) }
let(:good_file) { File.join(library.workspace.directory, 'lib', 'thing.rb') }
Expand Down

0 comments on commit c19d956

Please sign in to comment.