solargraph 0.47.2 → 0.53.3

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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/plugins.yml +40 -0
  4. data/.github/workflows/rspec.yml +4 -8
  5. data/.github/workflows/typecheck.yml +34 -0
  6. data/.yardopts +2 -2
  7. data/CHANGELOG.md +137 -3
  8. data/LICENSE +1 -1
  9. data/README.md +19 -16
  10. data/SPONSORS.md +2 -9
  11. data/lib/solargraph/api_map/cache.rb +60 -20
  12. data/lib/solargraph/api_map/source_to_yard.rb +17 -10
  13. data/lib/solargraph/api_map/store.rb +60 -12
  14. data/lib/solargraph/api_map.rb +171 -99
  15. data/lib/solargraph/bench.rb +3 -2
  16. data/lib/solargraph/cache.rb +77 -0
  17. data/lib/solargraph/complex_type/type_methods.rb +61 -12
  18. data/lib/solargraph/complex_type/unique_type.rb +193 -16
  19. data/lib/solargraph/complex_type.rb +113 -10
  20. data/lib/solargraph/convention/rakefile.rb +17 -0
  21. data/lib/solargraph/convention.rb +2 -3
  22. data/lib/solargraph/converters/dd.rb +5 -0
  23. data/lib/solargraph/converters/dl.rb +3 -0
  24. data/lib/solargraph/converters/dt.rb +3 -0
  25. data/lib/solargraph/diagnostics/rubocop.rb +23 -8
  26. data/lib/solargraph/diagnostics/rubocop_helpers.rb +4 -1
  27. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  28. data/lib/solargraph/diagnostics.rb +2 -2
  29. data/lib/solargraph/doc_map.rb +171 -0
  30. data/lib/solargraph/gem_pins.rb +64 -0
  31. data/lib/solargraph/language_server/host/cataloger.rb +2 -1
  32. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  33. data/lib/solargraph/language_server/host/dispatch.rb +15 -5
  34. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  35. data/lib/solargraph/language_server/host/sources.rb +7 -4
  36. data/lib/solargraph/language_server/host.rb +50 -26
  37. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  38. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  39. data/lib/solargraph/language_server/message/extended/download_core.rb +1 -5
  40. data/lib/solargraph/language_server/message/initialize.rb +13 -0
  41. data/lib/solargraph/language_server/message/initialized.rb +1 -0
  42. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +4 -1
  43. data/lib/solargraph/language_server/message/text_document/formatting.rb +4 -4
  44. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  45. data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -6
  46. data/lib/solargraph/language_server/message/text_document/type_definition.rb +24 -0
  47. data/lib/solargraph/language_server/message/text_document.rb +1 -1
  48. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  49. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +10 -3
  50. data/lib/solargraph/language_server/message.rb +1 -0
  51. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  52. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  53. data/lib/solargraph/library.rb +124 -37
  54. data/lib/solargraph/location.rb +1 -0
  55. data/lib/solargraph/page.rb +6 -0
  56. data/lib/solargraph/parser/comment_ripper.rb +4 -0
  57. data/lib/solargraph/parser/node_methods.rb +47 -7
  58. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  59. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -5
  60. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +57 -41
  62. data/lib/solargraph/parser/parser_gem/node_methods.rb +499 -0
  63. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  64. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +53 -0
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  66. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  67. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +14 -4
  68. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  69. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/def_node.rb +7 -20
  70. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  71. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  72. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  73. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  74. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  75. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  76. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  77. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +42 -0
  78. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  79. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sym_node.rb +1 -1
  80. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  81. data/lib/solargraph/parser/parser_gem.rb +12 -0
  82. data/lib/solargraph/parser/region.rb +1 -1
  83. data/lib/solargraph/parser/snippet.rb +2 -0
  84. data/lib/solargraph/parser.rb +9 -10
  85. data/lib/solargraph/pin/base.rb +69 -11
  86. data/lib/solargraph/pin/base_variable.rb +8 -4
  87. data/lib/solargraph/pin/block.rb +21 -28
  88. data/lib/solargraph/pin/closure.rb +17 -2
  89. data/lib/solargraph/pin/common.rb +7 -3
  90. data/lib/solargraph/pin/conversions.rb +34 -8
  91. data/lib/solargraph/pin/delegated_method.rb +97 -0
  92. data/lib/solargraph/pin/documenting.rb +25 -34
  93. data/lib/solargraph/pin/instance_variable.rb +4 -0
  94. data/lib/solargraph/pin/local_variable.rb +13 -1
  95. data/lib/solargraph/pin/method.rb +270 -16
  96. data/lib/solargraph/pin/namespace.rb +17 -1
  97. data/lib/solargraph/pin/parameter.rb +52 -17
  98. data/lib/solargraph/pin/reference/override.rb +2 -2
  99. data/lib/solargraph/pin/reference.rb +8 -0
  100. data/lib/solargraph/pin/search.rb +4 -4
  101. data/lib/solargraph/pin/signature.rb +143 -0
  102. data/lib/solargraph/pin.rb +2 -1
  103. data/lib/solargraph/range.rb +4 -6
  104. data/lib/solargraph/rbs_map/conversions.rb +601 -0
  105. data/lib/solargraph/rbs_map/core_fills.rb +47 -0
  106. data/lib/solargraph/rbs_map/core_map.rb +28 -0
  107. data/lib/solargraph/rbs_map/stdlib_map.rb +33 -0
  108. data/lib/solargraph/rbs_map.rb +84 -0
  109. data/lib/solargraph/shell.rb +69 -48
  110. data/lib/solargraph/source/chain/array.rb +32 -0
  111. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  112. data/lib/solargraph/source/chain/call.rb +125 -61
  113. data/lib/solargraph/source/chain/constant.rb +15 -1
  114. data/lib/solargraph/source/chain/if.rb +23 -0
  115. data/lib/solargraph/source/chain/link.rb +8 -2
  116. data/lib/solargraph/source/chain/or.rb +1 -1
  117. data/lib/solargraph/source/chain/z_super.rb +3 -3
  118. data/lib/solargraph/source/chain.rb +44 -14
  119. data/lib/solargraph/source/change.rb +3 -0
  120. data/lib/solargraph/source/cursor.rb +2 -0
  121. data/lib/solargraph/source/source_chainer.rb +8 -5
  122. data/lib/solargraph/source.rb +18 -19
  123. data/lib/solargraph/source_map/clip.rb +30 -23
  124. data/lib/solargraph/source_map/mapper.rb +20 -5
  125. data/lib/solargraph/source_map.rb +28 -13
  126. data/lib/solargraph/type_checker/checks.rb +10 -2
  127. data/lib/solargraph/type_checker.rb +201 -98
  128. data/lib/solargraph/version.rb +1 -1
  129. data/lib/solargraph/views/environment.erb +2 -2
  130. data/lib/solargraph/workspace/config.rb +14 -11
  131. data/lib/solargraph/workspace.rb +28 -17
  132. data/lib/solargraph/yard_map/cache.rb +6 -0
  133. data/lib/solargraph/yard_map/helpers.rb +1 -1
  134. data/lib/solargraph/yard_map/mapper/to_method.rb +18 -5
  135. data/lib/solargraph/yard_map/mapper.rb +1 -1
  136. data/lib/solargraph/yard_map/to_method.rb +11 -4
  137. data/lib/solargraph/yard_map.rb +1 -443
  138. data/lib/solargraph/yard_tags.rb +20 -0
  139. data/lib/solargraph/yardoc.rb +52 -0
  140. data/lib/solargraph.rb +8 -6
  141. data/solargraph.gemspec +19 -8
  142. metadata +162 -98
  143. data/.travis.yml +0 -19
  144. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  145. data/lib/solargraph/compat.rb +0 -37
  146. data/lib/solargraph/convention/rspec.rb +0 -30
  147. data/lib/solargraph/documentor.rb +0 -76
  148. data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
  149. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  150. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
  151. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  152. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +0 -63
  153. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +0 -21
  154. data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
  155. data/lib/solargraph/parser/legacy.rb +0 -12
  156. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -144
  157. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
  158. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
  159. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  160. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  161. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -22
  162. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  163. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -57
  164. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  165. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  166. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  167. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  168. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  169. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  170. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  171. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  172. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
  173. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -21
  174. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  175. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -277
  176. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +0 -18
  177. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
  178. data/lib/solargraph/parser/rubyvm.rb +0 -40
  179. data/lib/solargraph/yard_map/core_docs.rb +0 -170
  180. data/lib/solargraph/yard_map/core_fills.rb +0 -208
  181. data/lib/solargraph/yard_map/core_gen.rb +0 -76
  182. data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
  183. data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
  184. data/lib/yard-solargraph.rb +0 -33
  185. data/yardoc/2.2.2.tar.gz +0 -0
