Skip to content

Commit

Permalink
Handle names prefixed by :: when accessing index
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Aug 10, 2023
1 parent ab17bfb commit ee0d6a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def <<(entry)

sig { params(fully_qualified_name: String).returns(T.nilable(T::Array[Entry])) }
def [](fully_qualified_name)
@entries[fully_qualified_name]
@entries[fully_qualified_name.delete_prefix("::")]
end

# Try to find the entry based on the nesting from the most specific to the least specific. For example, if we have
Expand Down
20 changes: 20 additions & 0 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,25 @@ class Something

assert_nil(@index.resolve("DoesNotExist", ["Foo"]))
end

def test_accessing_with_colon_colon_prefix
RubyIndexer.index_single(@index, "/fake/path/foo.rb", <<~RUBY)
class Bar; end
module Foo
class Bar
end
class Baz
class Something
end
end
end
RUBY

entries = @index["::Foo::Baz::Something"]
refute_empty(entries)
assert_equal("Foo::Baz::Something", entries.first.name)
end
end
end

0 comments on commit ee0d6a0

Please sign in to comment.