ruby-lsp-ree 0.1.9 → 0.1.10

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: e2340c5046b16e260fd66ff9696e36c4e04db071520018f683e59e4ddcaef34f
4
- data.tar.gz: b3a89234d7a4627371ec1e8514970ad00ac540b5b4b6b9cdbd046a2729aa9fee
3
+ metadata.gz: 363caa1c6e2f1d4bdedac1791e0edf969fab9fa7037039a6146de7f0d98d0056
4
+ data.tar.gz: 750e5d2bba1606b9f50d465b7a86aafb830ee43c18637053421b68e59fabf1f9
5
5
  SHA512:
6
- metadata.gz: c7e8650725c0188ec521e53188cfdd68679d5d73a392ce624b9f89c3f2daf683497e2558e932daed14cf652d25140a4bca891c3c9dbb536cfecae9cb92d72912
7
- data.tar.gz: c8e71b80054434730dbc10bdb85cb82e5277f2582a00879688e25e32078e239620f0e481b0eacac4619acca9ef606933a9fd820c87bf7a075619b506b5ef0a1c
6
+ metadata.gz: 422890cf9cb718b345df5290c2493a0647ad699636e166c9989b4b91a88909c068a0f3b866b32481303d47e0a1eb29f3cfb1a45d3ba14431a9c8aece0aa85b37
7
+ data.tar.gz: b6a374374b8070b679bc2d2720f8a97c49116f21f91d63ba202a98838ec110d90e61c18936963e2aeaa0ff613a3c3fbe89c7ac48c151495045690e46eacd35c7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.1.10] - 2025-03-26
2
+
3
+ - async_bean support
4
+ - rename for 'copy' files
5
+ - add diagnostics for missing locale
6
+ - link in error locale hover leads to the correct line
7
+ - missing locale notification
8
+
1
9
  ## [0.1.8] - 2025-03-21
2
10
 
