ruby-lsp-i18n 0.3.0 → 0.4.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: 7f0fdc0478778d6e3c1f0a1214050b93bbf1e7fc5e88f1ca0b9600e1936d2952
4
- data.tar.gz: 26070828190643f05f77cef165b995810eec828510ae78def86cae0d65588ad9
3
+ metadata.gz: ef50020995375f664510365b17c970d6732fd3affec58a902fd7865244ae6702
4
+ data.tar.gz: 362f3463407c6fa6fad0ea4f3121c4ed3f66ceb4ab079e32be4187da25c65e53
5
5
  SHA512:
6
- metadata.gz: 5a9da889bf6f3fdb0ef5b773c7dd64c1b210cb62ff438b314b43ee1d57778324d7ada0ab36745119b9cb32b1080d6bb1988618b9a269a3232d2343d85e0bf8ce
7
- data.tar.gz: f198ccadd9f2e09dccb32f149e030a901a8f479042d34aac0d4301bb822bfaabb4160991d913b1b3b94721de01ef848aa13beb32c389933bceb1392c56f22404
6
+ metadata.gz: 2ffebae3651d61ce648fb155ebf3b27f7456fabd93c931c57a26127e52e143bc18cc3843dbfb72203af91a0c7e47885968e5c0cbda96fad122f19dbc650037d6
7
+ data.tar.gz: 91ceb189f956e6f983084f74214ad21b55ce85b90e67eb6b6e96ef8313d1a16311478f15d770c68875dc3fb77868d4fb65a76cfa336f8bc873e989b276da5db7
data/.rubocop.yml CHANGED
@@ -11,3 +11,6 @@ Style/StringLiteralsInInterpolation:
11
11
 
12
12
  Layout/LineLength:
13
13
  Max: 120
14
+
15
+ Layout/LeadingCommentSpace:
16
+ AllowRBSInlineAnnotation: true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2025-07-18
4
+
5
+ - Removed sorbet runtime dependency
6
+ - Fix bad use of generics because of RubyLsp sorbet runtime removal
7
+ - Updated RubyLsp to 0.25
8
+
3
9
  ## [0.3.0] - 2025-07-18
4
10
 
