ruby-lsp-view_component 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/lib/ruby_lsp/ruby_lsp_view_component/addon.rb +39 -0
- data/lib/ruby_lsp/ruby_lsp_view_component/code_lens.rb +55 -0
- data/lib/ruby_lsp_view_component/version.rb +7 -0
- metadata +63 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f750624290fc729f716c2bb2c20b13d56baa7fad7878014e795342cbdb61f148
|
|
4
|
+
data.tar.gz: 3b28ec82ce7c86cddf56b35595f472161b526cb0eb57ee2fb11204edb4355d24
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4738e8c1e9240ac1444aebdbf7f5ddb93df0d0374604811c234b36f5a14334b51d8638d813460e5f1bc66fe088e1233faaa38febaabbde17649f105079f39f77
|
|
7
|
+
data.tar.gz: 2e47b3801dde3a15a8757f3e767282a25bf0038d794a81dc5ab3b246b5b77cc2a8d870d07b7af9b01902ecf4f69f628385a1a95c8ab6e74ac0da9c29e3ce6030
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Retamal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# ruby-lsp-view_component
|
|
2
|
+
|
|
3
|
+
A [Ruby LSP](https://github.com/Shopify/ruby-lsp) add-on for [ViewComponent](https://viewcomponent.org). It adds a `Jump to template` CodeLens to each component class that opens the component's template.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Jump to template
|
|
8
|
+
|
|
9
|
+
The lens sits above the component class. When the component has a single template, a click opens it.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
When the component has more than one template, the click opens a picker with the main template first.
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
For `app/components/bar_component.rb`, the lens lists:
|
|
18
|
+
|
|
19
|
+
| File | What it is |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `bar_component.html.erb` | [Main template](https://viewcomponent.org/guide/templates.html#sibling-file) |
|
|
22
|
+
| `bar_component.html+phone.erb` | Variant of the main template |
|
|
23
|
+
| `bar_component/bar_component.html.erb` | [Main template in a subdirectory](https://viewcomponent.org/guide/templates.html#subdirectory) |
|
|
24
|
+
| `bar_component/list.html.erb` | Sub-template rendered with `call_list`, from [view_component_subtemplates](https://github.com/bukhr/view_component_subtemplates) |
|
|
25
|
+
|
|
26
|
+
ERB, Haml and Slim templates are supported. Templates of nested components in the subdirectory, such as `bar_component/item_component.html.erb` next to `bar_component/item_component.rb`, belong to that component and are left out.
|
|
27
|
+
|
|
28
|
+
Components without a template file of their own get no lens. That covers [inline](https://viewcomponent.org/guide/templates.html#inline) and [`call`](https://viewcomponent.org/guide/templates.html#call) components, and components that [inherit](https://viewcomponent.org/guide/templates.html#inherited) their template from a parent class.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Add the gem to your application's Gemfile:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
group :development do
|
|
36
|
+
gem "ruby-lsp-view_component", require: false
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Run `bundle install` and restart Ruby LSP. Ruby LSP loads add-ons from the bundle, so there is nothing to configure.
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bundle install
|
|
46
|
+
bundle exec rake
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`rake` runs the tests and RuboCop.
|
|
50
|
+
|
|
51
|
+
## Release
|
|
52
|
+
|
|
53
|
+
1. Update the version in `lib/ruby_lsp_view_component/version.rb` and add it to `CHANGELOG.md`.
|
|
54
|
+
2. Run `bundle exec rake release`. It builds the gem, tags the commit as `vX.Y.Z`, pushes the tag and pushes the gem to RubyGems. The gem requires MFA, so `gem push` asks for a one-time code.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
[MIT](LICENSE.txt)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ruby_lsp/addon"
|
|
4
|
+
require_relative "../../ruby_lsp_view_component/version"
|
|
5
|
+
require_relative "code_lens"
|
|
6
|
+
|
|
7
|
+
RubyLsp::Addon.depend_on_ruby_lsp!("~> 0.26.0")
|
|
8
|
+
|
|
9
|
+
module RubyLsp
|
|
10
|
+
module RubyLspViewComponent
|
|
11
|
+
class Addon < ::RubyLsp::Addon
|
|
12
|
+
# @override
|
|
13
|
+
#: (GlobalState, Thread::Queue) -> void
|
|
14
|
+
def activate(global_state, outgoing_queue); end
|
|
15
|
+
|
|
16
|
+
# @override
|
|
17
|
+
#: -> void
|
|
18
|
+
def deactivate; end
|
|
19
|
+
|
|
20
|
+
# @override
|
|
21
|
+
#: -> String
|
|
22
|
+
def name
|
|
23
|
+
"Ruby LSP ViewComponent"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @override
|
|
27
|
+
#: -> String
|
|
28
|
+
def version
|
|
29
|
+
VERSION
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @override
|
|
33
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens], URI::Generic, Prism::Dispatcher) -> void
|
|
34
|
+
def create_code_lens_listener(response_builder, uri, dispatcher)
|
|
35
|
+
CodeLens.new(response_builder, uri, dispatcher)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLsp
|
|
4
|
+
module RubyLspViewComponent
|
|
5
|
+
class CodeLens
|
|
6
|
+
include Requests::Support::Common
|
|
7
|
+
|
|
8
|
+
TEMPLATE_EXTENSIONS = "{erb,haml,slim}"
|
|
9
|
+
|
|
10
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens], URI::Generic, Prism::Dispatcher) -> void
|
|
11
|
+
def initialize(response_builder, uri, dispatcher)
|
|
12
|
+
@response_builder = response_builder
|
|
13
|
+
@path = uri.to_standardized_path #: String?
|
|
14
|
+
@seen_class = false
|
|
15
|
+
dispatcher.register(self, :on_class_node_enter) if @path&.end_with?(".rb")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#: (Prism::ClassNode) -> void
|
|
19
|
+
def on_class_node_enter(node)
|
|
20
|
+
return if @seen_class
|
|
21
|
+
|
|
22
|
+
@seen_class = true
|
|
23
|
+
uris = templates.map { |path| URI::Generic.from_path(path: path).to_s }
|
|
24
|
+
return if uris.empty?
|
|
25
|
+
|
|
26
|
+
@response_builder << create_code_lens(
|
|
27
|
+
node,
|
|
28
|
+
title: "Jump to template",
|
|
29
|
+
command_name: "rubyLsp.openFile",
|
|
30
|
+
arguments: [uris],
|
|
31
|
+
data: { type: "file" },
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
#: -> Array[String]
|
|
38
|
+
def templates
|
|
39
|
+
path = @path #: as !nil
|
|
40
|
+
dir = File.dirname(path)
|
|
41
|
+
name = File.basename(path, ".rb")
|
|
42
|
+
Dir.glob(["#{name}.*#{TEMPLATE_EXTENSIONS}", "#{name}/*.#{TEMPLATE_EXTENSIONS}"], base: dir)
|
|
43
|
+
.reject { |file| nested_component?(dir, file) }
|
|
44
|
+
.sort_by { |file| File.basename(file).start_with?("#{name}.") ? [0, file.length, file] : [1, 0, file] }
|
|
45
|
+
.map { |file| File.join(dir, file) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#: (String, String) -> bool
|
|
49
|
+
def nested_component?(dir, file)
|
|
50
|
+
File.dirname(file) != "." &&
|
|
51
|
+
File.exist?(File.join(dir, File.dirname(file), "#{File.basename(file).split(".").first}.rb"))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby-lsp-view_component
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Daniel Retamal
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ruby-lsp
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.26.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.26.0
|
|
26
|
+
description: Adds a CodeLens to ViewComponent classes that jumps to their templates
|
|
27
|
+
email:
|
|
28
|
+
- daniel.retamal.ahumada@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- CHANGELOG.md
|
|
34
|
+
- LICENSE.txt
|
|
35
|
+
- README.md
|
|
36
|
+
- lib/ruby_lsp/ruby_lsp_view_component/addon.rb
|
|
37
|
+
- lib/ruby_lsp/ruby_lsp_view_component/code_lens.rb
|
|
38
|
+
- lib/ruby_lsp_view_component/version.rb
|
|
39
|
+
homepage: https://github.com/daniel-retamal/ruby-lsp-view_component
|
|
40
|
+
licenses:
|
|
41
|
+
- MIT
|
|
42
|
+
metadata:
|
|
43
|
+
homepage_uri: https://github.com/daniel-retamal/ruby-lsp-view_component
|
|
44
|
+
changelog_uri: https://github.com/daniel-retamal/ruby-lsp-view_component/blob/main/CHANGELOG.md
|
|
45
|
+
rubygems_mfa_required: 'true'
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 3.3.0
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
requirements: []
|
|
60
|
+
rubygems_version: 3.6.9
|
|
61
|
+
specification_version: 4
|
|
62
|
+
summary: Ruby LSP add-on for ViewComponent
|
|
63
|
+
test_files: []
|