3
11
  - hover: show missing locales
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-lsp-ree (0.1.9)
4
+ ruby-lsp-ree (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -10,15 +10,22 @@ Ree addon for Ruby LSP
10
10
  If everything was installed successfully, you should see Ree in the list of Ruby LSP addons.
11
11
  (In VS Code click `{}` brackets in the bottom right corner)
12
12
 
13
- To use ree_formatter, add the following line into you `settings.json` file (e.g. `.vscode/settings.json`)
13
+ To use ree_formatter, add the following line into your `settings.json` file (e.g. `.vscode/settings.json`)
14
14
  ```json
15
15
  "rubyLsp.formatter": "ree_formatter"
16
16
  ```
17
17
 
18
+ To use diagnostics, add the following line into your `settings.json` file (e.g. `.vscode/settings.json`)
19
+ ```json
20
+ "rubyLsp.linters": ["ree_formatter"]
21
+ ```
22
+
18
23
  ## Functions
19
24
 
20
- - autocomplete for Ree functions
25
+ - autocomplete for Ree objects
21
26
  - autocomplete for constants
22
27
  - adds links to the links section on autocomplete
23
28
  - sort links on document save or format (with ree_formatter enabled)
24
- - Go To Definition for Ree functions
29
+ - missing error locales detection
30
+ - Go To Definition for Ree objects
31
+ - hover information for Ree objects and error locales
@@ -17,7 +17,7 @@ module RubyLsp
17
17
  @message_queue = message_queue
18
18
  @template_applicator = RubyLsp::Ree::ReeTemplateApplicator.new
19
19
 
20
- global_state.register_formatter("ree_formatter", RubyLsp::Ree::ReeFormatter.new)
20
+ global_state.register_formatter("ree_formatter", RubyLsp::Ree::ReeFormatter.new(@message_queue))
21
21
  register_additional_file_watchers(global_state, message_queue)
22
22
  end
23
23
 
@@ -1,8 +1,12 @@
1
1
  module RubyLsp
2
2
  module Ree
3
3
  class BaseFormatter
4
- def self.call(source, uri)
5
- new.call(source, uri)
4
+ def self.call(source, uri, message_queue)
5
+ new(message_queue).call(source, uri)
6
+ end
7
+
8
+ def initialize(message_queue)
9
+ @message_queue = message_queue
6
10
  end
7
11
 
8
12
  def call(source, uri)
@@ -11,7 +11,7 @@ module RubyLsp
11
11
  def call(source, uri)
12
12
  parsed_doc = RubyLsp::Ree::ParsedDocumentBuilder.build_from_source(source)
13
13
 
14
- locales_folder = package_locales_folder_path(URI.parse(uri.to_s).path)
14
+ locales_folder = package_locales_folder_path(get_uri_path(uri))
15
15
  return source if !locales_folder || !File.directory?(locales_folder)
16
16
 
17
17
  result = []
@@ -34,7 +34,8 @@ module RubyLsp
34
34
  unless value
35
35
  loc_key = File.basename(locale_file, '.yml')
36
36
 
37
- add_locale_placeholder(locale_file, key_path)
37
+ add_locale_placeholder(locale_file, key_path)
38
+ send_message(locale_file, key_path)
38
39
  end
39
40
  end
40
41
  end
@@ -77,7 +78,20 @@ module RubyLsp
77
78
 
78
79
  lines = File.read(file_path).lines
79
80
  lines[last_found_key.line] += adding_string
80
- File.write(file_path, lines.join)
81
+
82
+ new_source = lines.join.force_encoding("utf-8")
83
+ File.open(file_path, 'wb:UTF-8'){|f|
84
+ f.write(new_source)
85
+ }
86
+
87
+ new_source
88
+ end
89
+
90
+ def send_message(locale_file, key_path)
91
+ loc_key = File.basename(locale_file, '.yml')
92
+
93
+ message = "Missing locale #{loc_key}: #{key_path}"
94
+ @message_queue << RubyLsp::Notification.window_show_message(message, type: Constant::MessageType::ERROR)
81
95
  end
82
96
  end
83
97
  end
@@ -7,7 +7,7 @@ module RubyLsp
7
7
  include Requests::Support::Common
8
8
  include RubyLsp::Ree::ReeLspUtils
9
9
 
10
- RECEIVER_OBJECT_TYPES = [:enum, :dao, :bean]
10
+ RECEIVER_OBJECT_TYPES = [:enum, :dao, :bean, :async_bean]
11
11
  CANDIDATES_LIMIT = 100
12
12
 
13
13
  def initialize(index, uri, node_context)
@@ -30,7 +30,7 @@ module RubyLsp
30
30
  case @finder.object_type(ree_receiver)
31
31
  when :enum
32
32
  get_enum_values_completion_items(ree_receiver, location)
33
- when :bean
33
+ when :bean, :async_bean
34
34
  get_bean_methods_completion_items(ree_receiver, location)
35
35
  when :dao
36
36
  get_dao_filters_completion_items(ree_receiver, location)
@@ -86,7 +86,7 @@ module RubyLsp
86
86
  if value
87
87
  if value == MISSING_LOCALE_PLACEHOLDER
88
88
  value_location = find_locale_key_location(locale_file, key_path)
89
- file_uri = "#{locale_file}" # TODO add line to uri :#{value_location.line+1}:#{value_location.column}"
89
+ file_uri = "file://#{locale_file}##{value_location.line+1}"
90
90
  documentation += "#{loc_key}: [#{value}](#{file_uri})\n\n"
91
91
  else
92
92
  documentation += "#{loc_key}: #{value}\n\n"
@@ -106,7 +106,7 @@ class RubyLsp::Ree::ParsedDocument
106
106
  def parse_bean_node
107
107
  return unless class_node
108
108
 
109
- @bean_node ||= class_node.body.body.detect{ |node| node_name(node) == :bean }
109
+ @bean_node ||= class_node.body.body.detect{ |node| node_name(node) == :bean || node_name(node) == :async_bean}
110
110
  @links_container_block_node ||= @bean_node&.block
111
111
  end
112
112
 
@@ -1,7 +1,7 @@
1
1
  require 'prism'
2
2
 
3
3
  class RubyLsp::Ree::ParsedMethodNode
4
- attr_reader :method_node, :contract_node
4
+ attr_reader :method_node, :contract_node, :nested_local_methods
5
5
 
6
6
  def initialize(method_node, contract_node)
7
7
  @method_node = method_node
@@ -89,8 +89,10 @@ class RubyLsp::Ree::ParsedMethodNode
89
89
  return
90
90
  end
91
91
 
92
+ method_body = get_method_body(@method_node)
93
+
92
94
  local_method_names = local_methods.map(&:name)
93
- call_nodes = parse_body_call_objects(@method_node.body.body)
95
+ call_nodes = parse_body_call_objects(method_body)
94
96
  call_node_names = call_nodes.map(&:name)
95
97
 
96
98
  @nested_local_methods = local_methods.select{ call_node_names.include?(_1.name) }
@@ -112,4 +114,12 @@ class RubyLsp::Ree::ParsedMethodNode
112
114
 
113
115
  call_nodes
114
116
  end
117
+
118
+ def get_method_body(node)
119
+ if node.body.is_a?(Prism::BeginNode)
120
+ node.body.statements.body
121
+ else
122
+ node.body.body
123
+ end
124
+ end
115
125
  end
@@ -10,6 +10,12 @@ module RubyLsp
10
10
  include RubyLsp::Ree::ReeLspUtils
11
11
  include RubyLsp::Ree::ReeLocaleUtils
12
12
 
13
+ MISSING_LOCALE_PLACEHOLDER = '_MISSING_LOCALE_'
14
+
15
+ def initialize(message_queue)
16
+ @message_queue = message_queue
17
+ end
18
+
13
19
  def run_formatting(uri, document)
14
20
  source = document.source
15
21
 
@@ -20,13 +26,12 @@ module RubyLsp
20
26
  RubyLsp::Ree::MissingErrorLocalesFormatter
21
27
  ]
