-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
6,738 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyIndexer | ||
class IndexRbs | ||
extend T::Sig | ||
|
||
sig { params(index: Index).void } | ||
def initialize(index) | ||
@index = index | ||
end | ||
|
||
sig { void } | ||
def index_core_classes | ||
loader = RBS::EnvironmentLoader.new | ||
RBS::Environment.from_loader(loader).resolve_type_names | ||
|
||
loader.each_signature do |source, pathname, _buffer, declarations, _directives| | ||
process_signature(source, pathname, declarations) | ||
end | ||
end | ||
|
||
private | ||
|
||
sig { params(source: T.untyped, pathname: Pathname, declarations: T::Array[RBS::AST::Declarations::Base]).void } | ||
def process_signature(source, pathname, declarations) | ||
declarations.each do |declaration| | ||
process_declaration(declaration, pathname) | ||
end | ||
end | ||
|
||
sig { params(declaration: RBS::AST::Declarations::Base, pathname: Pathname).void } | ||
def process_declaration(declaration, pathname) | ||
return unless declaration.is_a?(RBS::AST::Declarations::Class) | ||
|
||
nesting = [declaration.name.name.to_s] | ||
file_path = pathname.to_s | ||
location = RubyIndexer::Location.from_rbs_location(declaration.location) | ||
comments = Array(declaration.comment&.string&.lines) | ||
parent_class = nil | ||
class_entry = Entry::Class.new(nesting, file_path, location, comments, parent_class) | ||
@index << class_entry | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require_relative "test_case" | ||
|
||
module RubyIndexer | ||
class IndexRbsTest < TestCase | ||
def setup | ||
@index = RubyIndexer::Index.new | ||
IndexRbs.new(@index).index_core_classes | ||
end | ||
|
||
def test_index_core_classes | ||
entries = @index["String"] | ||
refute_nil(entries) | ||
assert_equal(1, entries.length) | ||
entry = entries.first | ||
assert_match(%r{/gems/rbs-.*/core/string.rbs}, entry.file_path) | ||
assert_equal("string.rbs", entry.file_name) | ||
|
||
# Using fixed positions would be fragile, so let's just check some basics. | ||
assert_operator(entry.location.start_line, :>, 0) | ||
assert_operator(entry.location.end_line, :>, entry.location.start_line) | ||
assert_equal(0, entry.location.start_column) | ||
assert_operator(entry.location.end_column, :>, 0) | ||
|
||
assert(@index.instance_variable_get(:@entries).key?("String")) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.