ruby-lsp-ree 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +24 -0
- data/Rakefile +4 -0
- data/lib/ruby_lsp/ruby_lsp_ree/addon.rb +40 -0
- data/lib/ruby_lsp/ruby_lsp_ree/completion.rb +165 -0
- data/lib/ruby_lsp/ruby_lsp_ree/definition.rb +38 -0
- data/lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb +71 -0
- data/lib/ruby_lsp/ruby_lsp_ree/ree_indexing_enhancement.rb +56 -0
- data/lib/ruby_lsp/ruby_lsp_ree/ree_lsp_utils.rb +105 -0
- data/lib/ruby_lsp_ree/version.rb +9 -0
- data/lib/ruby_lsp_ree.rb +3 -0
- data/ruby-lsp-ree.gemspec +31 -0
- data/sig/ruby/lsp/ree.rbs +8 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 925a5297663b9b4e653e9c837cd6bfc8942c5445f657619f867699b33e765809
|
4
|
+
data.tar.gz: 3d3d73751c5c60d3b55ab426b896dcfcc633c921ab0b33ca7ba1aea4b1ae04dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46a0c311c26ffe7bea0bc546476cf92a7b45f620b1d38c261be5c409b4c75b0249bfea393bc532166b461d2373491f1093bd1be3afa44b1dd2530ae67f8cf77f
|
7
|
+
data.tar.gz: e150468d50597f9be7988891972bd708710ecc2991dadb512c36bada2bcbf4f619873435744a4b7f0b95f6eda7dc180d8e4edeec9c487de4e5084be99c59c0b8
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at oleg0potapov+1@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Ruslan Gatiyatov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Ruby::Lsp::Ree
|
2
|
+
|
3
|
+
Ree addon for Ruby LSP
|
4
|
+
|
5
|
+
## How to use it:
|
6
|
+
|
7
|
+
1. Install Ruby LSP for your editor [link](https://github.com/Shopify/ruby-lsp?tab=readme-ov-file#getting-started)
|
8
|
+
2. Add `ree` gem into the Gemfile and run `bundle install`. Ruby LSP will detect the addon and run it.
|
9
|
+
|
10
|
+
If everything was installed successfully, you should see Ree in the list of Ruby LSP addons.
|
11
|
+
(In VS Code click `{}` brackets in the bottom right corner)
|
12
|
+
|
13
|
+
To use ree_formatter, add the following line into you `settings.json` file (e.g. `.vscode/settings.json`)
|
14
|
+
```json
|
15
|
+
"rubyLsp.formatter": "ree_formatter"
|
16
|
+
```
|
17
|
+
|
18
|
+
## Functions
|
19
|
+
|
20
|
+
- autocomplete for Ree functions
|
21
|
+
- autocomplete for constants
|
22
|
+
- adds links to the links section on autocomplete
|
23
|
+
- sort links on document save or format (with ree_formatter enabled)
|
24
|
+
- Go To Definition for Ree functions
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "ruby_lsp/addon"
|
2
|
+
require_relative "definition"
|
3
|
+
require_relative "completion"
|
4
|
+
require_relative "ree_indexing_enhancement"
|
5
|
+
require_relative "ree_lsp_utils"
|
6
|
+
require_relative "ree_formatter"
|
7
|
+
|
8
|
+
module RubyLsp
|
9
|
+
module Ree
|
10
|
+
class Addon < ::RubyLsp::Addon
|
11
|
+
def activate(global_state, message_queue)
|
12
|
+
@global_state = global_state
|
13
|
+
@message_queue = message_queue
|
14
|
+
|
15
|
+
global_state.register_formatter("ree_formatter", RubyLsp::Ree::ReeFormatter.new)
|
16
|
+
end
|
17
|
+
|
18
|
+
def deactivate
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
"Ree Addon"
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_definition_listener(response_builder, uri, node_context, dispatcher)
|
26
|
+
$stderr.puts("create_definition_listener")
|
27
|
+
|
28
|
+
index = @global_state.index
|
29
|
+
RubyLsp::Ree::Definition.new(response_builder, node_context, index, dispatcher)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_completion_listener(response_builder, node_context, dispatcher, uri)
|
33
|
+
$stderr.puts("create_completion_listener")
|
34
|
+
|
35
|
+
index = @global_state.index
|
36
|
+
RubyLsp::Ree::Completion.new(response_builder, node_context, index, dispatcher, uri)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require_relative "ree_lsp_utils"
|
2
|
+
|
3
|
+
module RubyLsp
|
4
|
+
module Ree
|
5
|
+
class Completion
|
6
|
+
include Requests::Support::Common
|
7
|
+
include RubyLsp::Ree::ReeLspUtils
|
8
|
+
|
9
|
+
CHARS_COUNT = 4
|
10
|
+
|
11
|
+
def initialize(response_builder, node_context, index, dispatcher, uri)
|
12
|
+
@response_builder = response_builder
|
13
|
+
@index = index
|
14
|
+
@uri = uri
|
15
|
+
|
16
|
+
dispatcher.register(self, :on_call_node_enter)
|
17
|
+
dispatcher.register(self, :on_constant_read_node_enter)
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_constant_read_node_enter(node)
|
21
|
+
node_name = node.name.to_s
|
22
|
+
return if node_name.size < CHARS_COUNT
|
23
|
+
|
24
|
+
class_name_objects = @index.instance_variable_get(:@entries).keys.select{ _1.split('::').last[0...node_name.size] == node_name}
|
25
|
+
return if class_name_objects.size == 0
|
26
|
+
|
27
|
+
doc_info = parse_document_from_uri(@uri)
|
28
|
+
|
29
|
+
class_name_objects.take(15).each do |full_class_name|
|
30
|
+
entry = @index[full_class_name].first
|
31
|
+
class_name = full_class_name.split('::').last
|
32
|
+
|
33
|
+
package_name = package_name_from_uri(entry.uri)
|
34
|
+
|
35
|
+
label_details = Interface::CompletionItemLabelDetails.new(
|
36
|
+
description: "from: :#{package_name}",
|
37
|
+
detail: ""
|
38
|
+
)
|
39
|
+
|
40
|
+
@response_builder << Interface::CompletionItem.new(
|
41
|
+
label: class_name,
|
42
|
+
label_details: label_details,
|
43
|
+
filter_text: class_name,
|
44
|
+
text_edit: Interface::TextEdit.new(
|
45
|
+
range: range_from_location(node.location),
|
46
|
+
new_text: class_name,
|
47
|
+
),
|
48
|
+
kind: Constant::CompletionItemKind::CLASS,
|
49
|
+
additional_text_edits: get_additional_text_edits_for_constant(doc_info, class_name, package_name, entry)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def on_call_node_enter(node)
|
57
|
+
return if node.receiver
|
58
|
+
return if node.name.to_s.size < CHARS_COUNT
|
59
|
+
|
60
|
+
ree_objects = @index.prefix_search(node.name.to_s)
|
61
|
+
.take(50).map(&:first)
|
62
|
+
.select{ _1.comments }
|
63
|
+
.select{ _1.comments.to_s.lines.first&.chomp == 'ree_object' }
|
64
|
+
.take(10)
|
65
|
+
|
66
|
+
return if ree_objects.size == 0
|
67
|
+
|
68
|
+
doc_info = parse_document_from_uri(@uri)
|
69
|
+
|
70
|
+
ree_objects.each do |ree_object|
|
71
|
+
fn_name = ree_object.name
|
72
|
+
|
73
|
+
package_name = package_name_from_uri(ree_object.uri)
|
74
|
+
|
75
|
+
params_str = ree_object.signatures.first.parameters.map(&:name).join(', ')
|
76
|
+
|
77
|
+
label_details = Interface::CompletionItemLabelDetails.new(
|
78
|
+
description: "from: :#{package_name}",
|
79
|
+
detail: "(#{params_str})"
|
80
|
+
)
|
81
|
+
|
82
|
+
$stderr.puts("ree object #{ree_object.inspect}")
|
83
|
+
|
84
|
+
@response_builder << Interface::CompletionItem.new(
|
85
|
+
label: fn_name,
|
86
|
+
label_details: label_details,
|
87
|
+
filter_text: fn_name,
|
88
|
+
text_edit: Interface::TextEdit.new(
|
89
|
+
range: range_from_location(node.location),
|
90
|
+
new_text: "#{fn_name}(#{params_str})",
|
91
|
+
),
|
92
|
+
kind: Constant::CompletionItemKind::METHOD,
|
93
|
+
data: {
|
94
|
+
owner_name: "Object",
|
95
|
+
guessed_type: false,
|
96
|
+
},
|
97
|
+
additional_text_edits: get_additional_text_edits_for_method(doc_info, fn_name, package_name)
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_additional_text_edits_for_constant(doc_info, class_name, package_name, entry)
|
105
|
+
if doc_info.linked_objects.map(&:imports).flatten.include?(class_name)
|
106
|
+
$stderr.puts("links already include #{class_name}")
|
107
|
+
return []
|
108
|
+
end
|
109
|
+
|
110
|
+
entry_uri = entry.uri.to_s
|
111
|
+
|
112
|
+
link_text = if doc_info.package_name == package_name
|
113
|
+
fn_name = File.basename(entry_uri, ".*")
|
114
|
+
"\n\s\s\s\slink :#{fn_name}, import: -> { #{class_name} }"
|
115
|
+
else
|
116
|
+
path = path_from_package(entry_uri)
|
117
|
+
"\n\s\s\s\slink \"#{path}\", import: -> { #{class_name} }"
|
118
|
+
end
|
119
|
+
|
120
|
+
new_text = link_text
|
121
|
+
|
122
|
+
unless doc_info.block_node
|
123
|
+
new_text = "\sdo#{link_text}\n\s\send\n"
|
124
|
+
end
|
125
|
+
|
126
|
+
range = get_range_for_fn_insert(doc_info, link_text)
|
127
|
+
|
128
|
+
[
|
129
|
+
Interface::TextEdit.new(
|
130
|
+
range: range,
|
131
|
+
new_text: new_text,
|
132
|
+
)
|
133
|
+
]
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_additional_text_edits_for_method(doc_info, fn_name, package_name)
|
137
|
+
if doc_info.linked_objects.map(&:name).include?(fn_name)
|
138
|
+
$stderr.puts("links already include #{fn_name}")
|
139
|
+
return []
|
140
|
+
end
|
141
|
+
|
142
|
+
link_text = if doc_info.package_name == package_name
|
143
|
+
"\n\s\s\s\slink :#{fn_name}"
|
144
|
+
else
|
145
|
+
"\n\s\s\s\slink :#{fn_name}, from: :#{package_name}"
|
146
|
+
end
|
147
|
+
|
148
|
+
new_text = link_text
|
149
|
+
|
150
|
+
unless doc_info.block_node
|
151
|
+
new_text = "\sdo#{link_text}\n\s\send\n"
|
152
|
+
end
|
153
|
+
|
154
|
+
range = get_range_for_fn_insert(doc_info, link_text)
|
155
|
+
|
156
|
+
[
|
157
|
+
Interface::TextEdit.new(
|
158
|
+
range: range,
|
159
|
+
new_text: new_text,
|
160
|
+
)
|
161
|
+
]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RubyLsp
|
2
|
+
module Ree
|
3
|
+
class Definition
|
4
|
+
include Requests::Support::Common
|
5
|
+
|
6
|
+
def initialize(response_builder, node_context, index, dispatcher)
|
7
|
+
@response_builder = response_builder
|
8
|
+
@node_context = node_context
|
9
|
+
@nesting = node_context.nesting
|
10
|
+
@index = index
|
11
|
+
|
12
|
+
# dispatcher.register(self, :on_call_node_enter, :on_symbol_node_enter, :on_string_node_enter)
|
13
|
+
dispatcher.register(self, :on_call_node_enter)
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_call_node_enter(node)
|
17
|
+
message = node.message
|
18
|
+
$stderr.puts("definition on_call_node_enter #{message}")
|
19
|
+
|
20
|
+
return unless message
|
21
|
+
|
22
|
+
method = @index[message].detect{ !_1.location.nil? }
|
23
|
+
|
24
|
+
return unless method
|
25
|
+
|
26
|
+
@response_builder << Interface::Location.new(
|
27
|
+
uri: method.uri.to_s,
|
28
|
+
range: Interface::Range.new(
|
29
|
+
start: Interface::Position.new(line: 0, character: 0),
|
30
|
+
end: Interface::Position.new(line: 0, character: 0),
|
31
|
+
),
|
32
|
+
)
|
33
|
+
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module RubyLsp
|
2
|
+
module Ree
|
3
|
+
class ReeFormatter
|
4
|
+
include RubyLsp::Requests::Support::Formatter
|
5
|
+
include RubyLsp::Ree::ReeLspUtils
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_formatting(uri, document)
|
11
|
+
$stderr.puts("run_formating")
|
12
|
+
|
13
|
+
source = document.source
|
14
|
+
sort_links(source)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def sort_links(source)
|
20
|
+
doc_info = parse_document_from_source(source)
|
21
|
+
|
22
|
+
return source unless doc_info.fn_node
|
23
|
+
return source if doc_info.fn_node && !doc_info.block_node
|
24
|
+
|
25
|
+
if doc_info.link_nodes.size < doc_info.block_node.body.body.size
|
26
|
+
$stderr.puts("block contains not only link, don't sort")
|
27
|
+
return source
|
28
|
+
end
|
29
|
+
|
30
|
+
if doc_info.link_nodes.any?{ _1.location.start_line != _1.location.end_line }
|
31
|
+
$stderr.puts("multiline link definitions, don't sort")
|
32
|
+
return source
|
33
|
+
end
|
34
|
+
|
35
|
+
# sort link nodes
|
36
|
+
sorted_link_nodes = doc_info.link_nodes.sort{ |a, b|
|
37
|
+
a_name = a.arguments.arguments.first
|
38
|
+
b_name = b.arguments.arguments.first
|
39
|
+
|
40
|
+
if a_name.is_a?(Prism::SymbolNode) && !b_name.is_a?(Prism::SymbolNode)
|
41
|
+
-1
|
42
|
+
elsif b_name.is_a?(Prism::SymbolNode) && !a_name.is_a?(Prism::SymbolNode)
|
43
|
+
1
|
44
|
+
else
|
45
|
+
a_name.unescaped <=> b_name.unescaped
|
46
|
+
end
|
47
|
+
}
|
48
|
+
|
49
|
+
# check if no re-order
|
50
|
+
if doc_info.link_nodes.map{ _1.arguments.arguments.first.unescaped } == sorted_link_nodes.map{ _1.arguments.arguments.first.unescaped }
|
51
|
+
return source
|
52
|
+
end
|
53
|
+
|
54
|
+
# insert nodes to source
|
55
|
+
link_lines = doc_info.link_nodes.map{ _1.location.start_line }
|
56
|
+
|
57
|
+
source_lines = source.lines
|
58
|
+
|
59
|
+
sorted_lines = sorted_link_nodes.map do |sorted_link|
|
60
|
+
source_lines[sorted_link.location.start_line - 1]
|
61
|
+
end
|
62
|
+
|
63
|
+
link_lines.each_with_index do |link_line, index|
|
64
|
+
source_lines[link_line - 1] = sorted_lines[index]
|
65
|
+
end
|
66
|
+
|
67
|
+
source_lines.join()
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RubyLsp
|
2
|
+
module Ree
|
3
|
+
class ReeIndexingEnhancement < RubyIndexer::Enhancement
|
4
|
+
def on_call_node_enter(node)
|
5
|
+
return unless @listener.current_owner
|
6
|
+
|
7
|
+
# Return early unless the method call is the one we want to handle
|
8
|
+
return unless node.name == :fn
|
9
|
+
return unless node.arguments
|
10
|
+
|
11
|
+
# index = @listener.instance_variable_get(:@index)
|
12
|
+
|
13
|
+
location = node.location
|
14
|
+
fn_name = node.arguments.child_nodes.first.unescaped
|
15
|
+
signatures = parse_signatures(fn_name)
|
16
|
+
comments = "ree_object\nsome_documentation"
|
17
|
+
|
18
|
+
# visibility = RubyIndexer::Entry::Visibility::PUBLIC
|
19
|
+
# owner = index['Object'].first
|
20
|
+
|
21
|
+
# index.add(RubyIndexer::Entry::Method.new(
|
22
|
+
# fn_name,
|
23
|
+
# @listener.instance_variable_get(:@uri),
|
24
|
+
# location,
|
25
|
+
# location,
|
26
|
+
# comments,
|
27
|
+
# signatures,
|
28
|
+
# visibility,
|
29
|
+
# owner,
|
30
|
+
# ))
|
31
|
+
|
32
|
+
@listener.add_method(
|
33
|
+
fn_name,
|
34
|
+
location,
|
35
|
+
signatures,
|
36
|
+
comments: comments
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_signatures(fn_name)
|
41
|
+
uri = @listener.instance_variable_get(:@uri)
|
42
|
+
ast = Prism.parse_file(uri.path).value
|
43
|
+
|
44
|
+
class_node = ast.statements.body.detect{ |node| node.is_a?(Prism::ClassNode) }
|
45
|
+
return [] unless class_node
|
46
|
+
|
47
|
+
call_node = class_node.body.body.detect{ |node| node.name == :call }
|
48
|
+
return [] unless call_node
|
49
|
+
|
50
|
+
signature_params = @listener.send(:list_params, call_node.parameters)
|
51
|
+
|
52
|
+
[RubyIndexer::Entry::Signature.new(signature_params)]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module RubyLsp
|
2
|
+
module Ree
|
3
|
+
module ReeLspUtils
|
4
|
+
def package_name_from_uri(uri)
|
5
|
+
uri_parts = uri.to_s.split('/')
|
6
|
+
package_index = uri_parts.find_index('package') + 1
|
7
|
+
uri_parts[package_index]
|
8
|
+
end
|
9
|
+
|
10
|
+
def path_from_package(uri)
|
11
|
+
uri_parts = uri.chomp(File.extname(uri)).split('/')
|
12
|
+
pack_folder_index = uri_parts.index('package')
|
13
|
+
uri_parts.drop(pack_folder_index+1).join('/')
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_document_from_uri(uri)
|
17
|
+
ast = Prism.parse_file(uri.path).value
|
18
|
+
result = parse_document(ast)
|
19
|
+
|
20
|
+
result.package_name = package_name_from_uri(uri)
|
21
|
+
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_document_from_source(source)
|
26
|
+
ast = Prism.parse(source).value
|
27
|
+
parse_document(ast)
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_document(ast)
|
31
|
+
class_node = ast.statements.body.detect{ |node| node.is_a?(Prism::ClassNode) }
|
32
|
+
fn_node = class_node.body.body.detect{ |node| node.name == :fn }
|
33
|
+
block_node = fn_node.block
|
34
|
+
|
35
|
+
link_nodes = if block_node && block_node.body
|
36
|
+
block_node.body.body.select{ |node| node.name == :link }
|
37
|
+
else
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
|
41
|
+
linked_objects = link_nodes.map do |link_node|
|
42
|
+
name_arg_node = link_node.arguments.arguments.first
|
43
|
+
|
44
|
+
name_val = case name_arg_node
|
45
|
+
when Prism::SymbolNode
|
46
|
+
name_arg_node.value
|
47
|
+
when Prism::StringNode
|
48
|
+
name_arg_node.unescaped
|
49
|
+
else
|
50
|
+
""
|
51
|
+
end
|
52
|
+
|
53
|
+
OpenStruct.new(
|
54
|
+
name: name_val,
|
55
|
+
imports: parse_link_node_imports(link_node)
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
return OpenStruct.new(
|
60
|
+
ast: ast,
|
61
|
+
class_node: class_node,
|
62
|
+
fn_node: fn_node,
|
63
|
+
block_node: block_node,
|
64
|
+
link_nodes: link_nodes,
|
65
|
+
linked_objects: linked_objects
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_range_for_fn_insert(doc_info, link_text)
|
70
|
+
fn_line = doc_info.fn_node.location.start_line
|
71
|
+
|
72
|
+
position = if doc_info.block_node
|
73
|
+
doc_info.block_node.opening_loc.end_column + 1
|
74
|
+
else
|
75
|
+
doc_info.fn_node.arguments.location.end_column + 1
|
76
|
+
end
|
77
|
+
|
78
|
+
Interface::Range.new(
|
79
|
+
start: Interface::Position.new(line: fn_line - 1, character: position),
|
80
|
+
end: Interface::Position.new(line: fn_line - 1, character: position + link_text.size),
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_link_node_imports(node)
|
85
|
+
return [] if node.arguments.arguments.size == 1
|
86
|
+
|
87
|
+
last_arg = node.arguments.arguments.last
|
88
|
+
|
89
|
+
if last_arg.is_a?(Prism::KeywordHashNode)
|
90
|
+
import_arg = last_arg.elements.detect{ _1.key.unescaped == 'import' }
|
91
|
+
return [] unless import_arg
|
92
|
+
|
93
|
+
[import_arg.value.body.body.first.name.to_s]
|
94
|
+
elsif last_arg.is_a?(Prism::LambdaNode)
|
95
|
+
[last_arg.body.body.first.name.to_s]
|
96
|
+
else
|
97
|
+
return []
|
98
|
+
end
|
99
|
+
rescue => e
|
100
|
+
$stderr.puts("can't parse imports: #{e.message}")
|
101
|
+
return []
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/ruby_lsp_ree.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/ruby_lsp_ree/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ruby-lsp-ree"
|
7
|
+
spec.version = Ruby::Lsp::Ree::VERSION
|
8
|
+
spec.authors = ["Ruslan Gatiyatov"]
|
9
|
+
spec.email = ["ruslan.gatiyatov@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby LSP addon for Ree framework."
|
12
|
+
spec.description = "A Ruby LSP addon that adds extra editor functionality for Ree applications"
|
13
|
+
spec.homepage = "https://github.com/glabix/ree/tree/main/ruby-lsp-ree"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.1"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/glabix/ree/tree/main/ruby-lsp-ree"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/glabix/ree/blob/main/ruby-lsp-ree/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-lsp-ree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruslan Gatiyatov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby LSP addon that adds extra editor functionality for Ree applications
|
14
|
+
email:
|
15
|
+
- ruslan.gatiyatov@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- CODE_OF_CONDUCT.md
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/ruby_lsp/ruby_lsp_ree/addon.rb
|
27
|
+
- lib/ruby_lsp/ruby_lsp_ree/completion.rb
|
28
|
+
- lib/ruby_lsp/ruby_lsp_ree/definition.rb
|
29
|
+
- lib/ruby_lsp/ruby_lsp_ree/ree_formatter.rb
|
30
|
+
- lib/ruby_lsp/ruby_lsp_ree/ree_indexing_enhancement.rb
|
31
|
+
- lib/ruby_lsp/ruby_lsp_ree/ree_lsp_utils.rb
|
32
|
+
- lib/ruby_lsp_ree.rb
|
33
|
+
- lib/ruby_lsp_ree/version.rb
|
34
|
+
- ruby-lsp-ree.gemspec
|
35
|
+
- sig/ruby/lsp/ree.rbs
|
36
|
+
homepage: https://github.com/glabix/ree/tree/main/ruby-lsp-ree
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://github.com/glabix/ree/tree/main/ruby-lsp-ree
|
41
|
+
source_code_uri: https://github.com/glabix/ree/tree/main/ruby-lsp-ree
|
42
|
+
changelog_uri: https://github.com/glabix/ree/blob/main/ruby-lsp-ree/CHANGELOG.md
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '3.1'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.4.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Ruby LSP addon for Ree framework.
|
62
|
+
test_files: []
|