data/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- - 2.5
5
- - 2.6
6
- - 2.7
7
- - 3.0
8
- - jruby-head
9
- matrix:
10
- include:
11
- - rvm: 2.7
12
- os: osx
13
- allow_failures:
14
- - rvm: jruby-head
15
- before_install:
16
- - gem update --system
17
- - gem install bundler
18
- before_script: yard gems
19
- script: rspec
@@ -1,22 +0,0 @@
1
- require 'bundler'
2
- require 'shellwords'
3
-
4
- module Solargraph
5
- class ApiMap
6
- module BundlerMethods
7
- module_function
8
-
9
- # @param directory [String]
10
- # @return [Hash]
11
- def require_from_bundle directory
12
- begin
13
- Solargraph.logger.info "Loading gems for bundler/require"
14
- Documentor.specs_from_bundle(directory)
15
- rescue BundleNotFoundError => e
16
- Solargraph.logger.warn e.message
17
- {}
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,37 +0,0 @@
1
- unless Hash.method_defined?(:transform_keys)
2
- class Hash
3
- def transform_keys &block
4
- result = {}
5
- each_pair do |k, v|
6
- result[block.call(k)] = v
7
- end
8
- result
9
- end
10
- end
11
- end
12
-
13
- unless Hash.method_defined?(:transform_values)
14
- class Hash
15
- def transform_values &block
16
- result = {}
17
- each_pair do |k, v|
18
- result[k] = block.call(v)
19
- end
20
- result
21
- end
22
- end
23
- end
24
-
25
- unless Array.method_defined?(:sum)
26
- class Array
27
- def sum &block
28
- inject(0) do |s, x|
29
- if block
30
- s + block.call(x)
31
- else
32
- s + x
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Convention
5
- class Rspec < Base
6
- def local source_map
7
- return EMPTY_ENVIRON unless File.basename(source_map.filename) =~ /_spec\.rb$/
8
- @environ ||= Environ.new(
9
- requires: ['rspec'],
10
- domains: ['RSpec::Matchers', 'RSpec::ExpectationGroups'],
11
- pins: [
12
- # This override is necessary due to an erroneous @return tag in
13
- # rspec's YARD documentation.
14
- # @todo The return types have been fixed (https://github.com/rspec/rspec-expectations/pull/1121)
15
- Solargraph::Pin::Reference::Override.method_return('RSpec::Matchers#expect', 'RSpec::Expectations::ExpectationTarget')
16
- ].concat(extras)
17
- )
18
- end
19
-
20
- private
21
-
22
- def extras
23
- @@extras ||= SourceMap.load_string(%(
24
- def describe(*args); end
25
- def it(*args); end
26
- )).pins
27
- end
28
- end
29
- end
30
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler'
4
- require 'json'
5
- require 'open3'
6
- require 'shellwords'
7
- require 'yard'
8
- require 'fileutils'
9
-
10
- module Solargraph
11
- class Documentor
12
- RDOC_GEMS = %w[
13
- actioncable actionmailbox actionmailer actionpack actiontext actionview
14
- activejob activemodel activerecord activestorage activesupport railties
15
- ]
16
-
17
- def initialize directory, rebuild: false, out: File.new(File::NULL, 'w')
18
- @directory = directory
19
- @rebuild = rebuild
20
- @out = out
21
- end
22
-
23
- # @return [Boolean] True if all specs were found and documented.
24
- def document
25
- failures = 0
26
- Documentor.specs_from_bundle(@directory).each_pair do |name, version|
27
- yd = YARD::Registry.yardoc_file_for_gem(name, "= #{version}")
28
- if !yd || @rebuild
29
- FileUtils.safe_unlink File.join(YardMap::CoreDocs.cache_dir, 'gems', "#{name}-#{version}.ser")
30
- @out.puts "Documenting #{name} #{version}"
31
- `yard gems #{name} #{version} #{@rebuild ? '--rebuild' : ''}`
32
- yd = YARD::Registry.yardoc_file_for_gem(name, "= #{version}")
33
- # HACK: Ignore errors documenting bundler
34
- if !yd && name != 'bundler'
35
- @out.puts "#{name} #{version} YARD documentation failed"
36
- failures += 1
37
- end
38
- end
39
- if yd && RDOC_GEMS.include?(name)
40
- cache = File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{name}-#{version}", 'yardoc')
41
- if !File.exist?(cache) || @rebuild
42
- @out.puts "Caching custom documentation for #{name} #{version}"
43
- spec = Gem::Specification.find_by_name(name, "= #{version}")
44
- Solargraph::YardMap::RdocToYard.run(spec)
45
- end
46
- end
47
- end
48
- if failures > 0
49
- @out.puts "#{failures} gem#{failures == 1 ? '' : 's'} could not be documented. You might need to run `bundle install`."
50
- end
51
- failures == 0
52
- rescue Solargraph::BundleNotFoundError => e
53
- @out.puts "[#{e.class}] #{e.message}"
54
- @out.puts "No bundled gems are available in #{@directory}"
55
- false
56
- end
57
-
58
- # @param directory [String]
59
- # @return [Hash]
60
- def self.specs_from_bundle directory
61
- Solargraph.with_clean_env do
62
- cmd = [
63
- 'ruby', '-e',
64
- "require 'bundler'; require 'json'; Dir.chdir('#{directory}') { puts Bundler.definition.specs_for([:default]).map { |spec| [spec.name, spec.version] }.to_h.to_json }"
65
- ]
66
- o, e, s = Open3.capture3(*cmd)
67
- if s.success?
68
- o && !o.empty? ? JSON.parse(o.split("\n").last) : {}
69
- else
70
- Solargraph.logger.warn e
71
- raise BundleNotFoundError, "Failed to load gems from bundle at #{directory}"
72
- end
73
- end
74
- end
75
- end
76
- end
@@ -1,325 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Legacy
6
- module NodeProcessors
7
- class ArgsNode < Parser::NodeProcessor::Base
8
- def process
9
- node.children.each do |u|
10
- loc = get_node_location(u)
11
- locals.push Solargraph::Pin::Parameter.new(
12
- location: loc,
13
- closure: region.closure,
14
- comments: comments_for(node),
15
- name: u.children[0].to_s,
16
- assignment: u.children[1],
17
- asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
18
- presence: region.closure.location.range,
19
- decl: get_decl(u)
20
- )
21
- region.closure.parameters.push locals.last
22
- end
23
- process_children
24
- end
25
-
26
- private
27
-
28
- def get_decl node
29
- node.type
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Legacy
6
- module NodeProcessors
7
- class BeginNode < Parser::NodeProcessor::Base
8
- def process
9
- process_children
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Legacy
6
- module NodeProcessors
7
- class DefNode < Parser::NodeProcessor::Base
8
- def process
9
- methpin = Solargraph::Pin::Method.new(
10
- location: get_node_location(node),
11
- closure: region.closure,
12
- name: node.children[0].to_s,
13
- comments: comments_for(node),
14
- scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
15
- visibility: region.visibility,
16
- node: node
17
- )
18
- if methpin.name == 'initialize' and methpin.scope == :instance
19
- pins.push Solargraph::Pin::Method.new(
20
- location: methpin.location,
21
- closure: methpin.closure,
22
- name: 'new',
23
- comments: methpin.comments,
24
- scope: :class,
25
- parameters: methpin.parameters
26
- )
27
- # @todo Smelly instance variable access.
28
- pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
29
- pins.push methpin
30
- # @todo Smelly instance variable access.
31
- methpin.instance_variable_set(:@visibility, :private)
32
- methpin.instance_variable_set(:@return_type, ComplexType::VOID)
33
- elsif region.visibility == :module_function
34
- pins.push Solargraph::Pin::Method.new(
35
- location: methpin.location,
36
- closure: methpin.closure,
37
- name: methpin.name,
38
- comments: methpin.comments,
39
- scope: :class,
40
- visibility: :public,
41
- parameters: methpin.parameters,
42
- node: methpin.node
43
- )
44
- pins.push Solargraph::Pin::Method.new(
45
- location: methpin.location,
46
- closure: methpin.closure,
47
- name: methpin.name,
48
- comments: methpin.comments,
49
- scope: :instance,
50
- visibility: :private,
51
- parameters: methpin.parameters,
52
- node: methpin.node
53
- )
54
- else
55
- pins.push methpin
56
- end
57
- process_children region.update(closure: methpin, scope: methpin.scope)
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Legacy
6
- module NodeProcessors
7
- class SclassNode < Parser::NodeProcessor::Base
8
- def process
9
- # @todo Temporarily skipping remote metaclasses
10
- return unless node.children[0].is_a?(AST::Node) && node.children[0].type == :self
11
- pins.push Solargraph::Pin::Singleton.new(
12
- location: get_node_location(node),
13
- closure: region.closure
14
- )
15
- process_children region.update(visibility: :public, scope: :class, closure: pins.last)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end