ruby-lsp-rails-factory-bot 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74a733cd2866ef2bf14eef3cb4a7dd97dec52c7a315bed5ea884860bcb268f10
4
- data.tar.gz: b3ff978e4038960010882e6b51bf079aa057de8ba7ce60acb37b278aaec304ba
3
+ metadata.gz: ecaef6088d61c2afa9d54e033f288ab6221f3e607214f31d7a2c4749a9c58450
4
+ data.tar.gz: 813d00d86a4f54c299ab0cd8db98760f8d0e33207d1621fc454813acd70914d7
5
5
  SHA512:
6
- metadata.gz: f32b35548606386cf6bfdac973f5437d5a182984f8285f512f47f90f5a49d46598415de52661ed1c4962538b5c1dc29af29a497e2083de4e14a2981d62fe8b5d
7
- data.tar.gz: 98bfeb00adb8386588921797416174e6a7121f678b6b081c678f3367cf4e327aded286423ff93879f190524891c3274464d3ec191eb568727b9b947d2cb4b3f9
6
+ metadata.gz: 04755031614a46a02d65feb63b1f926e0ab4525d3e6b561f7964712ea9e46dfceccbfda8471586e518c2af5e308edb9050a1f36c8cff700b66804946e994c852
7
+ data.tar.gz: 822d8093fc8d3c113d17ddedd6e5fa7c37254b67c79227d6e7c6bbd97ee6bea436f17d7e387ed1a5b160b0e9841e37a23996cdf1ea19a17524e027ab12790c0f
data/README.md CHANGED
@@ -12,13 +12,11 @@ If bundler is not being used to manage dependencies, install the gem by executin
12
12
 
13
13
  $ gem install ruby-lsp-rails-factory-bot
14
14
 
15
- Note that this currenlty uses a fork of ruby-lsp-rails (to extend its server to be able to provide factory information).
16
-
17
15
  ## Usage
18
16
 
19
- Hover over an attribute or factory definition
17
+ Hover over a factory name, trait, or attribute
20
18
 
21
- ![lsp-factory-bot-hover](https://github.com/user-attachments/assets/6f570288-3cf3-4d12-acf9-71c86e834cd8)
19
+ ![lsp-factory-bot-hover-all](https://github.com/user-attachments/assets/16e463cb-dddf-4d12-8a85-3357d47df6ff)
22
20
 
23
21
  Receive completion suggestions as you type
24
22
 
@@ -42,7 +40,7 @@ Click through to definitions
42
40
  Notes:
43
41
 
44
42
  - The extension has "understanding" of factory/trait completion items, but due to limitations on when ruby-lsp displays the completion suggestions, they aren't visible for Symbols (eg. factory/trait names) :/ though they happen to be visible for symbols in Hash/Kw notation (ie with `:` after - `key: ...`)
45
- - Factory definition is not supported at the moment (current limitation of factory bot), but might come in due course
43
+ - Factory definition is not supported at the moment (limitation of current implementation), but might come in due course
46
44
 
47
45
 
48
46
  ## Development
@@ -61,6 +61,12 @@ module RubyLsp
61
61
  end
62
62
  end
63
63
 
64
+ def build_response(title, documentation, link)
65
+ @response_builder.push(title, category: :title) if title
66
+ @response_builder.push(documentation, category: :documentation) if documentation
67
+ @response_builder.push(link, category: :links) if link
68
+ end
69
+
64
70
  def handle_attribute(symbol_node, factory_node)
65
71
  name = symbol_node.value.to_s
66
72
  attribute = make_request(
@@ -70,10 +76,14 @@ module RubyLsp
70
76
 
71
77
  return unless attribute
72
78
 
73
- @response_builder.push(
74
- "#{attribute[:name]} (#{attribute[:type]})",
75
- category: :documentation,
76
- )
79
+ build_response(attribute[:name].to_s, attribute[:type].to_s, link_location(attribute[:source_location]))
80
+ end
81
+
82
+ def factory_documentation(factory)
83
+ index_entry = @ruby_index.first_unqualified_const(factory[:name])
84
+ return markdown_from_index_entries(factory[:model_class], index_entry) if index_entry
85
+
86
+ factory[:model_class].to_s
77
87
  end
78
88
 
79
89
  def handle_factory(symbol_node)
@@ -81,20 +91,12 @@ module RubyLsp
81
91
  factory = make_request(:factories, name: name)&.find { |f| f[:name] == name }
82
92
  return unless factory
83
93
 
84
- index_entry = @ruby_index.first_unqualified_const(factory[:name])
85
-
86
- hint = if index_entry
87
- markdown_from_index_entries(factory[:model_class], index_entry)
88
- else
89
- "#{factory[:name]} (#{factory[:model_class]})"
90
- end
91
-
92
- @response_builder.push(hint, category: :documentation)
94
+ build_response(factory[:name], factory_documentation(factory), nil)
93
95
  end
94
96
 
95
97
  def trait_tooltip(trait, factory_name)
96
98
  source = trait[:source]&.length&.positive? ? trait[:source] : nil
97
- source || "#{trait[:name]} (trait of #{trait[:owner] || factory_name})"
99
+ source ? "```ruby\n#{source}\n```" : "trait of #{trait[:owner] || factory_name}"
98
100
  end
99
101
 
100
102
  def handle_trait(symbol_node, factory_node)
@@ -107,7 +109,7 @@ module RubyLsp
107
109
 
108
110
  return unless trait
109
111
 
110
- @response_builder.push(trait_tooltip(trait, factory_name), category: :documentation)
112
+ build_response(trait[:name], trait_tooltip(trait, factory_name), link_location(trait[:source_location]))
111
113
  end
112
114
 
113
115
  def make_request(request_name, **params)
@@ -117,6 +119,14 @@ module RubyLsp
117
119
  **params,
118
120
  )
119
121
  end
122
+
123
+ def link_location(source_location)
124
+ return unless source_location
125
+
126
+ return if source_location.empty?
127
+
128
+ "[Definition](#{URI::Generic.from_path(path: source_location[0])}#L#{source_location[1]})"
129
+ end
120
130
  end
121
131
  end
122
132
  end
@@ -26,7 +26,7 @@ module RubyLsp
26
26
  # helper - might be best to live elsewhere?
27
27
  def block_source(attr)
28
28
  blk = block_for(attr)
29
- blk.source if blk.respond_to? :source
29
+ blk.source&.strip_heredoc if blk.respond_to? :source
30
30
  end
31
31
  end
32
32
  end
@@ -3,7 +3,7 @@
3
3
  module RubyLsp
4
4
  module Rails
5
5
  module FactoryBot
6
- VERSION = "0.5.0"
6
+ VERSION = "0.6.0"
7
7
  REQUIRED_RUBY_LSP_RAILS_VERSION = "~> 0.4"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-rails-factory-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - johansenja
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-21 00:00:00.000000000 Z
11
+ date: 2025-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -66,8 +66,8 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: A ruby-lsp-rails extension for factorybot, providing factory, trait and
70
- attribute completion, and more
69
+ description: A ruby-lsp-rails extension for factorybot, supporting hover, go-to-definition
70
+ and autocompletion - for factories, traits and attributes
71
71
  email:
72
72
  - 43235608+johansenja@users.noreply.github.com
73
73
  executables: []
@@ -114,8 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.3.26
117
+ rubygems_version: 3.5.11
118
118
  signing_key:
119
119
  specification_version: 4
120
- summary: A ruby-lsp-rails extension for factorybot
120
+ summary: A ruby-lsp-rails extension for factorybot, supporting hover, go-to-definition
121
+ and autocompletion
121
122
  test_files: []