22
28
 
23
- formatters.reduce(source){ |s, formatter| formatter.call(s, uri) }
29
+ formatters.reduce(source){ |s, formatter| formatter.call(s, uri, @message_queue) }
24
30
  rescue => e
25
31
  $stderr.puts("error in ree_formatter: #{e.message} : #{e.backtrace.first}")
26
32
  end
27
33
 
28
34
  def run_diagnostic(uri, document)
29
- $stderr.puts("ree_formatter_diagnostic")
30
35
  detect_missing_error_locales(uri, document)
31
36
  rescue => e
32
37
  $stderr.puts("error in ree_formatter_diagnostic: #{e.message} : #{e.backtrace.first}")
@@ -38,10 +43,11 @@ module RubyLsp
38
43
  parsed_doc = RubyLsp::Ree::ParsedDocumentBuilder.build_from_source(document.source)
39
44
 
40
45
  locales_folder = package_locales_folder_path(uri.path)
41
- return [] unless File.directory?(locales_folder)
46
+ return [] if !locales_folder || !File.directory?(locales_folder)
42
47
 
43
48
  result = []
44
- key_paths = []
49
+ error_keys = []
50
+
45
51
  parsed_doc.parse_error_definitions
46
52
  parsed_doc.error_definitions.each do |error_definition|
47
53
  key_path = if error_definition.value.arguments.arguments.size > 1
@@ -51,27 +57,24 @@ module RubyLsp
51
57
  "#{mod}.errors.#{error_definition.value.arguments.arguments[0].unescaped}"
52
58
  end
53
59
 
54
- key_paths << key_path
60
+ error_keys << [key_path, error_definition]
55
61
  end
56
62
 
57
- $stderr.puts("ree_formatter_diagnostic #{key_paths}")
58
-
59
63
  Dir.glob(File.join(locales_folder, '**/*.yml')).each do |locale_file|
60
- key_paths.each do |key_path|
64
+ error_keys.each do |error_key|
65
+ key_path = error_key[0]
61
66
  value = find_locale_value(locale_file, key_path)
62
- unless value
67
+ if !value || value == MISSING_LOCALE_PLACEHOLDER
63
68
  loc_key = File.basename(locale_file, '.yml')
69
+ error_definition = error_key[1]
64
70
 
65
- $stderr.puts("ree_formatter_diagnostic add diagnostic")
66
-
67
- # TODO correct error range
68
71
  result << RubyLsp::Interface::Diagnostic.new(
69
72
  message: "Missing locale #{loc_key}: #{key_path}",
70
73
  source: "Ree formatter",
71
74
  severity: RubyLsp::Constant::DiagnosticSeverity::ERROR,
72
75
  range: RubyLsp::Interface::Range.new(
73
- start: RubyLsp::Interface::Position.new(line: 0, character: 0),
74
- end: RubyLsp::Interface::Position.new(line: 0, character: 0),
76
+ start: RubyLsp::Interface::Position.new(line: error_definition.location.start_line-1, character: error_definition.name_loc.start_column),
77
+ end: RubyLsp::Interface::Position.new(line: error_definition.location.start_line-1, character: error_definition.name_loc.end_column),
75
78
  ),
76
79
  )
77
80
  end
@@ -6,7 +6,7 @@ module RubyLsp
6
6
  class ReeIndexingEnhancement < RubyIndexer::Enhancement
7
7
  include RubyLsp::Ree::ReeLspUtils
8
8
 
9
- REE_INDEXED_OBJECTS = [:fn, :enum, :action, :dao, :bean, :mapper, :aggregate]
9
+ REE_INDEXED_OBJECTS = [:fn, :enum, :action, :dao, :bean, :mapper, :aggregate, :async_bean]
10
10
 
11
11
  def on_call_node_enter(node)
12
12
  return unless @listener.current_owner
@@ -4,15 +4,23 @@ module RubyLsp
4
4
  include RubyLsp::Ree::ReeLspUtils
5
5
 
6
6
  def self.call(changes)
7
+ new.call(changes)
8
+ end
9
+
10
+ def call(changes)
7
11
  old_uri = URI.parse(changes.detect{ _1[:type] == Constant::FileChangeType::DELETED }[:uri])
8
12
  new_uri = URI.parse(changes.detect{ _1[:type] == Constant::FileChangeType::CREATED }[:uri])
13
+
14
+ old_path = get_uri_path(old_uri)
15
+ new_path = get_uri_path(new_uri)
9
16
 
10
- old_file_name = File.basename(old_uri, '.rb')
11
- new_file_name = File.basename(new_uri, '.rb')
17
+ old_file_name = File.basename(old_path, '.rb').chomp(" copy")
18
+ new_file_name = File.basename(new_path, '.rb')
12
19
 
13
20
  return if old_file_name == new_file_name
14
21
 
15
22
  parsed_doc = RubyLsp::Ree::ParsedDocumentBuilder.build_from_uri(new_uri)
23
+
16
24
  return if !parsed_doc || !parsed_doc.class_node
17
25
 
18
26
  old_class_name = old_file_name.split('_').collect(&:capitalize).join
@@ -20,7 +28,7 @@ module RubyLsp
20
28
 
21
29
  return unless parsed_doc.class_name == old_class_name
22
30
 
23
- file_content_lines = File.read(new_uri.path).lines
31
+ file_content_lines = File.read(new_path).lines
24
32
 
25
33
  class_line = parsed_doc.class_node.location.start_line - 1
26
34
 
@@ -32,7 +40,7 @@ module RubyLsp
32
40
  file_content_lines[links_container_node_line].gsub!(/\b#{old_file_name}\b/, new_file_name)
33
41
  end
34
42
 
35
- File.write(new_uri.path, file_content_lines.join)
43
+ File.write(new_path, file_content_lines.join)
36
44
  end
37
45
  end
38
46
  end
@@ -23,7 +23,9 @@ module RubyLsp
23
23
 
24
24
  def apply(change_item)
25
25
  uri = change_item[:uri]
26
- path = URI.parse(uri).path
26
+ path = get_uri_path(uri)
27
+
28
+ return unless File.exist?(path)
27
29
 
28
30
  file_content = File.read(path)
29
31
  return if file_content.size > 0
@@ -3,6 +3,10 @@ module RubyLsp
3
3
  module ReeLspUtils
4
4
  Entry = RubyIndexer::Entry
5
5
 
6
+ def get_uri_path(uri)
7
+ URI.decode_www_form_component(URI.parse(uri.to_s).path)
8
+ end
9
+
6
10
  def find_local_file_path(file_path)
7
11
  file_name = file_path + ".rb"
8
12
  Dir[File.join('**', file_name)].first
@@ -11,7 +11,7 @@ module RubyLsp
11
11
  class YamlFileParser
12
12
  def self.parse(file_path)
13
13
  parser = Psych::Parser.new(Psych::TreeBuilder.new)
14
- parser.parse(File.read(file_path))
14
+ parser.parse(File.read(file_path, encoding: 'utf-8'))
15
15
 
16
16
  parse_result = NodeVisitor.create.accept(parser.handler.root)
17
17
  normalize_hash_keys(parse_result.first)
@@ -19,7 +19,7 @@ module RubyLsp
19
19
 
20
20
  def self.parse_with_key_coordinates(file_path)
21
21
  parser = Psych::Parser.new(Psych::TreeBuilder.new)
22
- parser.parse(File.read(file_path))
22
+ parser.parse(File.read(file_path, encoding: 'utf-8'))
23
23
 
24
24
  NodeVisitor.create.accept(parser.handler.root).first
25
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLsp
4
4
  module Ree
5
- VERSION = "0.1.9"
5
+ VERSION = "0.1.10"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-ree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-21 00:00:00.000000000 Z
11
+ date: 2025-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby LSP addon that adds extra editor functionality for Ree applications
14
14
  email: