ruby-lsp-view_component 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -2
- data/lib/ruby_lsp/ruby_lsp_view_component/code_lens.rb +22 -12
- data/lib/ruby_lsp_view_component/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 311ae0434d3d08918eab99a1817e1d2448d737e5088bb627c5f58e0bb1347c9c
|
|
4
|
+
data.tar.gz: 11b21df73cdf7d6e5a3c515bd5849cf85eb79982e064dc13d999cf8f5b18fd9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33462a033067359f7f4ca3f27b0c29126c680a9fedb0ee068882cf10b4996a4f742fa58f1007fd0217bed0d65f9206be1224375fb231a5810dddcc20addb716d
|
|
7
|
+
data.tar.gz: c64141716d8f327e77e3c2989ad895a860c031c464358d8e1499a7c04611ae4312fb090125c68aad2308d24b2bd8c5fb7db32e44438de53b460749f27b4451d7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.0]
|
|
4
|
+
|
|
5
|
+
- `Jump to template` opens the inherited templates of a component without its own: those of the nearest ancestor that has them, unless a class in between defines `call`.
|
|
6
|
+
|
|
3
7
|
## [0.2.1]
|
|
4
8
|
|
|
5
9
|
- Drop the gemspec dependency on `ruby-lsp`. The add-on still declares `~> 0.26.0` with `depend_on_ruby_lsp!`, so a newer Ruby LSP no longer blocks `bundle update`: the add-on skips activation with a warning until it supports that version.
|
data/README.md
CHANGED
|
@@ -25,9 +25,13 @@ For `app/components/foo_component.rb` with all of these templates, the lens list
|
|
|
25
25
|
|
|
26
26
|
ERB, Haml and Slim templates are supported. Templates of nested components in the subdirectory, such as `foo_component/item_component.html.erb` next to `foo_component/item_component.rb`, belong to that component and are left out.
|
|
27
27
|
|
|
28
|
+
### Inherited template
|
|
29
|
+
|
|
30
|
+
A component without templates of its own [inherits](https://viewcomponent.org/guide/templates.html#inherited) them from its parent class. The lens opens the templates of the nearest ancestor that has them, unless a class in between defines `call`.
|
|
31
|
+
|
|
28
32
|
### Missing template
|
|
29
33
|
|
|
30
|
-
When a component needs a template and has none, the lens opens `foo_component.html.erb` next to the class. VS Code reports that the file does not exist and offers a **Create File** button. Once the file exists, the same lens opens it.
|
|
34
|
+
When a component needs a template and has none, not even an inherited one, the lens opens `foo_component.html.erb` next to the class. VS Code reports that the file does not exist and offers a **Create File** button. Once the file exists, the same lens opens it.
|
|
31
35
|
|
|
32
36
|

|
|
33
37
|
|
|
@@ -35,7 +39,6 @@ A component counts as needing a template only when it renders through a template
|
|
|
35
39
|
|
|
36
40
|
- define [`call`](https://viewcomponent.org/guide/templates.html#call), themselves or in a parent class
|
|
37
41
|
- declare an [inline template](https://viewcomponent.org/guide/templates.html#inline) with `erb_template`, `haml_template` or `slim_template`
|
|
38
|
-
- [inherit](https://viewcomponent.org/guide/templates.html#inherited) a template from a parent class
|
|
39
42
|
- are marked `abstract!`
|
|
40
43
|
|
|
41
44
|
A base class that is never rendered on its own still gets the lens. Mark it `abstract!` to hide it.
|
|
@@ -41,7 +41,7 @@ module RubyLsp
|
|
|
41
41
|
|
|
42
42
|
path = @path #: as !nil
|
|
43
43
|
paths = templates(path)
|
|
44
|
-
paths =
|
|
44
|
+
paths = fallback_templates(node, path) if paths.empty?
|
|
45
45
|
return if paths.empty?
|
|
46
46
|
|
|
47
47
|
@response_builder << create_code_lens(
|
|
@@ -55,25 +55,35 @@ module RubyLsp
|
|
|
55
55
|
|
|
56
56
|
private
|
|
57
57
|
|
|
58
|
-
#: (Prism::ClassNode) ->
|
|
59
|
-
def
|
|
58
|
+
#: (Prism::ClassNode, String) -> Array[String]
|
|
59
|
+
def fallback_templates(node, path)
|
|
60
|
+
return [] if declares_no_template?(node)
|
|
61
|
+
|
|
60
62
|
name = [*@nesting, node.constant_path.slice].join("::").delete_prefix("::")
|
|
61
63
|
ancestors = @index.linearized_ancestors_of(name)
|
|
62
64
|
base = ancestors.index("ViewComponent::Base")
|
|
63
|
-
return
|
|
64
|
-
return false if @index.resolve_method("call", name)
|
|
65
|
-
return false if (ancestors.take(base) - [name]).any? { |ancestor| inherited_template?(ancestor) }
|
|
65
|
+
return [] unless base
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
call_owner = @index.resolve_method("call", name)&.first&.owner&.name
|
|
68
|
+
ancestors.take(base).each do |ancestor|
|
|
69
|
+
return [] if ancestor == call_owner
|
|
70
|
+
|
|
71
|
+
files = (@index[ancestor] || []).filter_map(&:file_path).uniq
|
|
72
|
+
inherited = files.flat_map { |file| templates(file) }
|
|
73
|
+
return inherited if inherited.any?
|
|
69
74
|
end
|
|
75
|
+
return [] if call_owner
|
|
76
|
+
|
|
77
|
+
["#{path.delete_suffix(".rb")}.html.erb"]
|
|
70
78
|
rescue RubyIndexer::Index::NonExistingNamespaceError
|
|
71
|
-
|
|
79
|
+
[]
|
|
72
80
|
end
|
|
73
81
|
|
|
74
|
-
#: (
|
|
75
|
-
def
|
|
76
|
-
|
|
82
|
+
#: (Prism::ClassNode) -> bool
|
|
83
|
+
def declares_no_template?(node)
|
|
84
|
+
Array(node.body&.child_nodes).any? do |child|
|
|
85
|
+
child.is_a?(Prism::CallNode) && child.receiver.nil? && NO_TEMPLATE_CALLS.include?(child.name)
|
|
86
|
+
end
|
|
77
87
|
end
|
|
78
88
|
|
|
79
89
|
#: (String) -> Array[String]
|