Skip to content

Commit 6d194f9

Browse files
committed
Add RubyLSP indexing enhancement for register_element
1 parent 2f4b364 commit 6d194f9

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 => element_name], *]
35+
@listener.add_method(element_name, location, [
36+
RubyIndexer::Entry::Signature.new([
37+
RubyIndexer::Entry::KeywordRestParameter.new(name: :attributes),
38+
RubyIndexer::Entry::BlockParameter.new(name: :content),
39+
]),
40+
], visibility: :public)
41+
end
42+
end
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)