Class: RubyLsp::RailsPartial::PartialResolver
- Inherits:
-
Object
- Object
- RubyLsp::RailsPartial::PartialResolver
- Defined in:
- lib/ruby_lsp/ruby_lsp_rails_partial/partial_resolver.rb
Overview
Resolves the partial reference string of a ‘render` call to a PartialIndex key. Because resolution depends on the reference form and on the context of “which file the render is called from”, this class is responsible only for bridging to the index’s normalized key.
Instance Method Summary collapse
-
#completion_candidates ⇒ Object
Returns completion candidates as an array of [key (path form), representative path].
-
#initialize(index, views_path) ⇒ PartialResolver
constructor
A new instance of PartialResolver.
-
#resolve(reference, current_uri) ⇒ Object
Resolves a partial reference string (“foo” / “dir/foo”) in the context of the current file and returns the array of absolute paths of the matching partial files.
-
#resolve_without_context(reference) ⇒ Object
For contexts without a uri (hover).
Constructor Details
#initialize(index, views_path) ⇒ PartialResolver
Returns a new instance of PartialResolver.
10 11 12 13 |
# File 'lib/ruby_lsp/ruby_lsp_rails_partial/partial_resolver.rb', line 10 def initialize(index, views_path) @index = index @views_path = views_path end |
Instance Method Details
#completion_candidates ⇒ Object
Returns completion candidates as an array of [key (path form), representative path]. The key is always the normalized path form so that the display label, filter text, and inserted text all match, which keeps the item past the client-side filter regardless of how the user typed the reference.
36 37 38 |
# File 'lib/ruby_lsp/ruby_lsp_rails_partial/partial_resolver.rb', line 36 def completion_candidates @index.all_entries.map { |key, paths| [key, paths.first] } end |
#resolve(reference, current_uri) ⇒ Object
Resolves a partial reference string (“foo” / “dir/foo”) in the context of the current file and returns the array of absolute paths of the matching partial files.
17 18 19 20 21 22 |
# File 'lib/ruby_lsp/ruby_lsp_rails_partial/partial_resolver.rb', line 17 def resolve(reference, current_uri) key = key_for(reference, current_uri) return [] unless key @index.lookup(key) end |
#resolve_without_context(reference) ⇒ Object
For contexts without a uri (hover). Only resolves references that contain a slash. Bare names are out of scope (they need a uri for directory inference) and return [].
26 27 28 29 30 |
# File 'lib/ruby_lsp/ruby_lsp_rails_partial/partial_resolver.rb', line 26 def resolve_without_context(reference) return [] unless reference.include?("/") @index.lookup(reference) end |