ruby-lsp-ree 0.1.8 → 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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -3
- data/lib/ruby_lsp/ruby_lsp_ree/addon.rb +1 -1
- data/lib/ruby_lsp/ruby_lsp_ree/formatters/base_formatter.rb +6 -2
- data/lib/ruby_lsp/ruby_lsp_ree/formatters/missing_error_locales_formatter.rb +17 -3
- data/lib/ruby_lsp/ruby_lsp_ree/handlers/completion_handler.rb +2 -2
- data/lib/ruby_lsp/ruby_lsp_ree/handlers/hover_handler.rb +1 -1
- data/lib/ruby_lsp/ruby_lsp_ree/parsing/parsed_document.rb +3 -2
- data/lib/ruby_lsp/ruby_lsp_ree/parsing/parsed_document_builder.rb +8 -12
- data/lib/ruby_lsp/ruby_lsp_ree/parsing/parsed_method_node.rb +12 -2
- data/lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb +17 -14
- data/lib/ruby_lsp/ruby_lsp_ree/ree_indexing_enhancement.rb +1 -1
- data/lib/ruby_lsp/ruby_lsp_ree/ree_rename_handler.rb +12 -4
- data/lib/ruby_lsp/ruby_lsp_ree/ree_template_applicator.rb +3 -1
- data/lib/ruby_lsp/ruby_lsp_ree/utils/ree_lsp_utils.rb +4 -0
- data/lib/ruby_lsp/ruby_lsp_ree/utils/yaml_file_parser.rb +2 -2
- data/lib/ruby_lsp_ree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 363caa1c6e2f1d4bdedac1791e0edf969fab9fa7037039a6146de7f0d98d0056
|
4
|
+
data.tar.gz: 750e5d2bba1606b9f50d465b7a86aafb830ee43c18637053421b68e59fabf1f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
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
|
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
|
-
-
|
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(
|
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
|
-
|
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 = "
|
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"
|
@@ -28,8 +28,9 @@ class RubyLsp::Ree::ParsedDocument
|
|
28
28
|
:bean_node, :bean_methods, :mapper_node, :links_container_block_node, :aggregate_node,
|
29
29
|
:error_definitions, :error_definition_names, :doc_instance_methods
|
30
30
|
|
31
|
-
def initialize(ast)
|
31
|
+
def initialize(ast, package_name = nil)
|
32
32
|
@ast = ast
|
33
|
+
set_package_name(package_name) if package_name
|
33
34
|
end
|
34
35
|
|
35
36
|
def links_container_node
|
@@ -105,7 +106,7 @@ class RubyLsp::Ree::ParsedDocument
|
|
105
106
|
def parse_bean_node
|
106
107
|
return unless class_node
|
107
108
|
|
108
|
-
@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}
|
109
110
|
@links_container_block_node ||= @bean_node&.block
|
110
111
|
end
|
111
112
|
|
@@ -7,20 +7,16 @@ class RubyLsp::Ree::ParsedDocumentBuilder
|
|
7
7
|
|
8
8
|
def self.build_from_uri(uri, type = nil)
|
9
9
|
ast = Prism.parse_file(uri.path).value
|
10
|
-
document = build_document(ast, type)
|
10
|
+
document = build_document(ast, type, package_name_from_uri(uri))
|
11
11
|
return unless document
|
12
12
|
|
13
|
-
document.set_package_name(package_name_from_uri(uri))
|
14
|
-
|
15
13
|
document
|
16
14
|
end
|
17
15
|
|
18
16
|
def self.build_from_ast(ast, uri, type = nil)
|
19
|
-
document = build_document(ast, type)
|
17
|
+
document = build_document(ast, type, package_name_from_uri(uri))
|
20
18
|
return unless document
|
21
19
|
|
22
|
-
document.set_package_name(package_name_from_uri(uri))
|
23
|
-
|
24
20
|
document
|
25
21
|
end
|
26
22
|
|
@@ -29,7 +25,7 @@ class RubyLsp::Ree::ParsedDocumentBuilder
|
|
29
25
|
build_document(ast, type)
|
30
26
|
end
|
31
27
|
|
32
|
-
def self.build_document(ast, type)
|
28
|
+
def self.build_document(ast, type, package_name = nil)
|
33
29
|
case type
|
34
30
|
when :enum
|
35
31
|
build_enum_document(ast)
|
@@ -38,13 +34,13 @@ class RubyLsp::Ree::ParsedDocumentBuilder
|
|
38
34
|
when :bean
|
39
35
|
build_bean_document(ast)
|
40
36
|
else
|
41
|
-
build_detected_document_type(ast)
|
37
|
+
build_detected_document_type(ast, package_name)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
45
|
-
def self.build_detected_document_type(ast)
|
41
|
+
def self.build_detected_document_type(ast, package_name = nil)
|
46
42
|
if has_root_class?(ast)
|
47
|
-
build_regular_document(ast)
|
43
|
+
build_regular_document(ast, package_name)
|
48
44
|
elsif has_root_rspec_call?(ast)
|
49
45
|
build_rspec_document(ast)
|
50
46
|
else
|
@@ -69,8 +65,8 @@ class RubyLsp::Ree::ParsedDocumentBuilder
|
|
69
65
|
document
|
70
66
|
end
|
71
67
|
|
72
|
-
def self.build_regular_document(ast)
|
73
|
-
document = RubyLsp::Ree::ParsedDocument.new(ast)
|
68
|
+
def self.build_regular_document(ast, package_name)
|
69
|
+
document = RubyLsp::Ree::ParsedDocument.new(ast, package_name)
|
74
70
|
|
75
71
|
document.parse_class_node
|
76
72
|
document.parse_fn_node
|
@@ -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(
|
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 []
|
46
|
+
return [] if !locales_folder || !File.directory?(locales_folder)
|
42
47
|
|
43
48
|
result = []
|
44
|
-
|
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
|
-
|
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
|
-
|
64
|
+
error_keys.each do |error_key|
|
65
|
+
key_path = error_key[0]
|
61
66
|
value = find_locale_value(locale_file, key_path)
|
62
|
-
|
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:
|
74
|
-
end: RubyLsp::Interface::Position.new(line:
|
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(
|
11
|
-
new_file_name = File.basename(
|
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(
|
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(
|
43
|
+
File.write(new_path, file_content_lines.join)
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
@@ -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
|
data/lib/ruby_lsp_ree/version.rb
CHANGED
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.
|
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-
|
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:
|