5
11
  - Fix inlay hints patch thanks to [@enmy](https://github.com/enmy)
@@ -8,24 +8,23 @@ require_relative "listeners/completion"
8
8
  require_relative "i18n_index"
9
9
  require_relative "../../ruby_lsp_i18n/version"
10
10
 
11
- RubyLsp::Addon.depend_on_ruby_lsp!("~> 0.24.0")
11
+ RubyLsp::Addon.depend_on_ruby_lsp!("~> 0.25.0")
12
12
 
13
13
  module RubyLsp
14
14
  module RubyLspI18n
15
15
  GLOB_PATH = "**/config/locales/**/es.yml"
16
16
  # This class is the entry point for the addon. It is responsible for activating and deactivating the addon
17
17
  class Addon < ::RubyLsp::Addon
18
- extend T::Sig
19
-
20
- sig { void }
18
+ #: -> void
21
19
  def initialize
22
20
  super
23
- @i18n_index = T.let(I18nIndex.new(language: "es"), I18nIndex)
24
- @enabled = T.let(true, T::Boolean)
21
+ @i18n_index = I18nIndex.new(language: "es") #: I18nIndex
22
+ @enabled = true #: bool
25
23
  end
26
24
 
27
25
  # Performs any activation that needs to happen once when the language server is booted)}
28
- sig { override.params(global_state: RubyLsp::GlobalState, message_queue: Thread::Queue).void }
26
+ # @override
27
+ #: (RubyLsp::GlobalState, Thread::Queue) -> void
29
28
  def activate(global_state, message_queue)
30
29
  settings = global_state.settings_for_addon(name) || {}
31
30
  @enabled = settings[:enabled] if settings.key?(:enabled)
@@ -60,14 +59,15 @@ module RubyLsp
60
59
  end
61
60
 
62
61
  # Performs any cleanup when shutting down the server, like terminating a subprocess
63
- sig { override.void }
62
+ # @override
63
+ #: -> void
64
64
  def deactivate; end
65
65
 
66
- sig { params(changes: T::Array[T::Hash[Symbol, T.untyped]]).void }
66
+ #: (Array[Hash[Symbol, untyped]]) -> void
67
67
  def workspace_did_change_watched_files(changes)
68
68
  changes.each do |change|
69
69
  change = Interface::FileEvent.new(uri: change[:uri], type: change[:type])
70
- uri = T.let(change.uri, String)
70
+ uri = change.uri #: String
71
71
 
72
72
  next unless uri.end_with?("es.yml")
73
73
 
@@ -80,38 +80,27 @@ module RubyLsp
80
80
  end
81
81
  end
82
82
 
83
- sig { override.returns(String) }
83
+ # @override
84
+ #: -> String
84
85
  def version
85
86
  RubyLsp::RubyLspI18n::VERSION
86
87
  end
87
88
 
88
89
  # Returns the name of the addon
89
- sig { override.returns(String) }
90
+ # @override
91
+ #: -> String
90
92
  def name
91
93
  "Ruby LSP I18n"
92
94
  end
93
95
 
94
- sig do
95
- params(
96
- response_builder: ResponseBuilders::CollectionResponseBuilder,
97
- dispatcher: Prism::Dispatcher,
98
- document: T.any(RubyDocument, ERBDocument),
99
- ).void
100
- end
96
+ #: (ResponseBuilders::CollectionResponseBuilder, Prism::Dispatcher, (RubyDocument | ERBDocument)) -> void
101
97
  def create_inlay_hints_listener(response_builder, dispatcher, document)
102
98
  return unless @enabled
103
99
 
104
100
  InlayHints.new(@i18n_index, response_builder, dispatcher, document)
105
101
  end
106
102
 
107
- sig do
108
- override.params(
109
- response_builder: RubyLsp::ResponseBuilders::CollectionResponseBuilder,
110
- node_context: RubyLsp::NodeContext,
111
- dispatcher: Prism::Dispatcher,
112
- uri: URI::Generic,
113
- ).void
114
- end
103
+ #: (RubyLsp::ResponseBuilders::CollectionResponseBuilder, RubyLsp::NodeContext, Prism::Dispatcher, URI::Generic) -> void
115
104
  def create_completion_listener(response_builder, node_context, dispatcher, uri)
116
105
  return unless @enabled
117
106
 
@@ -124,14 +113,7 @@ end
124
113
  # Patch the InlayHints request to support addons
125
114
  module RubyLsp
126
115
  class Addon
127
- extend T::Sig
128
- sig do
129
- params(
130
- response_builder: ResponseBuilders::CollectionResponseBuilder,
131
- dispatcher: Prism::Dispatcher,
132
- document: T.any(RubyDocument, ERBDocument),
133
- ).void
134
- end
116
+ #: (ResponseBuilders::CollectionResponseBuilder, Prism::Dispatcher, (RubyDocument | ERBDocument)) -> void
135
117
  def create_inlay_hints_listener(response_builder, dispatcher, document)
136
118
  end
137
119
  end
@@ -8,15 +8,13 @@ module RubyLsp
8
8
  # to their values and the files they are defined in.
9
9
 
10
10
  class Entry
11
- extend T::Sig
12
-
13
- sig { returns(String) }
11
+ #: String
14
12
  attr_reader :value
15
13
 
16
- sig { returns(String) }
14
+ #: String
17
15
  attr_reader :file
18
16
 
19
- sig { params(value: String, file: String).void }
17
+ #: (String, String) -> void
20
18
  def initialize(value, file)
21
19
  @value = value
22
20
  @file = file
@@ -24,59 +22,58 @@ module RubyLsp
24
22
  end
25
23
 
26
24
  class I18nIndex
27
- extend T::Sig
28
-
29
- sig { params(language: String).void }
25
+ #: (language: String) -> void
30
26
  def initialize(language:)
31
27
  @language = language
32
- @data = T.let({}, T::Hash[String, T::Array[Entry]])
28
+ @data = {} #: Hash[String, Array[Entry]]
33
29
 
34
- @file_keys = T.let(
35
- Hash.new do |hash, key|
36
- hash[key] = []
37
- end,
38
- T::Hash[String, T::Array[String]],
39
- )
30
+ @file_keys = Hash.new do |hash, key|
31
+ hash[key] = []
32
+ end #: Hash[String, Array[String]]
40
33
 
41
- @keys_tree = T.let(RubyLsp::RubyLspI18n::PrefixTree.new, RubyLsp::RubyLspI18n::PrefixTree[String])
34
+ @keys_tree = RubyLsp::RubyLspI18n::PrefixTree.new #: RubyLsp::RubyLspI18n::PrefixTree[String]
42
35
  end
43
36
 
44
- sig { params(key: String, value: String, file: String).void }
37
+ #: (String key, String value, String file) -> void
45
38
  def add(key, value, file)
46
39
  entry = Entry.new(value, file)
47
40
  @data[key] ||= []
48
- T.must(@data[key]) << entry
49
- T.must(@file_keys[file]) << key
41
+ data_key = @data[key] #: as !nil
42
+ data_key << entry
43
+ data_file = @file_keys[file] #: as !nil
44
+ data_file << key
50
45
  @keys_tree.insert(key, key)
51
46
  end
52
47
 
53
- sig { params(key: String, file: String).void }
48
+ #: (String key, String file) -> void
54
49
  def remove(key, file)
55
50
  return unless @data[key]
56
51
 
57
- T.must(@data[key]).delete_if { |v| v.file == file }
58
- T.must(@file_keys[file]).delete(key)
52
+ data_key = @data[key] #: as !nil
53
+ data_key.delete_if { |v| v.file == file }
54
+ data_file = @file_keys[file] #: as !nil
55
+ data_file.delete(key)
59
56
  @keys_tree.delete(key)
60
57
  end
61
58
 
62
- sig { params(key: String).returns(T::Array[RubyLsp::RubyLspI18n::Entry]) }
59
+ #: (String key) -> Array[RubyLsp::RubyLspI18n::Entry]
63
60
  def find(key)
64
61
  datum = @data.dig(key)
65
62
  datum.nil? ? [] : datum
66
63
  end
67
64
 
68
- sig { params(prefix: String).returns(T::Array[String]) }
65
+ #: (String prefix) -> Array[String]
69
66
  def find_prefix(prefix)
70
67
  @keys_tree.search(prefix)
71
68
  end
72
69
 
73
- sig { params(key: String, value: String, file: String).void }
70
+ #: (String key, String value, String file) -> void
74
71
  def update(key, value, file)
75
72
  remove(key, file)
76
73
  add(key, value, file)
77
74
  end
78
75
 
79
- sig { params(path: String).void }
76
+ #: (String path) -> void
80
77
  def sync_file(path)
81
78
  # Clean entries from the file
82
79
  current_keys = get_keys_from_file(path)
@@ -108,12 +105,12 @@ module RubyLsp
108
105
 
109
106
  private
110
107
 
111
- sig { params(file: String).returns(T::Array[String]) }
108
+ #: (String file) -> Array[String]
112
109
  def get_keys_from_file(file)
113
- T.must(@file_keys[file])
110
+ @file_keys[file] #: as !nil
114
111
  end
115
112
 
116
- sig { params(translations: T::Hash[String, T.untyped], file: String, prefix: T.nilable(String)).void }
113
+ #: (Hash[String, untyped] translations, String file, ?String? prefix) -> void
117
114
  def process_translations(translations, file, prefix = nil)
118
115
  translations.each do |key, value|
119
116
  full_key = prefix ? "#{prefix}.#{key}" : key
@@ -4,16 +4,9 @@
4
4
  module RubyLsp
5
5
  module RubyLspI18n
6
6
  class Completion
7
- extend T::Sig
8
7
  include Requests::Support::Common
9
8
 
10
- sig do
11
- params(
12
- i18n_index: I18nIndex,
13
- response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem],
14
- dispatcher: Prism::Dispatcher,
15
- ).void
16
- end
9
+ #: (I18nIndex, ResponseBuilders::CollectionResponseBuilder, Prism::Dispatcher) -> void
17
10
  def initialize(i18n_index, response_builder, dispatcher)
