ruby-lsp-mongoid 0.1.0 → 0.1.1

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: a0ab653d0a88cf1ad6cc028fee44f4e74e90528d9435a62c8ba600371e2b25b8
4
- data.tar.gz: 7f913b8a4028be0151cdb591d98049bb6173835e85a925b6bc1517bc6e8c2a4e
3
+ metadata.gz: 25deaba20b973e9a4ceae841a71e0ae0d46b7ba6272fc5c48a9a56900d5240f3
4
+ data.tar.gz: 1075b753283b79bdf2cb9a0e36fdc16659d7b79e7f419b7a039531b8d1b92ecf
5
5
  SHA512:
6
- metadata.gz: bf1bbab9edc8c6632cdfbb31b26a58505bb885b7ff4b7b6aff6965df7d1d78cae117d8a44bf31bfd4cd248ef72fbeb5de3ab07bf49d461972a56409a1fd1d321
7
- data.tar.gz: cd83a370ef45d4c2e2d343966ca69e5429ea7893150c24d9a824837300490aedc4e6f23ce33ecb3f7d7f0379d6bc1bc11f995249008a1c8bca621fe581156431
6
+ metadata.gz: 7717dc958cb9f9c06fe1e097b8d8771ec0e52cfcf68ab502165ddc21e24dca5cf56cb07fff2c5d5790345fe56f08b479a843b2001b0ac21b7c89a9f0ef920e48
7
+ data.tar.gz: da98dc048563431553f88902e5068ce03757dc9056f43c47388651f978a98909e1fbf5664f367c9e3d2fe81c8fbe5a024ea710e9606b95ca7804c57e49af1610
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### Added
4
+
5
+ - Auto-index `_id` and `id` accessor methods for all Mongoid models that use any DSL (field, associations, scope)
6
+ - Each class using Mongoid DSL now automatically gets `_id`, `_id=`, `id`, and `id=` methods indexed at the first DSL location
7
+
3
8
  ## [0.1.0] - 2025-12-02
4
9
 
5
10
  - Initial release
data/TODO.md CHANGED
@@ -14,3 +14,4 @@ The add-on will recognize methods generated by the following Mongoid DSLs:
14
14
  ### Others
15
15
  - [ ] Callbacks - Lifecycle callback methods
16
16
  - [ ] Validations - Validation-related methods
17
+ - [ ] Enhance index only when class includes Mongoid::Document
@@ -3,6 +3,11 @@
3
3
  module RubyLsp
4
4
  module Mongoid
5
5
  class IndexingEnhancement < RubyIndexer::Enhancement
6
+ def initialize(listener)
7
+ super
8
+ @id_indexed_owners = Set.new
9
+ end
10
+
6
11
  def on_call_node_enter(call_node)
7
12
  owner = @listener.current_owner
8
13
  return unless owner
@@ -32,6 +37,8 @@ module RubyLsp
32
37
  loc = call_node.location
33
38
  comment = build_field_options_comment(call_node)
34
39
 
40
+ ensure_id_field_indexed(loc)
41
+
35
42
  add_accessor_methods(name, loc, comments: comment)
36
43
 
37
44
  # Handle as: option for field alias
@@ -43,7 +50,10 @@ module RubyLsp
43
50
  name = extract_name(call_node)
44
51
  return unless name
45
52
 
46
- add_accessor_methods(name, call_node.location)
53
+ loc = call_node.location
54
+ ensure_id_field_indexed(loc)
55
+
56
+ add_accessor_methods(name, loc)
47
57
  end
48
58
 
49
59
  def handle_many_association(call_node)
@@ -51,6 +61,7 @@ module RubyLsp
51
61
  return unless name
52
62
 
53
63
  loc = call_node.location
64
+ ensure_id_field_indexed(loc)
54
65
 
55
66
  add_accessor_methods(name, loc)
56
67
 
@@ -63,6 +74,7 @@ module RubyLsp
63
74
  return unless name
64
75
 
65
76
  loc = call_node.location
77
+ ensure_id_field_indexed(loc)
66
78
 
67
79
  add_accessor_methods(name, loc)
68
80
  add_builder_methods(name, loc)
@@ -75,7 +87,10 @@ module RubyLsp
75
87
  owner = @listener.current_owner
76
88
  return unless owner
77
89
 
78
- add_singleton_method(name.to_s, call_node.location, owner)
90
+ loc = call_node.location
91
+ ensure_id_field_indexed(loc)
92
+
93
+ add_singleton_method(name.to_s, loc, owner)
79
94
  end
80
95
 
81
96
  def extract_name(call_node)
@@ -198,6 +213,18 @@ module RubyLsp
198
213
  name_str
199
214
  end
200
215
  end
216
+
217
+ def ensure_id_field_indexed(location)
218
+ owner = @listener.current_owner
219
+ return unless owner
220
+ return if @id_indexed_owners.include?(owner.name)
221
+
222
+ @id_indexed_owners.add(owner.name)
223
+
224
+ # Add _id and id (alias) accessor methods
225
+ add_accessor_methods("_id", location)
226
+ add_accessor_methods("id", location)
227
+ end
201
228
  end
202
229
  end
203
230
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLsp
4
4
  module Mongoid
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia