diff --git a/lib/ruby_indexer/lib/ruby_indexer/entry.rb b/lib/ruby_indexer/lib/ruby_indexer/entry.rb index f1a3de424..f5e7a3687 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/entry.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/entry.rb @@ -11,7 +11,7 @@ class Entry sig { returns(String) } attr_reader :file_path - sig { returns(Prism::Location) } + sig { returns(RubyIndexer::Location) } attr_reader :location sig { returns(T::Array[String]) } @@ -20,13 +20,33 @@ class Entry sig { returns(Symbol) } attr_accessor :visibility - sig { params(name: String, file_path: String, location: Prism::Location, comments: T::Array[String]).void } + sig do + params( + name: String, + file_path: String, + location: T.any(Prism::Location, RubyIndexer::Location), + comments: T::Array[String], + ).void + end def initialize(name, file_path, location, comments) @name = name @file_path = file_path - @location = location @comments = comments @visibility = T.let(:public, Symbol) + + @location = T.let( + if location.is_a?(Prism::Location) + Location.new( + location.start_line, + location.end_line, + location.start_column, + location.end_column, + ) + else + location + end, + RubyIndexer::Location, + ) end sig { returns(String) } @@ -50,7 +70,7 @@ class Namespace < Entry params( name: String, file_path: String, - location: Prism::Location, + location: T.any(Prism::Location, RubyIndexer::Location), comments: T::Array[String], ).void end @@ -81,7 +101,7 @@ class Class < Namespace params( name: String, file_path: String, - location: Prism::Location, + location: T.any(Prism::Location, RubyIndexer::Location), comments: T::Array[String], parent_class: T.nilable(String), ).void @@ -181,7 +201,7 @@ class Member < Entry params( name: String, file_path: String, - location: Prism::Location, + location: T.any(Prism::Location, RubyIndexer::Location), comments: T::Array[String], owner: T.nilable(Entry::Namespace), ).void @@ -219,7 +239,7 @@ class Method < Member params( name: String, file_path: String, - location: Prism::Location, + location: T.any(Prism::Location, RubyIndexer::Location), comments: T::Array[String], parameters_node: T.nilable(Prism::ParametersNode), owner: T.nilable(Entry::Namespace), @@ -349,7 +369,7 @@ class UnresolvedAlias < Entry nesting: T::Array[String], name: String, file_path: String, - location: Prism::Location, + location: T.any(Prism::Location, RubyIndexer::Location), comments: T::Array[String], ).void end diff --git a/lib/ruby_indexer/lib/ruby_indexer/location.rb b/lib/ruby_indexer/lib/ruby_indexer/location.rb new file mode 100644 index 000000000..5b8366227 --- /dev/null +++ b/lib/ruby_indexer/lib/ruby_indexer/location.rb @@ -0,0 +1,26 @@ +# typed: strict +# frozen_string_literal: true + +module RubyIndexer + class Location + extend T::Sig + + sig { returns(Integer) } + attr_reader :start_line, :end_line, :start_column, :end_column + + sig do + params( + start_line: Integer, + end_line: Integer, + start_column: Integer, + end_column: Integer, + ).void + end + def initialize(start_line, end_line, start_column, end_column) + @start_line = start_line + @end_line = end_line + @start_column = start_column + @end_column = end_column + end + end +end diff --git a/lib/ruby_indexer/ruby_indexer.rb b/lib/ruby_indexer/ruby_indexer.rb index adf45ed74..ee5af2dc6 100644 --- a/lib/ruby_indexer/ruby_indexer.rb +++ b/lib/ruby_indexer/ruby_indexer.rb @@ -10,6 +10,7 @@ require "ruby_indexer/lib/ruby_indexer/entry" require "ruby_indexer/lib/ruby_indexer/configuration" require "ruby_indexer/lib/ruby_indexer/prefix_tree" +require "ruby_indexer/lib/ruby_indexer/location" module RubyIndexer @configuration = T.let(Configuration.new, Configuration)