Class: Steep::Services::HoverProvider::RBS
- Defined in:
- lib/steep/services/hover_provider/rbs.rb
Constant Summary collapse
- TypeAliasContent =
_ = Struct.new(:location, :decl, keyword_init: true)
- ClassContent =
_ = Struct.new(:location, :decl, keyword_init: true)
- InterfaceContent =
_ = Struct.new(:location, :decl, keyword_init: true)
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
- #content_for(target:, path:, line:, column:) ⇒ Object
- #content_for_type_name(type_name, env:, location:) ⇒ Object
-
#initialize(service:) ⇒ RBS
constructor
A new instance of RBS.
- #project ⇒ Object
Constructor Details
#initialize(service:) ⇒ RBS
Returns a new instance of RBS.
11 12 13 |
# File 'lib/steep/services/hover_provider/rbs.rb', line 11 def initialize(service:) @service = service end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
9 10 11 |
# File 'lib/steep/services/hover_provider/rbs.rb', line 9 def service @service end |
Instance Method Details
#content_for(target:, path:, line:, column:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/steep/services/hover_provider/rbs.rb', line 19 def content_for(target:, path:, line:, column:) service = self.service.signature_services.fetch(target.name) env = service.latest_env buffer = env.buffers.find {|buf| buf.name.to_s == path.to_s } or return (dirs, decls = env.signatures[buffer]) or raise locator = ::RBS::Locator.new(buffer: buffer, dirs: dirs, decls: decls) loc_key, path = locator.find2(line: line, column: column) || return head, *_tail = path case head when ::RBS::Types::Alias content_for_type_name(head.name, env: env, location: head.location || raise) when ::RBS::Types::ClassInstance, ::RBS::Types::ClassSingleton if loc_key == :name location = head.location&.[](:name) or raise content_for_type_name(head.name, env: env, location: location) end when ::RBS::Types::Interface location = head.location&.[](:name) or raise content_for_type_name(head.name, env: env, location: location) when ::RBS::AST::Declarations::ClassAlias, ::RBS::AST::Declarations::ModuleAlias if loc_key == :old_name location = head.location&.[](:old_name) or raise content_for_type_name(head.old_name, env: env, location: location) end when ::RBS::AST::Directives::Use::SingleClause if loc_key == :type_name location = head.location&.[](:type_name) or raise content_for_type_name(head.type_name.absolute!, env: env, location: location) end when ::RBS::AST::Directives::Use::WildcardClause if loc_key == :namespace location = head.location&.[](:namespace) or raise content_for_type_name(head.namespace.to_type_name.absolute!, env: env, location: location) end end end |
#content_for_type_name(type_name, env:, location:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/steep/services/hover_provider/rbs.rb', line 64 def content_for_type_name(type_name, env:, location:) case when type_name.alias? alias_decl = env.type_alias_decls[type_name]&.decl or return TypeAliasContent.new(location: location, decl: alias_decl) when type_name.interface? interface_decl = env.interface_decls[type_name]&.decl or return InterfaceContent.new(location: location, decl: interface_decl) when type_name.class? class_entry = env.module_class_entry(type_name) or return case class_entry when ::RBS::Environment::ClassEntry, ::RBS::Environment::ModuleEntry class_decl = class_entry.primary.decl when ::RBS::Environment::ClassAliasEntry, ::RBS::Environment::ModuleAliasEntry class_decl = class_entry.decl end ClassContent.new(location: location, decl: class_decl) end end |
#project ⇒ Object
15 16 17 |
# File 'lib/steep/services/hover_provider/rbs.rb', line 15 def project service.project end |