Skip to content

Add RubyLSP indexing enhancement for register_element #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/phlex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

module Phlex
Loader = Zeitwerk::Loader.for_gem.tap do |loader|
loader.ignore("#{__dir__}/ruby_lsp")

loader.inflector.inflect(
"csv" => "CSV",
"fifo" => "FIFO",
Expand Down
48 changes: 48 additions & 0 deletions lib/ruby_lsp/phlex/addon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require "ruby_lsp/addon"

module RubyLsp
module Phlex
class Addon < ::RubyLsp::Addon
def activate(global_state, message_queue)
end

def deactivate
end

def name
"Phlex"
end

def version
"0.1.0"
end
end

class IndexingEnhancement < RubyIndexer::Enhancement
def on_call_node_enter(node)
name = node.name
owner = @listener.current_owner
location = node.location
arguments = node.arguments&.arguments

return unless owner
return unless :register_element == name

case arguments
in [Prism::SymbolNode[unescaped: String => method_name], *]
tag_name = method_name.tr("_", "-")
arguments[1] in Prism::StringNode[unescaped: String => tag_name]

@listener.add_method(method_name, location, [
RubyIndexer::Entry::Signature.new([
RubyIndexer::Entry::KeywordRestParameter.new(name: :attributes),
RubyIndexer::Entry::BlockParameter.new(name: :content),
]),
], visibility: :public, comments: "Outputs a `<#{tag_name}>` tag.")
end
end
end
end
end