Skip to content

Commit 9920154

Browse files
authored
Add RubyLSP indexing enhancement for register_element (#907)
1 parent 2f4b364 commit 9920154

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/phlex.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
module Phlex
88
Loader = Zeitwerk::Loader.for_gem.tap do |loader|
9+
loader.ignore("#{__dir__}/ruby_lsp")
10+
911
loader.inflector.inflect(
1012
"csv" => "CSV",
1113
"fifo" => "FIFO",

lib/ruby_lsp/phlex/addon.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require "ruby_lsp/addon"
4+
5+
module RubyLsp
6+
module Phlex
7+
class Addon < ::RubyLsp::Addon
8+
def activate(global_state, message_queue)
9+
end
10+
11+
def deactivate
12+
end
13+
14+
def name
15+
"Phlex"
16+
end
17+
18+
def version
19+
"0.1.0"
20+
end
21+
end
22+
23+
class IndexingEnhancement < RubyIndexer::Enhancement
24+
def on_call_node_enter(node)
25+
name = node.name
26+
owner = @listener.current_owner
27+
location = node.location
28+
arguments = node.arguments&.arguments
29+
30+
return unless owner
31+
return unless :register_element == name
32+
33+
case arguments
34+
in [Prism::SymbolNode[unescaped: String => method_name], *]
35+
tag_name = method_name.tr("_", "-")
36+
arguments[1] in Prism::StringNode[unescaped: String => tag_name]
37+
38+
@listener.add_method(method_name, location, [
39+
RubyIndexer::Entry::Signature.new([
40+
RubyIndexer::Entry::KeywordRestParameter.new(name: :attributes),
41+
RubyIndexer::Entry::BlockParameter.new(name: :content),
42+
]),
43+
], visibility: :public, comments: "Outputs a `<#{tag_name}>` tag.")
44+
end
45+
end
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)