solargraph 0.58.3 → 0.59.2

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 (229) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.github/workflows/linting.yml +12 -5
  4. data/.github/workflows/plugins.yml +54 -34
  5. data/.github/workflows/rspec.yml +15 -28
  6. data/.github/workflows/typecheck.yml +6 -3
  7. data/.rubocop.yml +38 -6
  8. data/.rubocop_todo.yml +53 -966
  9. data/CHANGELOG.md +24 -0
  10. data/Gemfile +3 -1
  11. data/README.md +3 -3
  12. data/Rakefile +26 -23
  13. data/bin/solargraph +2 -1
  14. data/lib/solargraph/api_map/cache.rb +3 -3
  15. data/lib/solargraph/api_map/constants.rb +12 -3
  16. data/lib/solargraph/api_map/index.rb +29 -18
  17. data/lib/solargraph/api_map/source_to_yard.rb +22 -9
  18. data/lib/solargraph/api_map/store.rb +40 -30
  19. data/lib/solargraph/api_map.rb +160 -78
  20. data/lib/solargraph/bench.rb +2 -3
  21. data/lib/solargraph/complex_type/conformance.rb +176 -0
  22. data/lib/solargraph/complex_type/type_methods.rb +31 -18
  23. data/lib/solargraph/complex_type/unique_type.rb +221 -63
  24. data/lib/solargraph/complex_type.rb +173 -59
  25. data/lib/solargraph/convention/active_support_concern.rb +111 -111
  26. data/lib/solargraph/convention/base.rb +50 -50
  27. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +1 -1
  28. data/lib/solargraph/convention/data_definition/data_definition_node.rb +7 -5
  29. data/lib/solargraph/convention/data_definition.rb +5 -2
  30. data/lib/solargraph/convention/gemfile.rb +1 -1
  31. data/lib/solargraph/convention/gemspec.rb +1 -1
  32. data/lib/solargraph/convention/rakefile.rb +1 -1
  33. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +2 -1
  34. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -3
  35. data/lib/solargraph/convention/struct_definition.rb +8 -4
  36. data/lib/solargraph/convention.rb +2 -2
  37. data/lib/solargraph/converters/dd.rb +2 -0
  38. data/lib/solargraph/converters/dl.rb +2 -0
  39. data/lib/solargraph/converters/dt.rb +2 -0
  40. data/lib/solargraph/converters/misc.rb +2 -0
  41. data/lib/solargraph/diagnostics/require_not_found.rb +1 -0
  42. data/lib/solargraph/diagnostics/rubocop.rb +11 -10
  43. data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
  44. data/lib/solargraph/diagnostics/type_check.rb +11 -10
  45. data/lib/solargraph/diagnostics/update_errors.rb +4 -8
  46. data/lib/solargraph/diagnostics.rb +55 -55
  47. data/lib/solargraph/doc_map.rb +38 -39
  48. data/lib/solargraph/environ.rb +52 -52
  49. data/lib/solargraph/equality.rb +4 -4
  50. data/lib/solargraph/gem_pins.rb +4 -15
  51. data/lib/solargraph/language_server/error_codes.rb +10 -10
  52. data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
  53. data/lib/solargraph/language_server/host/dispatch.rb +3 -3
  54. data/lib/solargraph/language_server/host/message_worker.rb +4 -3
  55. data/lib/solargraph/language_server/host/sources.rb +2 -1
  56. data/lib/solargraph/language_server/host.rb +35 -28
  57. data/lib/solargraph/language_server/message/base.rb +1 -1
  58. data/lib/solargraph/language_server/message/client/register_capability.rb +1 -3
  59. data/lib/solargraph/language_server/message/completion_item/resolve.rb +6 -8
  60. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +12 -18
  61. data/lib/solargraph/language_server/message/extended/document.rb +1 -0
  62. data/lib/solargraph/language_server/message/extended/document_gems.rb +7 -7
  63. data/lib/solargraph/language_server/message/extended/download_core.rb +2 -1
  64. data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
  65. data/lib/solargraph/language_server/message/extended/search.rb +1 -1
  66. data/lib/solargraph/language_server/message/initialize.rb +20 -14
  67. data/lib/solargraph/language_server/message/initialized.rb +28 -28
  68. data/lib/solargraph/language_server/message/text_document/completion.rb +10 -8
  69. data/lib/solargraph/language_server/message/text_document/definition.rb +41 -32
  70. data/lib/solargraph/language_server/message/text_document/document_highlight.rb +17 -10
  71. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -19
  72. data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -6
  73. data/lib/solargraph/language_server/message/text_document/hover.rb +5 -5
  74. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +13 -6
  75. data/lib/solargraph/language_server/message/text_document/references.rb +17 -10
  76. data/lib/solargraph/language_server/message/text_document/rename.rb +20 -13
  77. data/lib/solargraph/language_server/message/text_document/signature_help.rb +3 -2
  78. data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -17
  79. data/lib/solargraph/language_server/message/text_document.rb +28 -28
  80. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +34 -28
  81. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +38 -30
  82. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +23 -17
  83. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -17
  84. data/lib/solargraph/language_server/message.rb +1 -1
  85. data/lib/solargraph/language_server/progress.rb +143 -143
  86. data/lib/solargraph/language_server/request.rb +4 -2
  87. data/lib/solargraph/language_server/transport/adapter.rb +68 -68
  88. data/lib/solargraph/language_server/transport/data_reader.rb +11 -13
  89. data/lib/solargraph/language_server/uri_helpers.rb +2 -2
  90. data/lib/solargraph/language_server.rb +20 -20
  91. data/lib/solargraph/library.rb +57 -38
  92. data/lib/solargraph/location.rb +17 -14
  93. data/lib/solargraph/logging.rb +22 -4
  94. data/lib/solargraph/page.rb +1 -1
  95. data/lib/solargraph/parser/comment_ripper.rb +19 -4
  96. data/lib/solargraph/parser/flow_sensitive_typing.rb +324 -108
  97. data/lib/solargraph/parser/node_processor/base.rb +34 -4
  98. data/lib/solargraph/parser/node_processor.rb +8 -7
  99. data/lib/solargraph/parser/parser_gem/class_methods.rb +30 -14
  100. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -1
  101. data/lib/solargraph/parser/parser_gem/node_chainer.rb +51 -25
  102. data/lib/solargraph/parser/parser_gem/node_methods.rb +181 -73
  103. data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
  104. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
  105. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +13 -11
  106. data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
  107. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +11 -12
  108. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
  109. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
  110. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +10 -3
  111. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +9 -8
  112. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
  113. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +36 -6
  114. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +5 -3
  115. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
  116. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
  117. data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +40 -40
  118. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +3 -3
  119. data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
  120. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
  121. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
  122. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -5
  123. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +124 -113
  124. data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +20 -20
  125. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +1 -1
  126. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
  127. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +6 -2
  128. data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
  129. data/lib/solargraph/parser/parser_gem.rb +2 -0
  130. data/lib/solargraph/parser/region.rb +9 -3
  131. data/lib/solargraph/parser/snippet.rb +3 -1
  132. data/lib/solargraph/parser.rb +2 -0
  133. data/lib/solargraph/pin/base.rb +126 -82
  134. data/lib/solargraph/pin/base_variable.rb +273 -24
  135. data/lib/solargraph/pin/block.rb +29 -6
  136. data/lib/solargraph/pin/breakable.rb +7 -1
  137. data/lib/solargraph/pin/callable.rb +65 -21
  138. data/lib/solargraph/pin/closure.rb +7 -10
  139. data/lib/solargraph/pin/common.rb +24 -6
  140. data/lib/solargraph/pin/compound_statement.rb +55 -0
  141. data/lib/solargraph/pin/constant.rb +3 -5
  142. data/lib/solargraph/pin/conversions.rb +10 -4
  143. data/lib/solargraph/pin/delegated_method.rb +19 -8
  144. data/lib/solargraph/pin/documenting.rb +4 -2
  145. data/lib/solargraph/pin/instance_variable.rb +5 -1
  146. data/lib/solargraph/pin/keyword.rb +0 -4
  147. data/lib/solargraph/pin/local_variable.rb +15 -59
  148. data/lib/solargraph/pin/method.rb +158 -104
  149. data/lib/solargraph/pin/method_alias.rb +8 -0
  150. data/lib/solargraph/pin/namespace.rb +19 -12
  151. data/lib/solargraph/pin/parameter.rb +102 -36
  152. data/lib/solargraph/pin/proxy_type.rb +4 -1
  153. data/lib/solargraph/pin/reference/override.rb +1 -1
  154. data/lib/solargraph/pin/reference/require.rb +14 -14
  155. data/lib/solargraph/pin/reference/superclass.rb +2 -0
  156. data/lib/solargraph/pin/reference/type_alias.rb +16 -0
  157. data/lib/solargraph/pin/reference.rb +20 -0
  158. data/lib/solargraph/pin/search.rb +8 -7
  159. data/lib/solargraph/pin/signature.rb +15 -12
  160. data/lib/solargraph/pin/singleton.rb +11 -11
  161. data/lib/solargraph/pin/symbol.rb +2 -1
  162. data/lib/solargraph/pin/until.rb +2 -4
  163. data/lib/solargraph/pin/while.rb +2 -4
  164. data/lib/solargraph/pin.rb +2 -0
  165. data/lib/solargraph/pin_cache.rb +22 -19
  166. data/lib/solargraph/position.rb +17 -10
  167. data/lib/solargraph/range.rb +16 -15
  168. data/lib/solargraph/rbs_map/conversions.rb +367 -231
  169. data/lib/solargraph/rbs_map/core_fills.rb +18 -11
  170. data/lib/solargraph/rbs_map/core_map.rb +24 -17
  171. data/lib/solargraph/rbs_map/stdlib_map.rb +33 -5
  172. data/lib/solargraph/rbs_map.rb +76 -32
  173. data/lib/solargraph/server_methods.rb +1 -1
  174. data/lib/solargraph/shell.rb +258 -66
  175. data/lib/solargraph/source/chain/array.rb +3 -12
  176. data/lib/solargraph/source/chain/block_symbol.rb +13 -13
  177. data/lib/solargraph/source/chain/block_variable.rb +13 -13
  178. data/lib/solargraph/source/chain/call.rb +96 -56
  179. data/lib/solargraph/source/chain/class_variable.rb +1 -1
  180. data/lib/solargraph/source/chain/constant.rb +5 -1
  181. data/lib/solargraph/source/chain/global_variable.rb +1 -1
  182. data/lib/solargraph/source/chain/hash.rb +8 -5
  183. data/lib/solargraph/source/chain/head.rb +19 -19
  184. data/lib/solargraph/source/chain/if.rb +12 -10
  185. data/lib/solargraph/source/chain/instance_variable.rb +24 -1
  186. data/lib/solargraph/source/chain/link.rb +12 -22
  187. data/lib/solargraph/source/chain/literal.rb +22 -15
  188. data/lib/solargraph/source/chain/or.rb +10 -4
  189. data/lib/solargraph/source/chain/q_call.rb +2 -0
  190. data/lib/solargraph/source/chain/variable.rb +3 -1
  191. data/lib/solargraph/source/chain/z_super.rb +1 -3
  192. data/lib/solargraph/source/chain.rb +51 -38
  193. data/lib/solargraph/source/change.rb +12 -5
  194. data/lib/solargraph/source/cursor.rb +33 -18
  195. data/lib/solargraph/source/encoding_fixes.rb +6 -7
  196. data/lib/solargraph/source/source_chainer.rb +56 -32
  197. data/lib/solargraph/source/updater.rb +5 -1
  198. data/lib/solargraph/source.rb +59 -35
  199. data/lib/solargraph/source_map/clip.rb +54 -30
  200. data/lib/solargraph/source_map/data.rb +4 -1
  201. data/lib/solargraph/source_map/mapper.rb +69 -42
  202. data/lib/solargraph/source_map.rb +21 -9
  203. data/lib/solargraph/type_checker/problem.rb +3 -1
  204. data/lib/solargraph/type_checker/rules.rb +81 -8
  205. data/lib/solargraph/type_checker.rb +196 -122
  206. data/lib/solargraph/version.rb +1 -1
  207. data/lib/solargraph/workspace/config.rb +14 -11
  208. data/lib/solargraph/workspace/gemspecs.rb +367 -0
  209. data/lib/solargraph/workspace/require_paths.rb +1 -0
  210. data/lib/solargraph/workspace.rb +50 -28
  211. data/lib/solargraph/yard_map/cache.rb +25 -25
  212. data/lib/solargraph/yard_map/helpers.rb +8 -3
  213. data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
  214. data/lib/solargraph/yard_map/mapper/to_method.rb +13 -7
  215. data/lib/solargraph/yard_map/mapper/to_namespace.rb +2 -1
  216. data/lib/solargraph/yard_map/mapper.rb +13 -8
  217. data/lib/solargraph/yard_map.rb +17 -18
  218. data/lib/solargraph/yard_tags.rb +2 -2
  219. data/lib/solargraph/yardoc.rb +7 -4
  220. data/lib/solargraph.rb +33 -10
  221. data/rbs/fills/rubygems/0/dependency.rbs +193 -0
  222. data/rbs/shims/ast/0/node.rbs +1 -1
  223. data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
  224. data/solargraph.gemspec +37 -35
  225. metadata +41 -42
  226. data/lib/solargraph/type_checker/checks.rb +0 -124
  227. data/lib/solargraph/type_checker/param_def.rb +0 -37
  228. data/lib/solargraph/yard_map/to_method.rb +0 -89
  229. data/rbs/fills/tuple/tuple.rbs +0 -149
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 0.59.2 - May 22, 2026
2
+ - Convert RBS implicit nil annotations (#1197)
3
+ - Temporary job stubs (#1200)
4
+ - Limit pin combination to doc maps (#1195)
5
+ - Ignore literal values in type inference (#1201)
6
+ - Fix for clips with flaky node recipients
7
+
8
+ ## 0.59.1 - May 18, 2026
9
+ - Fix signatureHelp bug (#1185)
10
+ - Linting fixes for Ruby 3.1 (#1193)
11
+ - Parameters shadow local variables with same name (#1192)
12
+
13
+ ## 0.59.0 - May 13, 2026
14
+ - Ensure pathname is required for rbs in shell caching processes (#1183)
15
+ - Pre-release branch 2026-01-12 (#1152)
16
+ - 2026-01-27 dev branch (#1165)
17
+ - Position linting (#1179)
18
+ - Revert YARD and RBS pin caching (#1180)
19
+ - Ensure pathname is required for rbs in shell caching processes (#1183)
20
+ - Limit default include glob to current directory (#1184)
21
+ - Require Ruby >= 3.1.0
22
+ - Require RBS >= 3.10.0
23
+ - Stub combine_same_type_arity_signatures (#1186)
24
+
1
25
  ## 0.58.3 - March 9, 2026
2
26
  - Ignore workspace dependencies in cache processes (#1174)
3
27
 
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec name: 'solargraph'
4
6
 
5
7
  # Local gemfile for development tools, etc.
6
- local_gemfile = File.expand_path(".Gemfile", __dir__)
8
+ local_gemfile = File.expand_path('.Gemfile', __dir__)
7
9
  instance_eval File.read local_gemfile if File.exist? local_gemfile
data/README.md CHANGED
@@ -51,6 +51,8 @@ Plug-ins and extensions are available for the following editors:
51
51
 
52
52
  Solargraph's behavior can be controlled via optional [configuration](https://solargraph.org/guides/configuration) files. The highest priority file is a `.solargraph.yml` file at the root of the project. If not present, any global configuration at `~/.config/solargraph/config.yml` will apply. The path to the global configuration can be overridden with the `SOLARGRAPH_GLOBAL_CONFIG` environment variable.
53
53
 
54
+ Use `bundle exec solargraph config` to create a configuration file.
55
+
54
56
  ### Plugins
55
57
 
56
58
  Solargraph supports [plugins](https://solargraph.org/guides/plugins) that implement their own Solargraph features, such as diagnostics reporters and conventions to provide LSP features and type-checking, e.g. for frameworks which use metaprogramming and/or DSLs.
@@ -132,9 +134,7 @@ See [https://solargraph.org/guides](https://solargraph.org/guides) for more tips
132
134
 
133
135
  ### Development
134
136
 
135
- To see more logging when typechecking or running specs, set the
136
- `SOLARGRAPH_LOG` environment variable to `debug` or `info`. `warn` is
137
- the default value.
137
+ To see more logging when typechecking or running specs, set the `SOLARGRAPH_LOG` environment variable to `debug` or `info`. `warn` is the default value.
138
138
 
139
139
  Code contributions are always appreciated. Feel free to fork the repo and submit pull requests. Check for open issues that could use help. Start new issues to discuss changes that have a major impact on the code or require large time commitments.
140
140
 
data/Rakefile CHANGED
@@ -1,42 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'bundler/gem_tasks'
3
5
  require 'fileutils'
4
6
  require 'open3'
5
7
 
6
- desc "Open a Pry session preloaded with this library"
8
+ desc 'Open a Pry session preloaded with this library'
7
9
  task :console do
8
- sh "pry -I lib -r solargraph.rb"
10
+ sh 'pry -I lib -r solargraph.rb'
9
11
  end
10
12
 
11
- desc "Run the type checker"
13
+ desc 'Run the type checker'
12
14
  task typecheck: [:typecheck_strong]
13
15
 
14
- desc "Run the type checker at typed level - return code issues provable without annotations being correct"
16
+ desc 'Run the type checker at typed level - return code issues provable without annotations being correct'
15
17
  task :typecheck_typed do
16
- sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed"
18
+ sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed'
17
19
  end
18
20
 
19
- desc "Run the type checker at strict level - report issues using type annotations"
21
+ desc 'Run the type checker at strict level - report issues using type annotations'
20
22
  task :typecheck_strict do
21
- sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strict"
23
+ sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strict'
22
24
  end
23
25
 
24
- desc "Run the type checker at strong level - enforce that type annotations exist"
26
+ desc 'Run the type checker at strong level - enforce that type annotations exist'
25
27
  task :typecheck_strong do
26
- sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strong"
28
+ sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strong'
27
29
  end
28
30
 
29
- desc "Run the type checker at alpha level - run high-false-alarm checks"
31
+ desc 'Run the type checker at alpha level - run high-false-alarm checks'
30
32
  task :typecheck_alpha do
31
- sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level alpha"
33
+ sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level alpha'
32
34
  end
33
35
 
34
- desc "Run RSpec tests, starting with the ones that failed last time"
36
+ desc 'Run RSpec tests, starting with the ones that failed last time'
35
37
  task spec: %i[spec_failed undercover_no_fail full_spec] do
36
38
  undercover
37
39
  end
38
40
 
39
- desc "Run all RSpec tests"
41
+ desc 'Run all RSpec tests'
40
42
  task :full_spec do
41
43
  warn 'starting spec'
42
44
  sh 'TEST_COVERAGE_COMMAND_NAME=full-new bundle exec rspec' # --profile'
@@ -63,19 +65,20 @@ def undercover
63
65
  status
64
66
  rescue StandardError => e
65
67
  warn "hit error: #{e.message}"
68
+ # @sg-ignore Need to add nil check here
66
69
  warn "Backtrace:\n#{e.backtrace.join("\n")}"
67
70
  warn "output: #{output}"
68
- puts "Flushing"
71
+ puts 'Flushing'
69
72
  $stdout.flush
70
73
  raise
71
74
  end
72
75
 
73
- desc "Check PR coverage"
76
+ desc 'Check PR coverage'
74
77
  task :undercover do
75
- raise "Undercover failed" unless undercover.success?
78
+ raise 'Undercover failed' unless undercover.success?
76
79
  end
77
80
 
78
- desc "Branch-focused fast-feedback quality/spec/coverage checks"
81
+ desc 'Branch-focused fast-feedback quality/spec/coverage checks'
79
82
  task test: %i[overcommit spec typecheck] do
80
83
  # do these in order
81
84
  Rake::Task['typecheck_strict'].invoke
@@ -83,18 +86,18 @@ task test: %i[overcommit spec typecheck] do
83
86
  Rake::Task['typecheck_alpha'].invoke
84
87
  end
85
88
 
86
- desc "Re-run failed specs. Add --fail-fast in your .rspec-local file if desired."
89
+ desc 'Re-run failed specs. Add --fail-fast in your .rspec-local file if desired.'
87
90
  task :spec_failed do
88
91
  # allow user to check out any persistent failures while looking for
89
92
  # more in the whole test suite
90
93
  sh 'TEST_COVERAGE_COMMAND_NAME=next-failure bundle exec rspec --only-failures || true'
91
94
  end
92
95
 
93
- desc "Run undercover and show output without failing the task if it fails"
96
+ desc 'Run undercover and show output without failing the task if it fails'
94
97
  task :undercover_no_fail do
95
98
  undercover
96
99
  rescue StandardError
97
- puts "Undercover failed, but continuing with other tasks."
100
+ puts 'Undercover failed, but continuing with other tasks.'
98
101
  end
99
102
 
100
103
  # @return [void]
@@ -103,7 +106,7 @@ def simplecov_collate
103
106
  require 'simplecov-lcov'
104
107
  require 'undercover/simplecov_formatter'
105
108
 
106
- SimpleCov.collate(Dir["coverage/{next-failure,full,ad-hoc}/.resultset.json"]) do
109
+ SimpleCov.collate(Dir['coverage/{next-failure,full,ad-hoc}/.resultset.json']) do
107
110
  cname = 'combined'
108
111
  command_name cname
109
112
  new_dir = File.join('coverage', cname)
@@ -118,7 +121,7 @@ def simplecov_collate
118
121
  ])
119
122
  SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
120
123
  end
121
- puts "Simplecov collated results into coverage/combined/.resultset.json"
124
+ puts 'Simplecov collated results into coverage/combined/.resultset.json'
122
125
  rescue StandardError => e
123
126
  puts "Simplecov collate failed: #{e.message}"
124
127
  ensure
@@ -130,7 +133,7 @@ task :simplecov_collate do
130
133
  simplecov_collate
131
134
  end
132
135
 
133
- desc "Show quality checks on this development branch so far, including any staged files"
136
+ desc 'Show quality checks on this development branch so far, including any staged files'
134
137
  task :overcommit do
135
138
  # OVERCOMMIT_DEBUG=1 will show more detail
136
139
  sh 'SOLARGRAPH_ASSERTS=on bundle exec overcommit --run --diff origin/master'
data/bin/solargraph CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # turn off warning diagnostics from Ruby
4
- $VERBOSE=nil
5
+ $VERBOSE = nil
5
6
 
6
7
  require 'solargraph'
7
8
 
@@ -8,7 +8,7 @@ module Solargraph
8
8
  @methods = {}
9
9
  # @type [Hash{String, Array<String> => Array<Pin::Base>}]
10
10
  @constants = {}
11
- # @type [Hash{String => String}]
11
+ # @type [Hash{String => String, nil}]
12
12
  @qualified_namespaces = {}
13
13
  # @type [Hash{String => Pin::Method}]
14
14
  @receiver_definitions = {}
@@ -61,14 +61,14 @@ module Solargraph
61
61
 
62
62
  # @param name [String]
63
63
  # @param context [String]
64
- # @return [String]
64
+ # @return [String, nil]
65
65
  def get_qualified_namespace name, context
66
66
  @qualified_namespaces["#{name}|#{context}"]
67
67
  end
68
68
 
69
69
  # @param name [String]
70
70
  # @param context [String]
71
- # @param value [String]
71
+ # @param value [String, nil]
72
72
  # @return [void]
73
73
  def set_qualified_namespace name, context, value
74
74
  @qualified_namespaces["#{name}|#{context}"] = value
@@ -27,9 +27,11 @@ module Solargraph
27
27
  # @param name [String] Namespace which may relative and not be rooted.
28
28
  # @param gates [Array<Array<String>, String>] Namespaces to search while resolving the name
29
29
  #
30
+ # @sg-ignore flow sensitive typing needs to eliminate literal from union with return if foo == :bar
30
31
  # @return [String, nil] fully qualified namespace (i.e., is
31
32
  # absolute, but will not start with ::)
32
33
  def resolve(name, *gates)
34
+ # @sg-ignore Need to add nil check here
33
35
  return store.get_path_pins(name[2..]).first&.path if name.start_with?('::')
34
36
 
35
37
  flat = gates.flatten
@@ -86,6 +88,7 @@ module Solargraph
86
88
  return unless fqns
87
89
  pin = store.get_path_pins(fqns).first
88
90
  if pin.is_a?(Pin::Constant)
91
+ # @sg-ignore Need to add nil check here
89
92
  const = Solargraph::Parser::NodeMethods.unpack_name(pin.assignment)
90
93
  return unless const
91
94
  fqns = resolve(const, *pin.gates)
@@ -105,6 +108,7 @@ module Solargraph
105
108
 
106
109
  # @param name [String]
107
110
  # @param gates [Array<String>]
111
+ # @sg-ignore flow sensitive typing should be able to handle redefinition
108
112
  # @return [String, nil]
109
113
  def resolve_and_cache name, gates
110
114
  cached_resolve[[name, gates]] = :in_process
@@ -125,6 +129,7 @@ module Solargraph
125
129
  if resolved
126
130
  base = [resolved]
127
131
  else
132
+ # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
128
133
  return resolve(name, first) unless first.empty?
129
134
  end
130
135
  end
@@ -138,7 +143,7 @@ module Solargraph
138
143
  # @param name [String]
139
144
  # @param gates [Array<String>]
140
145
  # @param internal [Boolean] True if the name is not the last in the namespace
141
- # @return [Array(Object, Array<String>)]
146
+ # @return [Array(String, Array<String>), Array(nil, Array<String>), String]
142
147
  def complex_resolve name, gates, internal
143
148
  resolved = nil
144
149
  gates.each.with_index do |gate, idx|
@@ -165,6 +170,7 @@ module Solargraph
165
170
  here = "#{gate}::#{name}".sub(/^::/, '').sub(/::$/, '')
166
171
  pin = store.get_path_pins(here).first
167
172
  if pin.is_a?(Pin::Constant) && internal
173
+ # @sg-ignore Need to add nil check here
168
174
  const = Solargraph::Parser::NodeMethods.unpack_name(pin.assignment)
169
175
  return unless const
170
176
  resolve(const, pin.gates)
@@ -197,13 +203,14 @@ module Solargraph
197
203
  # will start the search in the specified context until it finds a
198
204
  # match for the namespace.
199
205
  #
200
- # @param namespace [String, nil] The namespace to
206
+ # @param namespace [String] The namespace to
201
207
  # match
202
208
  # @param context_namespace [String] The context namespace in which the
203
209
  # tag was referenced; start from here to resolve the name
204
210
  # @return [String, nil] fully qualified namespace
205
211
  def qualify_namespace namespace, context_namespace = ''
206
212
  if namespace.start_with?('::')
213
+ # @sg-ignore Need to add nil check here
207
214
  inner_qualify(namespace[2..], '', Set.new)
208
215
  else
209
216
  inner_qualify(namespace, context_namespace, Set.new)
@@ -249,7 +256,7 @@ module Solargraph
249
256
  end
250
257
  end
251
258
 
252
- # @param fqns [String]
259
+ # @param fqns [String, nil]
253
260
  # @param visibility [Array<Symbol>]
254
261
  # @param skip [Set<String>]
255
262
  # @return [Array<Solargraph::Pin::Namespace, Solargraph::Pin::Constant>]
@@ -259,11 +266,13 @@ module Solargraph
259
266
  result = []
260
267
 
261
268
  store.get_prepends(fqns).each do |pre|
269
+ # @sg-ignore Need to add nil check here
262
270
  pre_fqns = resolve(pre.name, pre.closure.gates - skip.to_a)
263
271
  result.concat inner_get_constants(pre_fqns, [:public], skip)
264
272
  end
265
273
  result.concat(store.get_constants(fqns, visibility).sort { |a, b| a.name <=> b.name })
266
274
  store.get_includes(fqns).each do |pin|
275
+ # @sg-ignore Need to add nil check here
267
276
  inc_fqns = resolve(pin.name, pin.closure.gates - skip.to_a)
268
277
  result.concat inner_get_constants(inc_fqns, [:public], skip)
269
278
  end
@@ -36,17 +36,22 @@ module Solargraph
36
36
  @path_pin_hash ||= Hash.new { |h, k| h[k] = [] }
37
37
  end
38
38
 
39
+ # @return [Hash{String => ComplexType}]
40
+ def alias_hash
41
+ @alias_hash ||= {}
42
+ end
43
+
39
44
  # @generic T
40
45
  # @param klass [Class<generic<T>>]
41
46
  # @return [Set<generic<T>>]
42
47
  def pins_by_class klass
43
- # @type [Set<Solargraph::Pin::Base>]
48
+ # @type [Set<generic<T>>]
44
49
  s = Set.new
45
50
  # @sg-ignore need to support destructured args in blocks
46
51
  @pin_select_cache[klass] ||= pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
47
52
  end
48
53
 
49
- # @return [Hash{String => Array<String>}]
54
+ # @return [Hash{String => Array<Pin::Reference::Include>}]
50
55
  def include_references
51
56
  # @param h [String]
52
57
  # @param k [Array<String>]
@@ -60,21 +65,21 @@ module Solargraph
60
65
  @include_reference_pins ||= Hash.new { |h, k| h[k] = [] }
61
66
  end
62
67
 
63
- # @return [Hash{String => Array<String>}]
68
+ # @return [Hash{String => Array<Pin::Reference::Extend>}]
64
69
  def extend_references
65
70
  # @param h [String]
66
71
  # @param k [Array<String>]
67
72
  @extend_references ||= Hash.new { |h, k| h[k] = [] }
68
73
  end
69
74
 
70
- # @return [Hash{String => Array<String>}]
75
+ # @return [Hash{String => Array<Pin::Reference::Prepend>}]
71
76
  def prepend_references
72
77
  # @param h [String]
73
78
  # @param k [Array<String>]
74
79
  @prepend_references ||= Hash.new { |h, k| h[k] = [] }
75
80
  end
76
81
 
77
- # @return [Hash{String => Array<String>}]
82
+ # @return [Hash{String => Array<Pin::Reference::Superclass>}]
78
83
  def superclass_references
79
84
  # @param h [String]
80
85
  # @param k [Array<String>]
@@ -118,27 +123,28 @@ module Solargraph
118
123
  # @param k [String]
119
124
  # @param v [Set<Pin::Base>]
120
125
  set.classify(&:class)
121
- .map { |k, v| pin_class_hash[k].concat v.to_a }
126
+ .map { |k, v| pin_class_hash[k].concat v.to_a }
122
127
  # @param k [String]
123
128
  # @param v [Set<Pin::Namespace>]
124
129
  set.classify(&:namespace)
125
- .map { |k, v| namespace_hash[k].concat v.to_a }
130
+ .map { |k, v| namespace_hash[k].concat v.to_a }
126
131
  # @param k [String]
127
132
  # @param v [Set<Pin::Base>]
128
133
  set.classify(&:path)
129
- .map { |k, v| path_pin_hash[k].concat v.to_a }
134
+ .map { |k, v| path_pin_hash[k].concat v.to_a }
130
135
  @namespaces = path_pin_hash.keys.compact.to_set
131
136
  map_references Pin::Reference::Include, include_references
132
137
  map_references Pin::Reference::Prepend, prepend_references
133
138
  map_references Pin::Reference::Extend, extend_references
134
139
  map_references Pin::Reference::Superclass, superclass_references
135
140
  map_overrides
141
+ pins_by_class(Pin::Reference::TypeAlias).each { |pin| alias_hash[pin.name] = pin.return_type }
136
142
  self
137
143
  end
138
144
 
139
145
  # @generic T
140
146
  # @param klass [Class<generic<T>>]
141
- # @param hash [Hash{String => generic<T>}]
147
+ # @param hash [Hash{String => Array<generic<T>>}]
142
148
  #
143
149
  # @return [void]
144
150
  def map_references klass, hash
@@ -150,26 +156,32 @@ module Solargraph
150
156
 
151
157
  # @return [void]
152
158
  def map_overrides
159
+ # @todo should complain when type for 'ovr' is not provided
153
160
  # @param ovr [Pin::Reference::Override]
154
161
  pins_by_class(Pin::Reference::Override).each do |ovr|
155
162
  logger.debug { "ApiMap::Index#map_overrides: Looking at override #{ovr} for #{ovr.name}" }
156
163
  pins = path_pin_hash[ovr.name]
157
164
  logger.debug { "ApiMap::Index#map_overrides: pins for path=#{ovr.name}: #{pins}" }
158
165
  pins.each do |pin|
159
- new_pin = if pin.path.end_with?('#initialize')
160
- path_pin_hash[pin.path.sub(/#initialize/, '.new')].first
161
- end
166
+ new_pin = (path_pin_hash[pin.path.sub('#initialize', '.new')].first if pin.path.end_with?('#initialize'))
162
167
  (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
168
+ # @sg-ignore Wrong argument type for
169
+ # YARD::Docstring#delete_tags: name expected String,
170
+ # received String, Symbol - delete_tags is ok with a
171
+ # _ToS, but we should fix anyway
163
172
  pin.docstring.delete_tags tag
164
- new_pin.docstring.delete_tags tag if new_pin
173
+ new_pin&.docstring&.delete_tags tag
165
174
  end
166
175
  ovr.tags.each do |tag|
167
176
  pin.docstring.add_tag(tag)
168
177
  redefine_return_type pin, tag
169
- if new_pin
170
- new_pin.docstring.add_tag(tag)
171
- redefine_return_type new_pin, tag
172
- end
178
+ pin.reset_generated!
179
+
180
+ next unless new_pin
181
+
182
+ new_pin.docstring.add_tag(tag)
183
+ redefine_return_type new_pin, tag
184
+ new_pin.reset_generated!
173
185
  end
174
186
  end
175
187
  end
@@ -186,7 +198,6 @@ module Solargraph
186
198
  pin.signatures.each do |sig|
187
199
  sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
188
200
  end
189
- pin.reset_generated!
190
201
  end
191
202
  end
192
203
  end
@@ -3,16 +3,18 @@
3
3
  module Solargraph
4
4
  class ApiMap
5
5
  module SourceToYard
6
-
7
6
  # Get the YARD CodeObject at the specified path.
8
7
  #
8
+ # @sg-ignore Declared return type generic<T>, nil does not match
9
+ # inferred type ::YARD::CodeObjects::Base, nil for
10
+ # Solargraph::ApiMap::SourceToYard#code_object_at
9
11
  # @generic T
10
12
  # @param path [String]
11
13
  # @param klass [Class<generic<T>>]
12
14
  # @return [generic<T>, nil]
13
15
  def code_object_at path, klass = YARD::CodeObjects::Base
14
16
  obj = code_object_map[path]
15
- obj if obj&.is_a?(klass)
17
+ obj if obj.is_a?(klass)
16
18
  end
17
19
 
18
20
  # @return [Array<String>]
@@ -33,16 +35,20 @@ module Solargraph
33
35
  end
34
36
  if pin.type == :class
35
37
  # @param obj [YARD::CodeObjects::RootObject]
36
- code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) { |obj|
38
+ code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path) do |obj|
39
+ # @sg-ignore flow sensitive typing needs to handle attrs
37
40
  next if pin.location.nil? || pin.location.filename.nil?
41
+ # @sg-ignore flow sensitive typing needs to handle attrs
38
42
  obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
39
- }
43
+ end
40
44
  else
41
45
  # @param obj [YARD::CodeObjects::RootObject]
42
- code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) { |obj|
46
+ code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path) do |obj|
47
+ # @sg-ignore flow sensitive typing needs to handle attrs
43
48
  next if pin.location.nil? || pin.location.filename.nil?
49
+ # @sg-ignore flow sensitive typing needs to handle attrs
44
50
  obj.add_file(pin.location.filename, pin.location.range.start.line, !pin.comments.empty?)
45
- }
51
+ end
46
52
  end
47
53
  code_object_map[pin.path].docstring = pin.docstring
48
54
  store.get_includes(pin.path).each do |ref|
@@ -57,7 +63,6 @@ module Solargraph
57
63
  code_object = code_object_map[ref.type.to_s]
58
64
  next unless code_object
59
65
  extend_object.class_mixins.push code_object
60
- # @todo add spec showing why this next line is necessary
61
66
  extend_object.instance_mixins.push code_object
62
67
  end
63
68
  end
@@ -67,14 +72,22 @@ module Solargraph
67
72
  next
68
73
  end
69
74
 
75
+ # @sg-ignore Need to add nil check here
70
76
  # @param obj [YARD::CodeObjects::RootObject]
71
- code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope) { |obj|
77
+ code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(
78
+ code_object_at(pin.namespace, YARD::CodeObjects::NamespaceObject), pin.name, pin.scope
79
+ ) do |obj|
80
+ # @sg-ignore flow sensitive typing needs to handle attrs
72
81
  next if pin.location.nil? || pin.location.filename.nil?
82
+ # @sg-ignore flow sensitive typing needs to handle attrs
73
83
  obj.add_file pin.location.filename, pin.location.range.start.line
74
- }
84
+ end
75
85
  method_object = code_object_at(pin.path, YARD::CodeObjects::MethodObject)
86
+ # @sg-ignore Need to add nil check here
76
87
  method_object.docstring = pin.docstring
88
+ # @sg-ignore Need to add nil check here
77
89
  method_object.visibility = pin.visibility || :public
90
+ # @sg-ignore Need to add nil check here
78
91
  method_object.parameters = pin.parameters.map do |p|
79
92
  [p.full_name, p.asgn_code]
80
93
  end