ruby-lsp-ree 0.1.4 → 0.1.5
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 +5 -0
- data/Gemfile.lock +1 -1
- data/lib/ruby_lsp/ruby_lsp_ree/addon.rb +39 -0
- data/lib/ruby_lsp/ruby_lsp_ree/handlers/hover_handler.rb +6 -6
- data/lib/ruby_lsp/ruby_lsp_ree/ree_object_finder.rb +4 -15
- data/lib/ruby_lsp/ruby_lsp_ree/ree_template_applicator.rb +100 -0
- data/lib/ruby_lsp/ruby_lsp_ree/utils/ree_lsp_utils.rb +18 -1
- data/lib/ruby_lsp_ree/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c8f904d1cf98e1106296f608f265999c5c606fc83473d3e65a05395dd83ace5
|
4
|
+
data.tar.gz: daba84c44a1bf697f80ec7589ab0a9a436af14aa5d9d8cc6cb12377623de5e8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 318c26fe57dcc12ac7a2209c10abd65b5662034e00eb87fea1a2ea58107ccd955db3b1e22a40c80f0a92e1ff10fef0f27c5a1ed3964b7877daa15dd5c64c61d4
|
7
|
+
data.tar.gz: 13c136bd68c1aa9f505a79b94d6f30b713e4e7f24b22a2157c5ccdadc1300d57e27fd7fb4bc5d75f55e7a441125dccf10d6923048948ec416616d7dd723936b1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,6 +5,7 @@ require_relative "listeners/hover_listener"
|
|
5
5
|
require_relative "ree_indexing_enhancement"
|
6
6
|
require_relative "utils/ree_lsp_utils"
|
7
7
|
require_relative "ree_formatter"
|
8
|
+
require_relative "ree_template_applicator"
|
8
9
|
require_relative "parsing/parsed_document_builder"
|
9
10
|
|
10
11
|
module RubyLsp
|
@@ -13,8 +14,10 @@ module RubyLsp
|
|
13
14
|
def activate(global_state, message_queue)
|
14
15
|
@global_state = global_state
|
15
16
|
@message_queue = message_queue
|
17
|
+
@template_applicator = RubyLsp::Ree::ReeTemplateApplicator.new
|
16
18
|
|
17
19
|
global_state.register_formatter("ree_formatter", RubyLsp::Ree::ReeFormatter.new)
|
20
|
+
register_additional_file_watchers(global_state, message_queue)
|
18
21
|
end
|
19
22
|
|
20
23
|
def deactivate
|
@@ -38,6 +41,42 @@ module RubyLsp
|
|
38
41
|
index = @global_state.index
|
39
42
|
RubyLsp::Ree::HoverListener.new(response_builder, node_context, index, dispatcher)
|
40
43
|
end
|
44
|
+
|
45
|
+
def register_additional_file_watchers(global_state, message_queue)
|
46
|
+
# Clients are not required to implement this capability
|
47
|
+
return unless global_state.supports_watching_files
|
48
|
+
|
49
|
+
return unless @template_applicator.template_dir_exists?
|
50
|
+
|
51
|
+
message_queue << Request.new(
|
52
|
+
id: "ruby-lsp-ree-file-create-watcher",
|
53
|
+
method: "client/registerCapability",
|
54
|
+
params: Interface::RegistrationParams.new(
|
55
|
+
registrations: [
|
56
|
+
Interface::Registration.new(
|
57
|
+
id: "workspace/didCreateWatchedFilesRee",
|
58
|
+
method: "workspace/didChangeWatchedFiles",
|
59
|
+
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
|
60
|
+
watchers: [
|
61
|
+
Interface::FileSystemWatcher.new(
|
62
|
+
glob_pattern: "**/*.rb",
|
63
|
+
kind: Constant::WatchKind::CREATE,
|
64
|
+
),
|
65
|
+
],
|
66
|
+
),
|
67
|
+
),
|
68
|
+
],
|
69
|
+
),
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def workspace_did_change_watched_files(changes)
|
74
|
+
$stderr.puts("workspace_did_change_watched_files #{changes.inspect}")
|
75
|
+
|
76
|
+
changes.each do |change_item|
|
77
|
+
@template_applicator.apply(change_item)
|
78
|
+
end
|
79
|
+
end
|
41
80
|
end
|
42
81
|
end
|
43
82
|
end
|
@@ -21,13 +21,13 @@ module RubyLsp
|
|
21
21
|
return [] unless ree_object
|
22
22
|
|
23
23
|
documentation = <<~DOC
|
24
|
-
|
24
|
+
\`\`\`ruby
|
25
|
+
#{node.name.to_s}#{get_detail_string(ree_object)}
|
26
|
+
\`\`\`
|
27
|
+
---
|
28
|
+
ree type: :#{@finder.object_type(ree_object)} package: #{package_name_from_uri(ree_object.uri)}
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
package: #{package_name_from_uri(ree_object.uri)}
|
29
|
-
|
30
|
-
file: #{path_from_package_folder(ree_object.uri)}
|
30
|
+
[#{path_from_package_folder(ree_object.uri)}](#{ree_object.uri})
|
31
31
|
DOC
|
32
32
|
|
33
33
|
[documentation]
|
@@ -71,21 +71,10 @@ module RubyLsp
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def object_type(ree_object)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
when BEAN_TYPE_STRING
|
79
|
-
:bean
|
80
|
-
when ENUM_TYPE_STRING
|
81
|
-
:enum
|
82
|
-
when MAPPER_TYPE_STRING
|
83
|
-
:mapper
|
84
|
-
when AGGREGATE_TYPE_STRING
|
85
|
-
:aggregate
|
86
|
-
else
|
87
|
-
nil
|
88
|
-
end
|
74
|
+
type_str = ree_object.comments.lines[1]&.chomp
|
75
|
+
return unless type_str
|
76
|
+
|
77
|
+
type_str.split(' ').last[1..-1].to_sym
|
89
78
|
end
|
90
79
|
end
|
91
80
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module RubyLsp
|
2
|
+
module Ree
|
3
|
+
class ReeTemplateApplicator
|
4
|
+
include RubyLsp::Ree::ReeLspUtils
|
5
|
+
|
6
|
+
TEMPLATES_FOLDER = '.vscode-ree/templates'
|
7
|
+
DEFAULT_TEMPLATE_FILENAME = 'default.rb'
|
8
|
+
RSPEC_TEMPLATE_PATH = 'spec_template.rb'
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
return unless template_dir_exists?
|
12
|
+
|
13
|
+
@template_types = Dir
|
14
|
+
.entries(TEMPLATES_FOLDER)
|
15
|
+
.select{ |entry|
|
16
|
+
File.directory? File.join(TEMPLATES_FOLDER,entry) and !(entry =='.' || entry == '..')
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def template_dir_exists?
|
21
|
+
File.exist?(TEMPLATES_FOLDER)
|
22
|
+
end
|
23
|
+
|
24
|
+
def apply(change_item)
|
25
|
+
uri = change_item[:uri]
|
26
|
+
path = URI.parse(uri).path
|
27
|
+
|
28
|
+
file_content = File.read(path)
|
29
|
+
return if file_content.size > 0
|
30
|
+
|
31
|
+
if path.end_with?('_spec.rb')
|
32
|
+
template_str = fetch_rspec_template
|
33
|
+
template_info = fetch_rspec_template_info(uri)
|
34
|
+
else
|
35
|
+
template_type = get_template_type_from_uri(uri)
|
36
|
+
return unless template_type
|
37
|
+
|
38
|
+
template_str = fetch_template(template_type)
|
39
|
+
template_info = fetch_template_info(uri)
|
40
|
+
end
|
41
|
+
|
42
|
+
template_content = replace_placeholders(template_str, template_info)
|
43
|
+
|
44
|
+
File.write(path, template_content)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_template_type_from_uri(uri)
|
48
|
+
uri_parts = File.dirname(uri).split('/')
|
49
|
+
|
50
|
+
uri_parts.reverse.detect{ @template_types.include?(_1) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_template(template_type)
|
54
|
+
File.read(File.join(TEMPLATES_FOLDER, template_type, DEFAULT_TEMPLATE_FILENAME))
|
55
|
+
end
|
56
|
+
|
57
|
+
def fetch_rspec_template
|
58
|
+
File.read(File.join(TEMPLATES_FOLDER, RSPEC_TEMPLATE_PATH))
|
59
|
+
end
|
60
|
+
|
61
|
+
def fetch_template_info(uri)
|
62
|
+
object_name = File.basename(uri, '.rb')
|
63
|
+
object_class = object_name.split('_').collect(&:capitalize).join
|
64
|
+
package_name = package_name_from_uri(uri)
|
65
|
+
package_class = package_name.split('_').collect(&:capitalize).join
|
66
|
+
|
67
|
+
{
|
68
|
+
'PACKAGE_MODULE' => package_class,
|
69
|
+
'PACKAGE_NAME' => package_name,
|
70
|
+
'OBJECT_CLASS' => object_class,
|
71
|
+
'OBJECT_NAME' => object_name,
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch_rspec_template_info(uri)
|
76
|
+
object_name = File.basename(uri, '.rb')
|
77
|
+
object_class = object_name.split('_').collect(&:capitalize).join
|
78
|
+
package_name = package_name_from_spec_uri(uri)
|
79
|
+
package_class = package_name.split('_').collect(&:capitalize).join
|
80
|
+
file_path = spec_relative_file_path_from_uri(URI(uri))&.delete_suffix('_spec')
|
81
|
+
|
82
|
+
{
|
83
|
+
'RELATIVE_FILE_PATH' => file_path,
|
84
|
+
'MODULE_NAME' => package_class,
|
85
|
+
'CLASS_NAME' => object_class,
|
86
|
+
'OBJECT_NAME' => object_name,
|
87
|
+
'PACKAGE_NAME' => package_name,
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def replace_placeholders(template_str, template_info)
|
92
|
+
template_info.each do |k,v|
|
93
|
+
template_str.gsub!(k, v)
|
94
|
+
end
|
95
|
+
|
96
|
+
template_str
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -17,8 +17,17 @@ module RubyLsp
|
|
17
17
|
uri_parts[package_folder_index + 1]
|
18
18
|
end
|
19
19
|
|
20
|
+
def package_name_from_spec_uri(uri)
|
21
|
+
uri_parts = uri.to_s.split('/')
|
22
|
+
|
23
|
+
spec_folder_index = uri_parts.find_index('spec')
|
24
|
+
return unless spec_folder_index
|
25
|
+
|
26
|
+
uri_parts[spec_folder_index + 1]
|
27
|
+
end
|
28
|
+
|
20
29
|
def path_from_package_folder(uri)
|
21
|
-
uri_parts = uri.to_s.chomp(File.extname(uri)).split('/')
|
30
|
+
uri_parts = uri.to_s.chomp(File.extname(uri.to_s)).split('/')
|
22
31
|
|
23
32
|
package_folder_index = uri_parts.index('package')
|
24
33
|
return unless package_folder_index
|
@@ -26,6 +35,14 @@ module RubyLsp
|
|
26
35
|
uri_parts.drop(package_folder_index+1).join('/')
|
27
36
|
end
|
28
37
|
|
38
|
+
def spec_relative_file_path_from_uri(uri)
|
39
|
+
uri_parts = uri.path.split('/')
|
40
|
+
spec_folder_index = uri_parts.index('spec')
|
41
|
+
return unless spec_folder_index
|
42
|
+
|
43
|
+
uri_parts[spec_folder_index+1..-1].join('/').chomp('.rb')
|
44
|
+
end
|
45
|
+
|
29
46
|
def get_ree_type(ree_object)
|
30
47
|
type_comment = ree_object.comments.to_s.lines[1]
|
31
48
|
return unless type_comment
|
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.5
|
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-02-
|
11
|
+
date: 2025-02-28 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:
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb
|
40
40
|
- lib/ruby_lsp/ruby_lsp_ree/ree_indexing_enhancement.rb
|
41
41
|
- lib/ruby_lsp/ruby_lsp_ree/ree_object_finder.rb
|
42
|
+
- lib/ruby_lsp/ruby_lsp_ree/ree_template_applicator.rb
|
42
43
|
- lib/ruby_lsp/ruby_lsp_ree/utils/ree_lsp_utils.rb
|
43
44
|
- lib/ruby_lsp_ree.rb
|
44
45
|
- lib/ruby_lsp_ree/version.rb
|