18
11
  @i18n_index = i18n_index
19
12
  @response_builder = response_builder
@@ -25,7 +18,7 @@ module RubyLsp
25
18
  )
26
19
  end
27
20
 
28
- sig { params(node: Prism::CallNode).void }
21
+ #: (Prism::CallNode) -> void
29
22
  def on_call_node_enter(node)
30
23
  return unless node.name == :t
31
24
 
@@ -42,7 +35,8 @@ module RubyLsp
42
35
  return unless key_node.is_a?(Prism::StringNode)
43
36
 
44
37
  key = key_node.unescaped
45
- quote = T.must(key_node.opening_loc).slice
38
+ opening_location = key_node.opening_loc #: as !nil
39
+ quote = opening_location.slice
46
40
  candidates = @i18n_index.find_prefix(key)
47
41
 
48
42
  candidates.each do |candidate|
@@ -4,21 +4,13 @@
4
4
  module RubyLsp
5
5
  module RubyLspI18n
6
6
  class InlayHints
7
- extend T::Sig
8
7
  include Requests::Support::Common
9
8
 
10
- sig do
11
- params(
12
- i18n_index: I18nIndex,
13
- response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint],
14
- dispatcher: Prism::Dispatcher,
15
- document: T.any(RubyDocument, ERBDocument),
16
- ).void
17
- end
9
+ #: (I18nIndex, ResponseBuilders::CollectionResponseBuilder, Prism::Dispatcher, (RubyDocument | ERBDocument)) -> void
18
10
  def initialize(i18n_index, response_builder, dispatcher, document)
19
- absolute_path = T.must(document.uri.path)
20
- @absolute_path = T.let(absolute_path, String)
21
- @path = T.let(Pathname(absolute_path).relative_path_from(Dir.pwd), Pathname)
11
+ absolute_path = document.uri.path
12
+ @absolute_path = absolute_path #: String
13
+ @path = Pathname(absolute_path).relative_path_from(Dir.pwd) #: Pathname
22
14
  @i18n_index = i18n_index
23
15
  @response_builder = response_builder
24
16
 
@@ -28,7 +20,7 @@ module RubyLsp
28
20
  )
29
21
  end
30
22
 
31
- sig { params(node: Prism::CallNode).void }
23
+ #: (Prism::CallNode) -> void
32
24
  def on_call_node_enter(node)
33
25
  return unless node.name == :t
34
26
 
@@ -87,13 +79,13 @@ module RubyLsp
87
79
 
88
80
  private
89
81
 
90
- sig { params(path: String).returns(String) }
82
+ #: (String path) -> String
91
83
  def create_file_uri(path)
92
84
  base_uri = "file://#{Dir.pwd}/"
93
85
  URI.join(base_uri, path).to_s
94
86
  end
95
87
 
96
- sig { params(arguments: Prism::ArgumentsNode).returns(T::Boolean) }
88
+ #: (Prism::ArgumentsNode arguments) -> bool
97
89
  def i18n_arguments_has_scope_argument(arguments)
98
90
  arguments = arguments.arguments
99
91
  return false if arguments.size <= 1
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RubyLsp
@@ -35,15 +35,14 @@ module RubyLsp
35
35
  # `Value` type.
36
36
  #
37
37
  # See https://en.wikipedia.org/wiki/Trie for more information
38
+ #: [Value]
38
39
  class PrefixTree
39
- extend T::Sig
40
- extend T::Generic
41
-
42
- Value = type_member
43
-
44
- sig { void }
40
+ #: -> void
45
41
  def initialize
46
- @root = T.let(Node.new("", ""), Node[Value])
42
+ @root = Node.new(
43
+ "",
44
+ "", #: as untyped
45
+ ) #: Node[Value]
47
46
  end
48
47
 
49
48
  # Search the PrefixTree based on a given `prefix`. If `foo` is an entry in the tree, then searching for `fo` will
@@ -51,7 +50,7 @@ module RubyLsp
51
50
  # Notice that if the `Value` is an array, this method will return an array of arrays, where each entry is
52
51
  # the array
53
52
  # of values for a given match
54
- sig { params(prefix: String).returns(T::Array[Value]) }
53
+ #: (String prefix) -> Array[Value]
55
54
  def search(prefix)
56
55
  node = find_node(prefix)
57
56
  return [] unless node
@@ -60,7 +59,7 @@ module RubyLsp
60
59
  end
61
60
 
62
61
  # Inserts a `value` using the given `key`
63
- sig { params(key: String, value: Value).void }
62
+ #: (String key, Value value) -> void
64
63
  def insert(key, value)
65
64
  node = @root
66
65
 
@@ -77,13 +76,13 @@ module RubyLsp
77
76
 
78
77
  # Deletes the entry identified by `key` from the tree. Notice that a partial match will still delete all entries
79
78
  # that match it. For example, if the tree contains `foo` and we ask to delete `fo`, then `foo` will be deleted
80
- sig { params(key: String).void }
79
+ #: (String key) -> void
81
80
  def delete(key)
82
81
  node = find_node(key)
83
82
  return unless node
84
83
 
85
84
  # Remove the node from the tree and then go up the parents to remove any of them with empty children
86
- parent = T.let(T.must(node.parent), T.nilable(Node[Value]))
85
+ parent = node.parent #: Node[Value]?
87
86
 
88
87
  while parent
89
88
  parent.children.delete(node.key)
@@ -97,7 +96,7 @@ module RubyLsp
97
96
  private
98
97
 
99
98
  # Find a node that matches the given `key`
100
- sig { params(key: String).returns(T.nilable(Node[Value])) }
99
+ #: (String key) -> Node[Value]?
101
100
  def find_node(key)
102
101
  node = @root
103
102
 
@@ -111,37 +110,33 @@ module RubyLsp
111
110
  node
112
111
  end
113
112
 
113
+ #: [Value]
114
114
  class Node
115
- extend T::Sig
116
- extend T::Generic
117
-
118
- Value = type_member
119
-
120
- sig { returns(T::Hash[String, Node[Value]]) }
115
+ #: Hash[String, Node[Value]]
121
116
  attr_reader :children
122
117
 
123
- sig { returns(String) }
118
+ #: String
124
119
  attr_reader :key
125
120
 
126
- sig { returns(Value) }
121
+ #: Value
127
122
  attr_accessor :value
128
123
 
129
- sig { returns(T::Boolean) }
124
+ #: bool
130
125
  attr_accessor :leaf
131
126
 
132
- sig { returns(T.nilable(Node[Value])) }
127
+ #: Node[Value]?
133
128
  attr_reader :parent
134
129
 
135
- sig { params(key: String, value: Value, parent: T.nilable(Node[Value])).void }
130
+ #: (String key, Value value, ?Node[Value]? parent) -> void
136
131
  def initialize(key, value, parent = nil)
137
132
  @key = key
138
133
  @value = value
139
134
  @parent = parent
140
- @children = {}
141
- @leaf = false
135
+ @children = {} #: Hash[String, Node[Value]]
136
+ @leaf = false #: bool
142
137
  end
143
138
 
144
- sig { returns(T::Array[Value]) }
139
+ #: -> Array[Value]
145
140
  def collect
146
141
  result = []
147
142
  result << @value if @leaf
@@ -6,19 +6,9 @@
6
6
  module RubyLsp
7
7
  module Requests
8
8
  module InlayHintsPatch
9
- extend T::Sig
10
- extend T::Helpers
11
-
12
- requires_ancestor { InlayHints }
13
-
14
- sig do
15
- params(
16
- document: T.any(RubyDocument, ERBDocument),
17
- hints_configuration: RequestConfig,
18
- dispatcher: Prism::Dispatcher,
19
- ).void
20
- end
21
- def initialize(document, hints_configuration, dispatcher)
9
+ # @requires_ancestor: Kernel
10
+ #: (RubyLsp::GlobalState, RubyDocument | ERBDocument, Prism::Dispatcher) -> void
11
+ def initialize(global_state, document, dispatcher)
22
12
  super
23
13
 
24
14
  Addon.addons.each do |addon|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLsp
4
4
  module RubyLspI18n
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
Binary file
data/sorbet/config CHANGED
@@ -2,3 +2,5 @@
2
2
  .
3
3
  --ignore=tmp/
4
4
  --ignore=vendor/
5
+ --enable-experimental-rbs-comments
6
+ --enable-experimental-requires-ancestor
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - domingo2000
@@ -38,6 +38,7 @@ files:
38
38
  - lib/ruby_lsp_i18n.rb
39
39
  - lib/ruby_lsp_i18n/version.rb
40
40
  - media/demo.gif
41
+ - ruby-lsp-i18n-0.3.0.gem
41
42
  - ruby-lsp-i18n.gemspec
42
43
  - sorbet/config
43
44
  - sorbet/rbi/annotations/.gitattributes