cosmicgraph 0.49.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 +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/rspec.yml +41 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +1150 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +136 -0
- data/Rakefile +25 -0
- data/SPONSORS.md +15 -0
- data/bin/solargraph +5 -0
- data/cosmicgraph.gemspec +44 -0
- data/lib/.rubocop.yml +22 -0
- data/lib/solargraph/api_map/bundler_methods.rb +22 -0
- data/lib/solargraph/api_map/cache.rb +70 -0
- data/lib/solargraph/api_map/source_to_yard.rb +81 -0
- data/lib/solargraph/api_map/store.rb +268 -0
- data/lib/solargraph/api_map.rb +704 -0
- data/lib/solargraph/bench.rb +27 -0
- data/lib/solargraph/cache.rb +51 -0
- data/lib/solargraph/complex_type/type_methods.rb +134 -0
- data/lib/solargraph/complex_type/unique_type.rb +132 -0
- data/lib/solargraph/complex_type.rb +254 -0
- data/lib/solargraph/convention/base.rb +33 -0
- data/lib/solargraph/convention/gemfile.rb +15 -0
- data/lib/solargraph/convention/gemspec.rb +22 -0
- data/lib/solargraph/convention/rakefile.rb +17 -0
- data/lib/solargraph/convention/rspec.rb +30 -0
- data/lib/solargraph/convention.rb +49 -0
- data/lib/solargraph/converters/dd.rb +12 -0
- data/lib/solargraph/converters/dl.rb +12 -0
- data/lib/solargraph/converters/dt.rb +12 -0
- data/lib/solargraph/converters/misc.rb +1 -0
- data/lib/solargraph/diagnostics/base.rb +29 -0
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -0
- data/lib/solargraph/diagnostics/rubocop.rb +112 -0
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +65 -0
- data/lib/solargraph/diagnostics/severities.rb +15 -0
- data/lib/solargraph/diagnostics/type_check.rb +54 -0
- data/lib/solargraph/diagnostics/update_errors.rb +41 -0
- data/lib/solargraph/diagnostics.rb +55 -0
- data/lib/solargraph/documentor.rb +76 -0
- data/lib/solargraph/environ.rb +45 -0
- data/lib/solargraph/language_server/completion_item_kinds.rb +35 -0
- data/lib/solargraph/language_server/error_codes.rb +20 -0
- data/lib/solargraph/language_server/host/cataloger.rb +56 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -0
- data/lib/solargraph/language_server/host/dispatch.rb +111 -0
- data/lib/solargraph/language_server/host/message_worker.rb +59 -0
- data/lib/solargraph/language_server/host/sources.rb +156 -0
- data/lib/solargraph/language_server/host.rb +869 -0
- data/lib/solargraph/language_server/message/base.rb +89 -0
- data/lib/solargraph/language_server/message/cancel_request.rb +13 -0
- data/lib/solargraph/language_server/message/client/register_capability.rb +15 -0
- data/lib/solargraph/language_server/message/client.rb +11 -0
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -0
- data/lib/solargraph/language_server/message/completion_item.rb +11 -0
- data/lib/solargraph/language_server/message/exit_notification.rb +13 -0
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +100 -0
- data/lib/solargraph/language_server/message/extended/document.rb +20 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -0
- data/lib/solargraph/language_server/message/extended/download_core.rb +19 -0
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -0
- data/lib/solargraph/language_server/message/extended/search.rb +20 -0
- data/lib/solargraph/language_server/message/extended.rb +21 -0
- data/lib/solargraph/language_server/message/initialize.rb +164 -0
- data/lib/solargraph/language_server/message/initialized.rb +27 -0
- data/lib/solargraph/language_server/message/method_not_found.rb +16 -0
- data/lib/solargraph/language_server/message/method_not_implemented.rb +14 -0
- data/lib/solargraph/language_server/message/shutdown.rb +13 -0
- data/lib/solargraph/language_server/message/text_document/base.rb +19 -0
- data/lib/solargraph/language_server/message/text_document/code_action.rb +17 -0
- data/lib/solargraph/language_server/message/text_document/completion.rb +59 -0
- data/lib/solargraph/language_server/message/text_document/definition.rb +38 -0
- data/lib/solargraph/language_server/message/text_document/did_change.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_close.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_open.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_save.rb +17 -0
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +16 -0
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +23 -0
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +26 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +126 -0
- data/lib/solargraph/language_server/message/text_document/hover.rb +56 -0
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +34 -0
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +11 -0
- data/lib/solargraph/language_server/message/text_document/references.rb +16 -0
- data/lib/solargraph/language_server/message/text_document/rename.rb +19 -0
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -0
- data/lib/solargraph/language_server/message/text_document.rb +28 -0
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +30 -0
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +40 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -0
- data/lib/solargraph/language_server/message/workspace.rb +14 -0
- data/lib/solargraph/language_server/message.rb +93 -0
- data/lib/solargraph/language_server/message_types.rb +14 -0
- data/lib/solargraph/language_server/request.rb +24 -0
- data/lib/solargraph/language_server/symbol_kinds.rb +36 -0
- data/lib/solargraph/language_server/transport/adapter.rb +53 -0
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -0
- data/lib/solargraph/language_server/transport.rb +13 -0
- data/lib/solargraph/language_server/uri_helpers.rb +49 -0
- data/lib/solargraph/language_server.rb +19 -0
- data/lib/solargraph/library.rb +547 -0
- data/lib/solargraph/location.rb +37 -0
- data/lib/solargraph/logging.rb +27 -0
- data/lib/solargraph/page.rb +83 -0
- data/lib/solargraph/parser/comment_ripper.rb +52 -0
- data/lib/solargraph/parser/legacy/class_methods.rb +135 -0
- data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
- data/lib/solargraph/parser/legacy/node_chainer.rb +148 -0
- data/lib/solargraph/parser/legacy/node_methods.rb +325 -0
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
- data/lib/solargraph/parser/legacy/node_processors/block_node.rb +42 -0
- data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +35 -0
- data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
- data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
- data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
- data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
- data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
- data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
- data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
- data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +42 -0
- data/lib/solargraph/parser/legacy/node_processors/send_node.rb +257 -0
- data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
- data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
- data/lib/solargraph/parser/legacy.rb +12 -0
- data/lib/solargraph/parser/node_methods.rb +43 -0
- data/lib/solargraph/parser/node_processor/base.rb +77 -0
- data/lib/solargraph/parser/node_processor.rb +43 -0
- data/lib/solargraph/parser/region.rb +66 -0
- data/lib/solargraph/parser/rubyvm/class_methods.rb +149 -0
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +160 -0
- data/lib/solargraph/parser/rubyvm/node_methods.rb +315 -0
- data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +85 -0
- data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +42 -0
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +33 -0
- data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +75 -0
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +68 -0
- data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +39 -0
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +32 -0
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +279 -0
- data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
- data/lib/solargraph/parser/rubyvm/node_processors.rb +63 -0
- data/lib/solargraph/parser/rubyvm/node_wrapper.rb +47 -0
- data/lib/solargraph/parser/rubyvm.rb +40 -0
- data/lib/solargraph/parser/snippet.rb +13 -0
- data/lib/solargraph/parser.rb +26 -0
- data/lib/solargraph/pin/base.rb +299 -0
- data/lib/solargraph/pin/base_variable.rb +84 -0
- data/lib/solargraph/pin/block.rb +73 -0
- data/lib/solargraph/pin/class_variable.rb +8 -0
- data/lib/solargraph/pin/closure.rb +37 -0
- data/lib/solargraph/pin/common.rb +70 -0
- data/lib/solargraph/pin/constant.rb +43 -0
- data/lib/solargraph/pin/conversions.rb +92 -0
- data/lib/solargraph/pin/documenting.rb +105 -0
- data/lib/solargraph/pin/duck_method.rb +16 -0
- data/lib/solargraph/pin/global_variable.rb +8 -0
- data/lib/solargraph/pin/instance_variable.rb +30 -0
- data/lib/solargraph/pin/keyword.rb +15 -0
- data/lib/solargraph/pin/keyword_param.rb +8 -0
- data/lib/solargraph/pin/local_variable.rb +55 -0
- data/lib/solargraph/pin/method.rb +335 -0
- data/lib/solargraph/pin/method_alias.rb +31 -0
- data/lib/solargraph/pin/namespace.rb +94 -0
- data/lib/solargraph/pin/parameter.rb +206 -0
- data/lib/solargraph/pin/proxy_type.rb +29 -0
- data/lib/solargraph/pin/reference/extend.rb +10 -0
- data/lib/solargraph/pin/reference/include.rb +10 -0
- data/lib/solargraph/pin/reference/override.rb +29 -0
- data/lib/solargraph/pin/reference/prepend.rb +10 -0
- data/lib/solargraph/pin/reference/require.rb +14 -0
- data/lib/solargraph/pin/reference/superclass.rb +10 -0
- data/lib/solargraph/pin/reference.rb +14 -0
- data/lib/solargraph/pin/search.rb +56 -0
- data/lib/solargraph/pin/signature.rb +23 -0
- data/lib/solargraph/pin/singleton.rb +11 -0
- data/lib/solargraph/pin/symbol.rb +47 -0
- data/lib/solargraph/pin.rb +38 -0
- data/lib/solargraph/position.rb +100 -0
- data/lib/solargraph/range.rb +95 -0
- data/lib/solargraph/rbs_map/conversions.rb +394 -0
- data/lib/solargraph/rbs_map/core_fills.rb +61 -0
- data/lib/solargraph/rbs_map/core_map.rb +38 -0
- data/lib/solargraph/rbs_map/core_signs.rb +33 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +36 -0
- data/lib/solargraph/rbs_map.rb +73 -0
- data/lib/solargraph/server_methods.rb +16 -0
- data/lib/solargraph/shell.rb +234 -0
- data/lib/solargraph/source/chain/block_variable.rb +13 -0
- data/lib/solargraph/source/chain/call.rb +215 -0
- data/lib/solargraph/source/chain/class_variable.rb +13 -0
- data/lib/solargraph/source/chain/constant.rb +75 -0
- data/lib/solargraph/source/chain/global_variable.rb +13 -0
- data/lib/solargraph/source/chain/hash.rb +28 -0
- data/lib/solargraph/source/chain/head.rb +19 -0
- data/lib/solargraph/source/chain/instance_variable.rb +13 -0
- data/lib/solargraph/source/chain/link.rb +71 -0
- data/lib/solargraph/source/chain/literal.rb +23 -0
- data/lib/solargraph/source/chain/or.rb +23 -0
- data/lib/solargraph/source/chain/q_call.rb +11 -0
- data/lib/solargraph/source/chain/variable.rb +13 -0
- data/lib/solargraph/source/chain/z_super.rb +30 -0
- data/lib/solargraph/source/chain.rb +179 -0
- data/lib/solargraph/source/change.rb +79 -0
- data/lib/solargraph/source/cursor.rb +164 -0
- data/lib/solargraph/source/encoding_fixes.rb +23 -0
- data/lib/solargraph/source/source_chainer.rb +191 -0
- data/lib/solargraph/source/updater.rb +54 -0
- data/lib/solargraph/source.rb +522 -0
- data/lib/solargraph/source_map/clip.rb +229 -0
- data/lib/solargraph/source_map/completion.rb +23 -0
- data/lib/solargraph/source_map/mapper.rb +241 -0
- data/lib/solargraph/source_map.rb +180 -0
- data/lib/solargraph/type_checker/checks.rb +112 -0
- data/lib/solargraph/type_checker/param_def.rb +35 -0
- data/lib/solargraph/type_checker/problem.rb +32 -0
- data/lib/solargraph/type_checker/rules.rb +57 -0
- data/lib/solargraph/type_checker.rb +549 -0
- data/lib/solargraph/version.rb +5 -0
- data/lib/solargraph/views/_method.erb +62 -0
- data/lib/solargraph/views/_name_type_tag.erb +10 -0
- data/lib/solargraph/views/_namespace.erb +24 -0
- data/lib/solargraph/views/document.erb +23 -0
- data/lib/solargraph/views/environment.erb +58 -0
- data/lib/solargraph/views/layout.erb +44 -0
- data/lib/solargraph/views/search.erb +11 -0
- data/lib/solargraph/workspace/config.rb +231 -0
- data/lib/solargraph/workspace.rb +212 -0
- data/lib/solargraph/yard_map/cache.rb +19 -0
- data/lib/solargraph/yard_map/helpers.rb +16 -0
- data/lib/solargraph/yard_map/mapper/to_constant.rb +25 -0
- data/lib/solargraph/yard_map/mapper/to_method.rb +81 -0
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +27 -0
- data/lib/solargraph/yard_map/mapper.rb +77 -0
- data/lib/solargraph/yard_map/to_method.rb +79 -0
- data/lib/solargraph/yard_map.rb +301 -0
- data/lib/solargraph.rb +69 -0
- data/lib/yard-solargraph.rb +33 -0
- metadata +587 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
class CommentRipper < Ripper::SexpBuilderPP
|
6
|
+
def initialize src, filename = '(ripper)', lineno = 0
|
7
|
+
super
|
8
|
+
@buffer = src
|
9
|
+
@buffer_lines = @buffer.lines
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_comment *args
|
13
|
+
result = super
|
14
|
+
if @buffer_lines[result[2][0]][0..result[2][1]].strip =~ /^#/
|
15
|
+
chomped = result[1].chomp
|
16
|
+
if result[2][0] == 0 && chomped.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').match(/^#\s*frozen_string_literal:/)
|
17
|
+
chomped = '#'
|
18
|
+
end
|
19
|
+
@comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_embdoc_beg *args
|
25
|
+
result = super
|
26
|
+
chomped = result[1].chomp
|
27
|
+
@comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_embdoc *args
|
32
|
+
result = super
|
33
|
+
chomped = result[1].chomp
|
34
|
+
@comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_embdoc_end *args
|
39
|
+
result = super
|
40
|
+
chomped = result[1].chomp
|
41
|
+
@comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped)
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse
|
46
|
+
@comments = {}
|
47
|
+
super
|
48
|
+
@comments
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'parser/current'
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
module ClassMethods
|
7
|
+
# @param code [String]
|
8
|
+
# @param filename [String]
|
9
|
+
# @return [Array(Parser::AST::Node, Array<Parser::Source::Comment>)]
|
10
|
+
def parse_with_comments code, filename = nil
|
11
|
+
buffer = ::Parser::Source::Buffer.new(filename, 0)
|
12
|
+
buffer.source = code
|
13
|
+
node = parser.parse(buffer)
|
14
|
+
comments = CommentRipper.new(code, filename, 0).parse
|
15
|
+
[node, comments]
|
16
|
+
rescue ::Parser::SyntaxError => e
|
17
|
+
raise Parser::SyntaxError, e.message
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param code [String]
|
21
|
+
# @param filename [String, nil]
|
22
|
+
# @param line [Integer]
|
23
|
+
# @return [Parser::AST::Node]
|
24
|
+
def parse code, filename = nil, line = 0
|
25
|
+
buffer = ::Parser::Source::Buffer.new(filename, line)
|
26
|
+
buffer.source = code
|
27
|
+
parser.parse(buffer)
|
28
|
+
rescue ::Parser::SyntaxError => e
|
29
|
+
raise Parser::SyntaxError, e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Parser::Base]
|
33
|
+
def parser
|
34
|
+
# @todo Consider setting an instance variable. We might not need to
|
35
|
+
# recreate the parser every time we use it.
|
36
|
+
parser = ::Parser::CurrentRuby.new(FlawedBuilder.new)
|
37
|
+
parser.diagnostics.all_errors_are_fatal = true
|
38
|
+
parser.diagnostics.ignore_warnings = true
|
39
|
+
parser
|
40
|
+
end
|
41
|
+
|
42
|
+
def map source
|
43
|
+
NodeProcessor.process(source.node, Region.new(source: source))
|
44
|
+
end
|
45
|
+
|
46
|
+
def returns_from node
|
47
|
+
NodeMethods.returns_from(node)
|
48
|
+
end
|
49
|
+
|
50
|
+
def references source, name
|
51
|
+
if name.end_with?("=")
|
52
|
+
reg = /#{Regexp.escape name[0..-2]}\s*=/
|
53
|
+
extract_offset = ->(code, offset) { reg.match(code, offset).offset(0) }
|
54
|
+
else
|
55
|
+
extract_offset = ->(code, offset) { [soff = code.index(name, offset), soff + name.length] }
|
56
|
+
end
|
57
|
+
inner_node_references(name, source.node).map do |n|
|
58
|
+
rng = Range.from_node(n)
|
59
|
+
offset = Position.to_offset(source.code, rng.start)
|
60
|
+
soff, eoff = extract_offset[source.code, offset]
|
61
|
+
Location.new(
|
62
|
+
source.filename,
|
63
|
+
Range.new(
|
64
|
+
Position.from_offset(source.code, soff),
|
65
|
+
Position.from_offset(source.code, eoff)
|
66
|
+
)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param name [String]
|
72
|
+
# @param top [AST::Node]
|
73
|
+
# @return [Array<AST::Node>]
|
74
|
+
def inner_node_references name, top
|
75
|
+
result = []
|
76
|
+
if top.is_a?(AST::Node) && top.to_s.include?(":#{name}")
|
77
|
+
result.push top if top.children.any? { |c| c.to_s == name }
|
78
|
+
top.children.each { |c| result.concat inner_node_references(name, c) }
|
79
|
+
end
|
80
|
+
result
|
81
|
+
end
|
82
|
+
|
83
|
+
def chain *args
|
84
|
+
NodeChainer.chain *args
|
85
|
+
end
|
86
|
+
|
87
|
+
def chain_string *args
|
88
|
+
NodeChainer.load_string *args
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_node *args
|
92
|
+
Solargraph::Parser::NodeProcessor.process *args
|
93
|
+
end
|
94
|
+
|
95
|
+
def infer_literal_node_type node
|
96
|
+
NodeMethods.infer_literal_node_type node
|
97
|
+
end
|
98
|
+
|
99
|
+
def version
|
100
|
+
parser.version
|
101
|
+
end
|
102
|
+
|
103
|
+
def is_ast_node? node
|
104
|
+
node.is_a?(::Parser::AST::Node)
|
105
|
+
end
|
106
|
+
|
107
|
+
def node_range node
|
108
|
+
st = Position.new(node.loc.line, node.loc.column)
|
109
|
+
en = Position.new(node.loc.last_line, node.loc.last_column)
|
110
|
+
Range.new(st, en)
|
111
|
+
end
|
112
|
+
|
113
|
+
def string_ranges node
|
114
|
+
return [] unless is_ast_node?(node)
|
115
|
+
result = []
|
116
|
+
if node.type == :str
|
117
|
+
result.push Range.from_node(node)
|
118
|
+
end
|
119
|
+
node.children.each do |child|
|
120
|
+
result.concat string_ranges(child)
|
121
|
+
end
|
122
|
+
if node.type == :dstr && node.children.last.nil?
|
123
|
+
last = node.children[-2]
|
124
|
+
unless last.nil?
|
125
|
+
rng = Range.from_node(last)
|
126
|
+
pos = Position.new(rng.ending.line, rng.ending.column - 1)
|
127
|
+
result.push Range.new(pos, pos)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
result
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
# A custom builder for source parsers that ignores character encoding
|
7
|
+
# issues in literal strings.
|
8
|
+
#
|
9
|
+
class FlawedBuilder < ::Parser::Builders::Default
|
10
|
+
def string_value(token)
|
11
|
+
value(token)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
# A factory for generating chains from nodes.
|
7
|
+
#
|
8
|
+
class NodeChainer
|
9
|
+
include NodeMethods
|
10
|
+
Chain = Source::Chain
|
11
|
+
|
12
|
+
# @param node [Parser::AST::Node]
|
13
|
+
# @param filename [String]
|
14
|
+
def initialize node, filename = nil, in_block = false
|
15
|
+
@node = node
|
16
|
+
@filename = filename
|
17
|
+
@in_block = in_block ? 1 : 0
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Source::Chain]
|
21
|
+
def chain
|
22
|
+
links = generate_links(@node)
|
23
|
+
Chain.new(links, @node, (Parser.is_ast_node?(@node) && @node.type == :splat))
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# @param node [Parser::AST::Node]
|
28
|
+
# @param filename [String]
|
29
|
+
# @return [Source::Chain]
|
30
|
+
def chain node, filename = nil, in_block = false
|
31
|
+
NodeChainer.new(node, filename, in_block).chain
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param code [String]
|
35
|
+
# @return [Source::Chain]
|
36
|
+
def load_string(code)
|
37
|
+
node = Parser.parse(code.sub(/\.$/, ''))
|
38
|
+
chain = NodeChainer.new(node).chain
|
39
|
+
chain.links.push(Chain::Link.new) if code.end_with?('.')
|
40
|
+
chain
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# @param n [Parser::AST::Node]
|
47
|
+
# @return [Array<Chain::Link>]
|
48
|
+
def generate_links n
|
49
|
+
return [] unless n.is_a?(::Parser::AST::Node)
|
50
|
+
return generate_links(n.children[0]) if n.type == :begin
|
51
|
+
return generate_links(n.children[0]) if n.type == :splat
|
52
|
+
result = []
|
53
|
+
if n.type == :block
|
54
|
+
@in_block += 1
|
55
|
+
result.concat generate_links(n.children[0])
|
56
|
+
@in_block -= 1
|
57
|
+
elsif n.type == :send
|
58
|
+
if n.children[0].is_a?(::Parser::AST::Node)
|
59
|
+
result.concat generate_links(n.children[0])
|
60
|
+
args = []
|
61
|
+
n.children[2..-1].each do |c|
|
62
|
+
args.push NodeChainer.chain(c)
|
63
|
+
end
|
64
|
+
result.push Chain::Call.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
65
|
+
elsif n.children[0].nil?
|
66
|
+
args = []
|
67
|
+
n.children[2..-1].each do |c|
|
68
|
+
args.push NodeChainer.chain(c)
|
69
|
+
end
|
70
|
+
result.push Chain::Call.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
71
|
+
else
|
72
|
+
raise "No idea what to do with #{n}"
|
73
|
+
end
|
74
|
+
elsif n.type == :csend
|
75
|
+
if n.children[0].is_a?(::Parser::AST::Node)
|
76
|
+
result.concat generate_links(n.children[0])
|
77
|
+
args = []
|
78
|
+
n.children[2..-1].each do |c|
|
79
|
+
args.push NodeChainer.chain(c)
|
80
|
+
end
|
81
|
+
result.push Chain::QCall.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
82
|
+
elsif n.children[0].nil?
|
83
|
+
args = []
|
84
|
+
n.children[2..-1].each do |c|
|
85
|
+
args.push NodeChainer.chain(c)
|
86
|
+
end
|
87
|
+
result.push Chain::QCall.new(n.children[1].to_s, args, @in_block > 0 || block_passed?(n))
|
88
|
+
else
|
89
|
+
raise "No idea what to do with #{n}"
|
90
|
+
end
|
91
|
+
elsif n.type == :self
|
92
|
+
result.push Chain::Head.new('self')
|
93
|
+
elsif n.type == :zsuper
|
94
|
+
result.push Chain::ZSuper.new('super', @in_block > 0 || block_passed?(n))
|
95
|
+
elsif n.type == :super
|
96
|
+
args = n.children.map { |c| NodeChainer.chain(c) }
|
97
|
+
result.push Chain::Call.new('super', args, @in_block > 0 || block_passed?(n))
|
98
|
+
elsif n.type == :const
|
99
|
+
const = unpack_name(n)
|
100
|
+
result.push Chain::Constant.new(const)
|
101
|
+
elsif [:lvar, :lvasgn].include?(n.type)
|
102
|
+
result.push Chain::Call.new(n.children[0].to_s)
|
103
|
+
elsif [:ivar, :ivasgn].include?(n.type)
|
104
|
+
result.push Chain::InstanceVariable.new(n.children[0].to_s)
|
105
|
+
elsif [:cvar, :cvasgn].include?(n.type)
|
106
|
+
result.push Chain::ClassVariable.new(n.children[0].to_s)
|
107
|
+
elsif [:gvar, :gvasgn].include?(n.type)
|
108
|
+
result.push Chain::GlobalVariable.new(n.children[0].to_s)
|
109
|
+
elsif n.type == :or_asgn
|
110
|
+
result.concat generate_links n.children[1]
|
111
|
+
elsif [:class, :module, :def, :defs].include?(n.type)
|
112
|
+
# @todo Undefined or what?
|
113
|
+
result.push Chain::UNDEFINED_CALL
|
114
|
+
elsif n.type == :and
|
115
|
+
result.concat generate_links(n.children.last)
|
116
|
+
elsif n.type == :or
|
117
|
+
result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename)])
|
118
|
+
elsif [:begin, :kwbegin].include?(n.type)
|
119
|
+
result.concat generate_links(n.children[0])
|
120
|
+
elsif n.type == :block_pass
|
121
|
+
result.push Chain::BlockVariable.new("&#{n.children[0].children[0].to_s}")
|
122
|
+
elsif n.type == :hash
|
123
|
+
result.push Chain::Hash.new('::Hash', hash_is_splatted?(n))
|
124
|
+
else
|
125
|
+
lit = infer_literal_node_type(n)
|
126
|
+
# if lit == '::Hash'
|
127
|
+
# result.push Chain::Hash.new(lit, hash_is_splatted?(n))
|
128
|
+
# else
|
129
|
+
result.push (lit ? Chain::Literal.new(lit) : Chain::Link.new)
|
130
|
+
# end
|
131
|
+
end
|
132
|
+
result
|
133
|
+
end
|
134
|
+
|
135
|
+
def hash_is_splatted? node
|
136
|
+
return false unless Parser.is_ast_node?(node) && node.type == :hash
|
137
|
+
return false unless Parser.is_ast_node?(node.children.last) && node.children.last.type == :kwsplat
|
138
|
+
return false if Parser.is_ast_node?(node.children.last.children[0]) && node.children.last.children[0].type == :hash
|
139
|
+
true
|
140
|
+
end
|
141
|
+
|
142
|
+
def block_passed? node
|
143
|
+
node.children.last.is_a?(::Parser::AST::Node) && node.children.last.type == :block_pass
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,325 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'parser'
|
4
|
+
|
5
|
+
module Solargraph
|
6
|
+
module Parser
|
7
|
+
module Legacy
|
8
|
+
module NodeMethods
|
9
|
+
module_function
|
10
|
+
|
11
|
+
# @param node [Parser::AST::Node]
|
12
|
+
# @return [String]
|
13
|
+
def unpack_name(node)
|
14
|
+
pack_name(node).join("::")
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param node [Parser::AST::Node]
|
18
|
+
# @return [Array<String>]
|
19
|
+
def pack_name(node)
|
20
|
+
parts = []
|
21
|
+
if node.is_a?(AST::Node)
|
22
|
+
node.children.each { |n|
|
23
|
+
if n.is_a?(AST::Node)
|
24
|
+
if n.type == :cbase
|
25
|
+
parts = [''] + pack_name(n)
|
26
|
+
else
|
27
|
+
parts += pack_name(n)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
parts.push n unless n.nil?
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
parts
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param node [Parser::AST::Node]
|
38
|
+
# @return [String, nil]
|
39
|
+
def infer_literal_node_type node
|
40
|
+
return nil unless node.is_a?(AST::Node)
|
41
|
+
if node.type == :str || node.type == :dstr
|
42
|
+
return '::String'
|
43
|
+
elsif node.type == :array
|
44
|
+
return '::Array'
|
45
|
+
elsif node.type == :hash
|
46
|
+
return '::Hash'
|
47
|
+
elsif node.type == :int
|
48
|
+
return '::Integer'
|
49
|
+
elsif node.type == :float
|
50
|
+
return '::Float'
|
51
|
+
elsif node.type == :sym
|
52
|
+
return '::Symbol'
|
53
|
+
elsif node.type == :regexp
|
54
|
+
return '::Regexp'
|
55
|
+
elsif node.type == :irange
|
56
|
+
return '::Range'
|
57
|
+
elsif node.type == :true || node.type == :false
|
58
|
+
return '::Boolean'
|
59
|
+
# @todo Support `nil` keyword in types
|
60
|
+
# elsif node.type == :nil
|
61
|
+
# return 'NilClass'
|
62
|
+
end
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param node [Parser::AST::Node]
|
67
|
+
# @return [Position]
|
68
|
+
def get_node_start_position(node)
|
69
|
+
Position.new(node.loc.line, node.loc.column)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param node [Parser::AST::Node]
|
73
|
+
# @return [Position]
|
74
|
+
def get_node_end_position(node)
|
75
|
+
Position.new(node.loc.last_line, node.loc.last_column)
|
76
|
+
end
|
77
|
+
|
78
|
+
def drill_signature node, signature
|
79
|
+
return signature unless node.is_a?(AST::Node)
|
80
|
+
if node.type == :const or node.type == :cbase
|
81
|
+
unless node.children[0].nil?
|
82
|
+
signature += drill_signature(node.children[0], signature)
|
83
|
+
end
|
84
|
+
signature += '::' unless signature.empty?
|
85
|
+
signature += node.children[1].to_s
|
86
|
+
elsif node.type == :lvar or node.type == :ivar or node.type == :cvar
|
87
|
+
signature += '.' unless signature.empty?
|
88
|
+
signature += node.children[0].to_s
|
89
|
+
elsif node.type == :send
|
90
|
+
unless node.children[0].nil?
|
91
|
+
signature += drill_signature(node.children[0], signature)
|
92
|
+
end
|
93
|
+
signature += '.' unless signature.empty?
|
94
|
+
signature += node.children[1].to_s
|
95
|
+
end
|
96
|
+
signature
|
97
|
+
end
|
98
|
+
|
99
|
+
def convert_hash node
|
100
|
+
return {} unless Parser.is_ast_node?(node)
|
101
|
+
return convert_hash(node.children[0]) if node.type == :kwsplat
|
102
|
+
return convert_hash(node.children[0]) if Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
|
103
|
+
return {} unless node.type == :hash
|
104
|
+
result = {}
|
105
|
+
node.children.each do |pair|
|
106
|
+
result[pair.children[0].children[0]] = Solargraph::Parser.chain(pair.children[1])
|
107
|
+
end
|
108
|
+
result
|
109
|
+
end
|
110
|
+
|
111
|
+
NIL_NODE = ::Parser::AST::Node.new(:nil)
|
112
|
+
|
113
|
+
def const_nodes_from node
|
114
|
+
return [] unless Parser.is_ast_node?(node)
|
115
|
+
result = []
|
116
|
+
if node.type == :const
|
117
|
+
result.push node
|
118
|
+
else
|
119
|
+
node.children.each { |child| result.concat const_nodes_from(child) }
|
120
|
+
end
|
121
|
+
result
|
122
|
+
end
|
123
|
+
|
124
|
+
def splatted_hash? node
|
125
|
+
Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
|
126
|
+
end
|
127
|
+
|
128
|
+
def splatted_call? node
|
129
|
+
return false unless Parser.is_ast_node?(node)
|
130
|
+
Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat && node.children[0].children[0].type != :hash
|
131
|
+
end
|
132
|
+
|
133
|
+
def any_splatted_call?(nodes)
|
134
|
+
nodes.any? { |n| splatted_call?(n) }
|
135
|
+
end
|
136
|
+
|
137
|
+
# @todo Temporarily here for testing. Move to Solargraph::Parser.
|
138
|
+
def call_nodes_from node
|
139
|
+
return [] unless node.is_a?(::Parser::AST::Node)
|
140
|
+
result = []
|
141
|
+
if node.type == :block
|
142
|
+
result.push node
|
143
|
+
if Parser.is_ast_node?(node.children[0]) && node.children[0].children.length > 2
|
144
|
+
node.children[0].children[2..-1].each { |child| result.concat call_nodes_from(child) }
|
145
|
+
end
|
146
|
+
node.children[1..-1].each { |child| result.concat call_nodes_from(child) }
|
147
|
+
elsif node.type == :send
|
148
|
+
result.push node
|
149
|
+
node.children[2..-1].each { |child| result.concat call_nodes_from(child) }
|
150
|
+
elsif [:super, :zsuper].include?(node.type)
|
151
|
+
result.push node
|
152
|
+
node.children.each { |child| result.concat call_nodes_from(child) }
|
153
|
+
elsif node.type == :masgn
|
154
|
+
# @todo We're treating a mass assignment as a call node, but the
|
155
|
+
# type checker still needs the logic to handle it.
|
156
|
+
result.push node
|
157
|
+
else
|
158
|
+
node.children.each { |child| result.concat call_nodes_from(child) }
|
159
|
+
end
|
160
|
+
result
|
161
|
+
end
|
162
|
+
|
163
|
+
# Find all the nodes within the provided node that potentially return a
|
164
|
+
# value.
|
165
|
+
#
|
166
|
+
# The node parameter typically represents a method's logic, e.g., the
|
167
|
+
# second child (after the :args node) of a :def node. A simple one-line
|
168
|
+
# method would typically return itself, while a node with conditions
|
169
|
+
# would return the resulting node from each conditional branch. Nodes
|
170
|
+
# that follow a :return node are assumed to be unreachable. Nil values
|
171
|
+
# are converted to nil node types.
|
172
|
+
#
|
173
|
+
# @param node [Parser::AST::Node]
|
174
|
+
# @return [Array<Parser::AST::Node>]
|
175
|
+
def returns_from node
|
176
|
+
DeepInference.get_return_nodes(node).map { |n| n || NIL_NODE }
|
177
|
+
end
|
178
|
+
|
179
|
+
# @param cursor [Solargraph::Source::Cursor]
|
180
|
+
def find_recipient_node cursor
|
181
|
+
return repaired_find_recipient_node(cursor) if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
|
182
|
+
source = cursor.source
|
183
|
+
position = cursor.position
|
184
|
+
offset = cursor.offset
|
185
|
+
tree = if source.synchronized?
|
186
|
+
match = source.code[0..offset-1].match(/,\s*\z/)
|
187
|
+
if match
|
188
|
+
source.tree_at(position.line, position.column - match[0].length)
|
189
|
+
else
|
190
|
+
source.tree_at(position.line, position.column)
|
191
|
+
end
|
192
|
+
else
|
193
|
+
source.tree_at(position.line, position.column - 1)
|
194
|
+
end
|
195
|
+
prev = nil
|
196
|
+
tree.each do |node|
|
197
|
+
if node.type == :send
|
198
|
+
args = node.children[2..-1]
|
199
|
+
if !args.empty?
|
200
|
+
return node if prev && args.include?(prev)
|
201
|
+
else
|
202
|
+
if source.synchronized?
|
203
|
+
return node if source.code[0..offset-1] =~ /\(\s*\z/ && source.code[offset..-1] =~ /^\s*\)/
|
204
|
+
else
|
205
|
+
return node if source.code[0..offset-1] =~ /\([^\(]*\z/
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
prev = node
|
210
|
+
end
|
211
|
+
nil
|
212
|
+
end
|
213
|
+
|
214
|
+
def repaired_find_recipient_node cursor
|
215
|
+
cursor = cursor.source.cursor_at([cursor.position.line, cursor.position.column - 1])
|
216
|
+
node = cursor.source.tree_at(cursor.position.line, cursor.position.column).first
|
217
|
+
return node if node && node.type == :send
|
218
|
+
end
|
219
|
+
|
220
|
+
module DeepInference
|
221
|
+
class << self
|
222
|
+
CONDITIONAL = [:if, :unless]
|
223
|
+
REDUCEABLE = [:begin, :kwbegin]
|
224
|
+
SKIPPABLE = [:def, :defs, :class, :sclass, :module]
|
225
|
+
|
226
|
+
# @param node [Parser::AST::Node]
|
227
|
+
# @return [Array<Parser::AST::Node>]
|
228
|
+
def get_return_nodes node
|
229
|
+
return [] unless node.is_a?(::Parser::AST::Node)
|
230
|
+
result = []
|
231
|
+
if REDUCEABLE.include?(node.type)
|
232
|
+
result.concat get_return_nodes_from_children(node)
|
233
|
+
elsif CONDITIONAL.include?(node.type)
|
234
|
+
result.concat reduce_to_value_nodes(node.children[1..-1])
|
235
|
+
# result.push NIL_NODE unless node.children[2]
|
236
|
+
elsif node.type == :or
|
237
|
+
result.concat reduce_to_value_nodes(node.children)
|
238
|
+
elsif node.type == :return
|
239
|
+
result.concat reduce_to_value_nodes([node.children[0]])
|
240
|
+
elsif node.type == :block
|
241
|
+
result.push node
|
242
|
+
result.concat get_return_nodes_only(node.children[2])
|
243
|
+
elsif node.type == :case
|
244
|
+
node.children[1..-1].each do |cc|
|
245
|
+
if cc.nil?
|
246
|
+
result.push NIL_NODE
|
247
|
+
else
|
248
|
+
result.concat reduce_to_value_nodes(cc.children[1..-2]) unless cc.children.length < 1
|
249
|
+
result.concat reduce_to_value_nodes([cc.children.last])
|
250
|
+
end
|
251
|
+
end
|
252
|
+
else
|
253
|
+
result.push node
|
254
|
+
end
|
255
|
+
result
|
256
|
+
end
|
257
|
+
|
258
|
+
private
|
259
|
+
|
260
|
+
def get_return_nodes_from_children parent
|
261
|
+
result = []
|
262
|
+
nodes = parent.children.select{|n| n.is_a?(AST::Node)}
|
263
|
+
nodes.each_with_index do |node, idx|
|
264
|
+
if node.type == :block
|
265
|
+
result.concat get_return_nodes_only(node.children[2])
|
266
|
+
elsif SKIPPABLE.include?(node.type)
|
267
|
+
next
|
268
|
+
elsif node.type == :return
|
269
|
+
result.concat reduce_to_value_nodes([node.children[0]])
|
270
|
+
# Return the result here because the rest of the code is
|
271
|
+
# unreachable
|
272
|
+
return result
|
273
|
+
else
|
274
|
+
result.concat get_return_nodes_only(node)
|
275
|
+
end
|
276
|
+
result.concat reduce_to_value_nodes([nodes.last]) if idx == nodes.length - 1
|
277
|
+
end
|
278
|
+
result
|
279
|
+
end
|
280
|
+
|
281
|
+
def get_return_nodes_only parent
|
282
|
+
return [] unless parent.is_a?(::Parser::AST::Node)
|
283
|
+
result = []
|
284
|
+
nodes = parent.children.select{|n| n.is_a?(::Parser::AST::Node)}
|
285
|
+
nodes.each do |node|
|
286
|
+
next if SKIPPABLE.include?(node.type)
|
287
|
+
if node.type == :return
|
288
|
+
result.concat reduce_to_value_nodes([node.children[0]])
|
289
|
+
# Return the result here because the rest of the code is
|
290
|
+
# unreachable
|
291
|
+
return result
|
292
|
+
else
|
293
|
+
result.concat get_return_nodes_only(node)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
result
|
297
|
+
end
|
298
|
+
|
299
|
+
def reduce_to_value_nodes nodes
|
300
|
+
result = []
|
301
|
+
nodes.each do |node|
|
302
|
+
if !node.is_a?(::Parser::AST::Node)
|
303
|
+
result.push nil
|
304
|
+
elsif REDUCEABLE.include?(node.type)
|
305
|
+
result.concat get_return_nodes_from_children(node)
|
306
|
+
elsif CONDITIONAL.include?(node.type)
|
307
|
+
result.concat reduce_to_value_nodes(node.children[1..-1])
|
308
|
+
elsif node.type == :return
|
309
|
+
result.concat reduce_to_value_nodes([node.children[0]])
|
310
|
+
elsif node.type == :or
|
311
|
+
result.concat reduce_to_value_nodes(node.children)
|
312
|
+
elsif node.type == :block
|
313
|
+
result.concat get_return_nodes_only(node.children[2])
|
314
|
+
else
|
315
|
+
result.push node
|
316
|
+
end
|
317
|
+
end
|
318
|
+
result
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Parser
|
5
|
+
module Legacy
|
6
|
+
module NodeProcessors
|
7
|
+
class AliasNode < Parser::NodeProcessor::Base
|
8
|
+
def process
|
9
|
+
loc = get_node_location(node)
|
10
|
+
pins.push Solargraph::Pin::MethodAlias.new(
|
11
|
+
location: loc,
|
12
|
+
closure: region.closure,
|
13
|
+
name: node.children[0].children[0].to_s,
|
14
|
+
original: node.children[1].children[0].to_s,
|
15
|
+
scope: region.scope || :instance
|
16
|
+
)
|
17
|
+
process_children
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|