solargraph 0.54.4 → 0.57.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.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linting.yml +125 -0
  3. data/.github/workflows/plugins.yml +149 -5
  4. data/.github/workflows/rspec.yml +39 -4
  5. data/.github/workflows/typecheck.yml +8 -3
  6. data/.gitignore +7 -0
  7. data/.overcommit.yml +72 -0
  8. data/.rspec +1 -0
  9. data/.rubocop.yml +66 -0
  10. data/.rubocop_todo.yml +2627 -0
  11. data/.yardopts +1 -0
  12. data/CHANGELOG.md +104 -0
  13. data/README.md +20 -6
  14. data/Rakefile +125 -13
  15. data/lib/solargraph/api_map/cache.rb +3 -2
  16. data/lib/solargraph/api_map/constants.rb +218 -0
  17. data/lib/solargraph/api_map/index.rb +44 -42
  18. data/lib/solargraph/api_map/source_to_yard.rb +10 -4
  19. data/lib/solargraph/api_map/store.rb +165 -32
  20. data/lib/solargraph/api_map.rb +319 -243
  21. data/lib/solargraph/bench.rb +18 -1
  22. data/lib/solargraph/complex_type/type_methods.rb +7 -1
  23. data/lib/solargraph/complex_type/unique_type.rb +105 -16
  24. data/lib/solargraph/complex_type.rb +40 -7
  25. data/lib/solargraph/convention/active_support_concern.rb +111 -0
  26. data/lib/solargraph/convention/base.rb +20 -3
  27. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
  28. data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
  29. data/lib/solargraph/convention/data_definition.rb +105 -0
  30. data/lib/solargraph/convention/gemspec.rb +3 -2
  31. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -0
  32. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -0
  33. data/lib/solargraph/convention/struct_definition.rb +164 -0
  34. data/lib/solargraph/convention.rb +35 -4
  35. data/lib/solargraph/diagnostics/rubocop.rb +6 -1
  36. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -1
  37. data/lib/solargraph/doc_map.rb +313 -65
  38. data/lib/solargraph/environ.rb +9 -2
  39. data/lib/solargraph/gem_pins.rb +60 -38
  40. data/lib/solargraph/language_server/host/dispatch.rb +2 -0
  41. data/lib/solargraph/language_server/host/message_worker.rb +13 -7
  42. data/lib/solargraph/language_server/host.rb +14 -3
  43. data/lib/solargraph/language_server/message/base.rb +2 -1
  44. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
  45. data/lib/solargraph/language_server/message/extended/document.rb +5 -2
  46. data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
  47. data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
  48. data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -2
  49. data/lib/solargraph/language_server/message/text_document/type_definition.rb +1 -0
  50. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
  51. data/lib/solargraph/language_server/progress.rb +8 -0
  52. data/lib/solargraph/language_server/request.rb +1 -0
  53. data/lib/solargraph/library.rb +53 -32
  54. data/lib/solargraph/location.rb +23 -0
  55. data/lib/solargraph/logging.rb +12 -2
  56. data/lib/solargraph/page.rb +4 -0
  57. data/lib/solargraph/parser/comment_ripper.rb +20 -7
  58. data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -0
  59. data/lib/solargraph/parser/node_methods.rb +16 -2
  60. data/lib/solargraph/parser/node_processor/base.rb +10 -5
  61. data/lib/solargraph/parser/node_processor.rb +26 -9
  62. data/lib/solargraph/parser/parser_gem/class_methods.rb +17 -15
  63. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
  64. data/lib/solargraph/parser/parser_gem/node_chainer.rb +13 -11
  65. data/lib/solargraph/parser/parser_gem/node_methods.rb +8 -4
  66. data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
  67. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
  68. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +4 -2
  69. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +7 -4
  70. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -1
  71. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
  72. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +6 -3
  73. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +2 -1
  74. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
  75. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -0
  76. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +4 -2
  77. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -1
  78. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +7 -1
  79. data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
  80. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +42 -0
  81. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
  82. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +3 -1
  83. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +4 -3
  84. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +63 -30
  85. data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +3 -1
  86. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
  87. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
  88. data/lib/solargraph/parser/parser_gem/node_processors.rb +14 -0
  89. data/lib/solargraph/parser/region.rb +4 -1
  90. data/lib/solargraph/parser/snippet.rb +2 -0
  91. data/lib/solargraph/parser.rb +1 -0
  92. data/lib/solargraph/pin/base.rb +360 -30
  93. data/lib/solargraph/pin/base_variable.rb +16 -10
  94. data/lib/solargraph/pin/block.rb +2 -0
  95. data/lib/solargraph/pin/breakable.rb +9 -0
  96. data/lib/solargraph/pin/callable.rb +83 -3
  97. data/lib/solargraph/pin/closure.rb +20 -1
  98. data/lib/solargraph/pin/common.rb +10 -1
  99. data/lib/solargraph/pin/constant.rb +2 -0
  100. data/lib/solargraph/pin/delegated_method.rb +21 -1
  101. data/lib/solargraph/pin/documenting.rb +16 -0
  102. data/lib/solargraph/pin/keyword.rb +7 -2
  103. data/lib/solargraph/pin/local_variable.rb +18 -6
  104. data/lib/solargraph/pin/method.rb +175 -46
  105. data/lib/solargraph/pin/method_alias.rb +3 -0
  106. data/lib/solargraph/pin/namespace.rb +17 -9
  107. data/lib/solargraph/pin/parameter.rb +78 -19
  108. data/lib/solargraph/pin/proxy_type.rb +13 -6
  109. data/lib/solargraph/pin/reference/override.rb +24 -6
  110. data/lib/solargraph/pin/reference/require.rb +2 -2
  111. data/lib/solargraph/pin/reference/superclass.rb +5 -0
  112. data/lib/solargraph/pin/reference.rb +26 -0
  113. data/lib/solargraph/pin/search.rb +3 -1
  114. data/lib/solargraph/pin/signature.rb +44 -0
  115. data/lib/solargraph/pin/singleton.rb +1 -1
  116. data/lib/solargraph/pin/symbol.rb +8 -2
  117. data/lib/solargraph/pin/until.rb +18 -0
  118. data/lib/solargraph/pin/while.rb +18 -0
  119. data/lib/solargraph/pin.rb +4 -1
  120. data/lib/solargraph/pin_cache.rb +245 -0
  121. data/lib/solargraph/position.rb +11 -0
  122. data/lib/solargraph/range.rb +10 -0
  123. data/lib/solargraph/rbs_map/conversions.rb +226 -70
  124. data/lib/solargraph/rbs_map/core_fills.rb +32 -16
  125. data/lib/solargraph/rbs_map/core_map.rb +37 -11
  126. data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
  127. data/lib/solargraph/rbs_map.rb +88 -18
  128. data/lib/solargraph/shell.rb +20 -18
  129. data/lib/solargraph/source/chain/array.rb +11 -7
  130. data/lib/solargraph/source/chain/block_symbol.rb +1 -1
  131. data/lib/solargraph/source/chain/block_variable.rb +1 -1
  132. data/lib/solargraph/source/chain/call.rb +53 -23
  133. data/lib/solargraph/source/chain/constant.rb +1 -1
  134. data/lib/solargraph/source/chain/hash.rb +4 -3
  135. data/lib/solargraph/source/chain/head.rb +1 -1
  136. data/lib/solargraph/source/chain/if.rb +1 -1
  137. data/lib/solargraph/source/chain/link.rb +12 -1
  138. data/lib/solargraph/source/chain/literal.rb +22 -2
  139. data/lib/solargraph/source/chain/or.rb +1 -1
  140. data/lib/solargraph/source/chain/z_super.rb +1 -1
  141. data/lib/solargraph/source/chain.rb +84 -47
  142. data/lib/solargraph/source/change.rb +2 -2
  143. data/lib/solargraph/source/cursor.rb +2 -3
  144. data/lib/solargraph/source/source_chainer.rb +3 -3
  145. data/lib/solargraph/source.rb +5 -2
  146. data/lib/solargraph/source_map/clip.rb +4 -2
  147. data/lib/solargraph/source_map/data.rb +4 -0
  148. data/lib/solargraph/source_map/mapper.rb +13 -7
  149. data/lib/solargraph/source_map.rb +21 -31
  150. data/lib/solargraph/type_checker/checks.rb +4 -0
  151. data/lib/solargraph/type_checker/param_def.rb +2 -0
  152. data/lib/solargraph/type_checker/rules.rb +8 -0
  153. data/lib/solargraph/type_checker.rb +208 -128
  154. data/lib/solargraph/version.rb +1 -1
  155. data/lib/solargraph/views/_method.erb +10 -10
  156. data/lib/solargraph/views/_namespace.erb +3 -3
  157. data/lib/solargraph/views/document.erb +10 -10
  158. data/lib/solargraph/workspace/config.rb +1 -3
  159. data/lib/solargraph/workspace/require_paths.rb +98 -0
  160. data/lib/solargraph/workspace.rb +38 -52
  161. data/lib/solargraph/yard_map/helpers.rb +29 -1
  162. data/lib/solargraph/yard_map/mapper/to_constant.rb +7 -5
  163. data/lib/solargraph/yard_map/mapper/to_method.rb +53 -18
  164. data/lib/solargraph/yard_map/mapper/to_namespace.rb +9 -7
  165. data/lib/solargraph/yard_map/mapper.rb +4 -3
  166. data/lib/solargraph/yard_map/to_method.rb +4 -2
  167. data/lib/solargraph/yardoc.rb +22 -10
  168. data/lib/solargraph.rb +34 -1
  169. data/rbs/fills/tuple.rbs +149 -0
  170. data/rbs_collection.yaml +19 -0
  171. data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -0
  172. data/sig/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
  173. data/sig/shims/thor/1.2.0.1/manifest.yaml +7 -0
  174. data/sig/shims/thor/1.2.0.1/thor.rbs +17 -0
  175. data/solargraph.gemspec +15 -4
  176. metadata +157 -15
  177. data/lib/.rubocop.yml +0 -22
  178. data/lib/solargraph/cache.rb +0 -77
data/.yardopts CHANGED
@@ -1,2 +1,3 @@
1
1
  lib/**/*.rb
2
2
  --plugin yard-solargraph
3
+ --plugin activesupport-concern
data/CHANGELOG.md CHANGED
@@ -1,3 +1,107 @@
1
+ ## 0.57.0 - September 16, 2025
2
+ - Support ActiveSupport::Concern pattern for class methods (#948)
3
+ - More CI checks (#996)
4
+ - Linting / type annotation fixes (#999)
5
+ - Avoid overlapping chdir calls in multiple threads (#1007)
6
+ - Fix kwarg generation in ApiMap::SourceToYard (#1003)
7
+ - Enable Steep typechecking of Solargraph code (#1004)
8
+ - Fix convention requires (#1008)
9
+ - Plugin Util: Add Combination Priority (#1010)
10
+ - [regression] Fix crash while typechecking files with Struct use (#1031)
11
+ - Remove yard reference from gemfile (#1033)
12
+ - Allow newer RBS gem versions, exclude incompatible ones (#995)
13
+ - Look for external requires before cataloging bench (#1021)
14
+ - Remove Library#folding_ranges (#904)
15
+ - Complain in strong type-checking if an @sg-ignore line is not needed (#1011)
16
+ - Document a log level env variable (#894)
17
+ - Fix hole in type checking evaluation (#1009)
18
+ - Improve typechecking error message (#1014)
19
+ - Internal strict type-checking fixes (#1013)
20
+ - Reproduce and fix a ||= (or-asgn) evaluation issue (#1017)
21
+ - Define closure for Pin::Symbol, for completeness (#1027)
22
+ - Fix 'all!' config to reporters (#1018)
23
+ - Fix DocMap.all_rbs_collection_gems_in_memory return type (#1037)
24
+ - Fix RuboCop linting errors in regular expressions (#1038)
25
+ - Resolve class aliases via Constant pins (#1029)
26
+ - Speed-up LSP completion response times (#1035)
27
+ - Revert "Resolve class aliases via Constant pins (#1029)" (#1041)
28
+ - Avoid stack errors when resolving method aliases (#1040)
29
+ - [regression] Refine order of object convention method pins (#1036)
30
+ - Fix crash while generating activesupport pins (#1043)
31
+ - Type annotation improvements (#1016)
32
+ - Resolve class aliases via Constant pins (#1048)
33
+ - Understand "Parser::AST::Node < AST::Node" in RBS (#1060)
34
+ - Factor out require_paths logic to its own class (#1062)
35
+ - Fix type errors found in strong typechecking (#1045)
36
+ - Run plugin specs separately for perf insights (#1046)
37
+ - Run specs from solargraph-rails configured against current code in CI (#892)
38
+ - Fix Convention/Plugin pins not being updated on file change (#1028)
39
+ - Fix solargraph-rails check (#1073)
40
+ - Flow sensitive typing handles x.is_a? without an argument (#1070)
41
+ - Refactor reference pin handling (#1058)
42
+
43
+ ## 0.56.2 - July 29, 2025
44
+ - Add support for Ruby Data.define (#970)
45
+ - Ensure that pin locations are always populated (#965)
46
+ - Improve struct support (#992)
47
+ - Include Rakefile, Gemfile, and gemspec files in config by default (#984)
48
+ - Use Open3 to cache gemspecs (#1000)
49
+ - Eager load node processors (#1002)
50
+
51
+ ## 0.56.1 - July 13, 2025
52
+ - Library avoids blocking on pending yardoc caches (#990)
53
+ - DocMap checks for default Gemfile (#989)
54
+ - [Bug fix] Fixed an error in rbs/fills/tuple.rbs (#993)
55
+
56
+ ## 0.56.0 - July 1, 2025
57
+ - [regression] Gem caching perf and logging fixes #983
58
+
59
+ ## 0.55.5 - July 1, 2025
60
+ - Flatten results of DocMap external bundle query (#981)
61
+ - [breaking] Reimplement global conventions (#877)
62
+ - GemPins pin merging improvements (#946)
63
+ - Support class-scoped aliases and attributes from RBS (#952)
64
+ - Restructure ComplexType specs towards YARD doc compliance (#969)
65
+ - Use Prism (#974)
66
+ - Document pages (#977)
67
+ - Enable disabled-but-working specs (#978)
68
+ - Map RBS 'untyped' type (RBS::Types::Bases::Any) to 'undefined' (#979)
69
+ - Re-enable support for .gem_rbs_collection directories (#942)
70
+ - [breaking] Comply with YARD documentation on Hash tag format (#968)
71
+ - Ignore directory paths in Workspace#would_require? (#988)
72
+
73
+ ## 0.55.4 - June 27, 2025
74
+ - Flatten results of DocMap external bundle query (#981)
75
+
76
+ ## 0.55.3 - June 25, 2025
77
+ - Nil guards in flow-sensitive typing (patch release) (#980)
78
+
79
+ ## 0.55.2 - June 21, 2025
80
+ - Require external bundle (#972)
81
+
82
+ ## 0.55.1 - June 8, 2025
83
+ - Fix inline Struct definition (#962)
84
+ - Ensure DocMap requires bundler when loading gemspecs (#963)
85
+ - DelegatedMethod improvements (#953)
86
+
87
+ ## 0.55.0 - June 3, 2025
88
+ - Flow-sensitive typing - automatically downcast from is_a? calls (#856)
89
+ - Tuple enabler: infer literal types and use them for signature selection (#836)
90
+ - Signature selection improvements (#907)
91
+ - Add support for Ruby Structs (#939)
92
+ - [regression] Fix interface change breaking solargraph-rails (#940)
93
+ - [regression] Add back bundler/require support for solargraph-rails (#941)
94
+ - Add specs for initialize capabilities (#955)
95
+ - Create MethodAlias pins from YARD (#945)
96
+ - MessageWorker prioritizes synchronization (#956)
97
+ - initialize/new method pin cleanups (#949)
98
+ - Clip rebinds blocks when cursor is not part of receiver (#958)
99
+
100
+ ## 0.54.5 - May 17, 2025
101
+ - Repair unknown encoding errors (#936, #935)
102
+ - Index arbitrary pinsets (#937)
103
+ - Separate YARD cache from doc map cache (#938)
104
+
1
105
  ## 0.54.4 - May 14, 2025
2
106
  - Delete files from Library hash (#932)
3
107
  - Clip#define returns variable pins (#934, #933)
data/README.md CHANGED
@@ -53,7 +53,7 @@ Solargraph's behavior can be controlled via optional [configuration](https://sol
53
53
 
54
54
  ### Plugins
55
55
 
56
- Solargraph supports [plugins](https://solargraph.org/guides/plugins) that implements 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.
56
+ 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.
57
57
 
58
58
  For better Rails support, please consider using [solargraph-rails](https://github.com/iftheshoefritz/solargraph-rails/)
59
59
 
@@ -63,15 +63,25 @@ The RSpec framework is supported via [solargraph-rspec](https://github.com/lekem
63
63
 
64
64
  **Note: Before version 0.53.0, it was recommended to run `yard gems` periodically or automate it with `yard config` to ensure that Solargraph had access to gem documentation. These steps are no longer necessary. Solargraph maintains its own gem documentation cache independent of the yardocs in your gem installations.**
65
65
 
66
- Solargraph automatically generates code maps from installed gems. You can also manage your cached gem documentation with the `solargraph gems` command.
66
+ When editing code, a `require` call that references a gem will pull the documentation into the code maps and include the gem's API in code completion and intellisense. Solargraph automatically generates code maps from installed gems, based on the YARD or RBS type information inside the gem. You can also eagerly cache gem documentation with the `solargraph gems` command.
67
67
 
68
- When editing code, a `require` call that references a gem will pull the documentation into the code maps and include the gem's API in code completion and intellisense.
68
+ If your project automatically requires bundled gem with the `Bundler.require` statement, Solargraph will add all of the Gemfile's default dependencies to the map.
69
69
 
70
- If your project automatically requires bundled gems (e.g., `require 'bundler/require'`), Solargraph will add all of the Gemfile's default dependencies to the map.
70
+ To ensure you have types for gems which contain neither RBS nor YARD
71
+ information, use
72
+ [gem\_rbs\_collection](https://github.com/ruby/gem_rbs_collection) to
73
+ install a community-supported set of RBS types for various gems:
74
+
75
+ ```sh
76
+ bundle exec rbs collection init
77
+ bundle exec rbs collection install
78
+ ```
79
+
80
+ Once installed, you can also insert your own local overrides and definitions in RBS in a directory configured in the `rbs_collection.yaml` that the above commands create.
71
81
 
72
82
  ### Type Checking
73
83
 
74
- As of version 0.33.0, Solargraph includes a [type checker](https://github.com/castwide/solargraph/issues/192) that uses a combination of YARD tags and code analysis to report missing type definitions. In strict mode, it performs type inference to determine whether the tags match the types it detects from code.
84
+ As of version 0.33.0, Solargraph includes a [type checker](https://github.com/castwide/solargraph/issues/192) that uses a combination of YARD tags and code analysis to report missing type definitions. In strict mode, it performs type inference to determine whether the tags match the types it detects from code. In strong mode it will ask you to clarify your intentions by adding annotations for better validation.
75
85
 
76
86
  ### The Documentation Cache
77
87
 
@@ -91,7 +101,7 @@ Run `bundle install` and optionally use `bundle exec solargraph gems` to generat
91
101
 
92
102
  In order to make sure you're using the correct dependencies, you can start the language server with Bundler. In VS Code, there's a `solargraph.useBundler` option. Other clients will vary, but the command you probably want to run is `bundle exec solargraph socket` or `bundle exec solargraph stdio`.
93
103
 
94
- ### Rubocop Version
104
+ ### RuboCop Version
95
105
 
96
106
  If you have multiple versions of [`rubocop`](https://rubygems.org/gems/rubocop) installed and you would like to choose a version other than the latest to use, this specific version can be configured.
97
107
 
@@ -122,6 +132,10 @@ See [https://solargraph.org/guides](https://solargraph.org/guides) for more tips
122
132
 
123
133
  ### Development
124
134
 
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.
138
+
125
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.
126
140
 
127
141
  ### Sponsorship and Donation
data/Rakefile CHANGED
@@ -1,12 +1,7 @@
1
1
  require 'rake'
2
- require 'rspec/core/rake_task'
3
2
  require 'bundler/gem_tasks'
4
-
5
- begin
6
- require 'rspec/core/rake_task'
7
- RSpec::Core::RakeTask.new(:spec)
8
- rescue LoadError
9
- end
3
+ require 'fileutils'
4
+ require 'open3'
10
5
 
11
6
  desc "Open a Pry session preloaded with this library"
12
7
  task :console do
@@ -14,12 +9,129 @@ task :console do
14
9
  end
15
10
 
16
11
  desc "Run the type checker"
17
- task :typecheck do
18
- sh "bundle exec solargraph typecheck --level typed"
12
+ task typecheck: [:typecheck_typed]
13
+
14
+ desc "Run the type checker at typed level - return code issues provable without annotations being correct"
15
+ task :typecheck_typed do
16
+ sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed"
17
+ end
18
+
19
+ desc "Run the type checker at strict level - report issues using type annotations"
20
+ task :typecheck_strict do
21
+ sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strict"
22
+ end
23
+
24
+ desc "Run the type checker at strong level - enforce that type annotations exist"
25
+ task :typecheck_strong do
26
+ sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strong"
27
+ end
28
+
29
+ desc "Run the type checker at alpha level - run high-false-alarm checks"
30
+ task :typecheck_alpha do
31
+ sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level alpha"
32
+ end
33
+
34
+ desc "Run RSpec tests, starting with the ones that failed last time"
35
+ task spec: %i[spec_failed undercover_no_fail full_spec] do
36
+ undercover
37
+ end
38
+
39
+ desc "Run all RSpec tests"
40
+ task :full_spec do
41
+ warn 'starting spec'
42
+ sh 'TEST_COVERAGE_COMMAND_NAME=full-new bundle exec rspec' # --profile'
43
+ warn 'ending spec'
44
+ # move coverage/full-new to coverage/full on success so that we
45
+ # always have the last successful run's 'coverage info
46
+ FileUtils.rm_rf('coverage/full')
47
+ FileUtils.mv('coverage/full-new', 'coverage/full')
48
+ end
49
+
50
+ # @sg-ignore #undercover return type could not be inferred
51
+ # @return [Process::Status]
52
+ def undercover
53
+ simplecov_collate
54
+ cmd = 'bundle exec undercover ' \
55
+ '--simplecov coverage/combined/coverage.json ' \
56
+ '--exclude-files "Rakefile,spec/*,spec/**/*,lib/solargraph/version.rb" ' \
57
+ '--compare origin/master'
58
+ output, status = Bundler.with_unbundled_env do
59
+ Open3.capture2e(cmd)
60
+ end
61
+ puts output
62
+ $stdout.flush
63
+ status
64
+ rescue StandardError => e
65
+ warn "hit error: #{e.message}"
66
+ warn "Backtrace:\n#{e.backtrace.join("\n")}"
67
+ warn "output: #{output}"
68
+ puts "Flushing"
69
+ $stdout.flush
70
+ raise
71
+ end
72
+
73
+ desc "Check PR coverage"
74
+ task :undercover do
75
+ raise "Undercover failed" unless undercover.success?
76
+ end
77
+
78
+ desc "Branch-focused fast-feedback quality/spec/coverage checks"
79
+ task test: %i[overcommit spec typecheck] do
80
+ # do these in order
81
+ Rake::Task['typecheck_strict'].invoke
82
+ Rake::Task['typecheck_strong'].invoke
83
+ Rake::Task['typecheck_alpha'].invoke
84
+ end
85
+
86
+ desc "Re-run failed specs. Add --fail-fast in your .rspec-local file if desired."
87
+ task :spec_failed do
88
+ # allow user to check out any persistent failures while looking for
89
+ # more in the whole test suite
90
+ sh 'TEST_COVERAGE_COMMAND_NAME=next-failure bundle exec rspec --only-failures || true'
91
+ end
92
+
93
+ desc "Run undercover and show output without failing the task if it fails"
94
+ task :undercover_no_fail do
95
+ undercover
96
+ rescue StandardError
97
+ puts "Undercover failed, but continuing with other tasks."
98
+ end
99
+
100
+ # @return [void]
101
+ def simplecov_collate
102
+ require 'simplecov'
103
+ require 'simplecov-lcov'
104
+ require 'undercover/simplecov_formatter'
105
+
106
+ SimpleCov.collate(Dir["coverage/{next-failure,full,ad-hoc}/.resultset.json"]) do
107
+ cname = 'combined'
108
+ command_name cname
109
+ new_dir = File.join('coverage', cname)
110
+ coverage_dir new_dir
111
+
112
+ formatter \
113
+ SimpleCov::Formatter::MultiFormatter
114
+ .new([
115
+ SimpleCov::Formatter::HTMLFormatter,
116
+ SimpleCov::Formatter::Undercover,
117
+ SimpleCov::Formatter::LcovFormatter
118
+ ])
119
+ SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
120
+ end
121
+ puts "Simplecov collated results into coverage/combined/.resultset.json"
122
+ rescue StandardError => e
123
+ puts "Simplecov collate failed: #{e.message}"
124
+ ensure
125
+ $stdout.flush
126
+ end
127
+
128
+ desc 'Add incremental coverage for rapid iteration with undercover'
129
+ task :simplecov_collate do
130
+ simplecov_collate
19
131
  end
20
132
 
21
- desc "Run all tests"
22
- task :test do
23
- Rake::Task["typecheck"].invoke
24
- Rake::Task["spec"].invoke
133
+ desc "Show quality checks on this development branch so far, including any staged files"
134
+ task :overcommit do
135
+ # OVERCOMMIT_DEBUG=1 will show more detail
136
+ sh 'SOLARGRAPH_ASSERTS=on bundle exec overcommit --run --diff origin/master'
25
137
  end
@@ -4,9 +4,9 @@ module Solargraph
4
4
  class ApiMap
5
5
  class Cache
6
6
  def initialize
7
- # @type [Hash{Array => Array<Pin::Method>}]
7
+ # @type [Hash{String => Array<Pin::Method>}]
8
8
  @methods = {}
9
- # @type [Hash{(String, Array<String>) => Array<Pin::Base>}]
9
+ # @type [Hash{String, Array<String> => Array<Pin::Base>}]
10
10
  @constants = {}
11
11
  # @type [Hash{String => String}]
12
12
  @qualified_namespaces = {}
@@ -101,6 +101,7 @@ module Solargraph
101
101
 
102
102
  private
103
103
 
104
+ # @return [Array<Object>]
104
105
  def all_caches
105
106
  [@methods, @constants, @qualified_namespaces, @receiver_definitions, @clips]
106
107
  end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class ApiMap
5
+ # Methods for handling constants.
6
+ #
7
+ class Constants
8
+ # @param store [Store]
9
+ def initialize store
10
+ @store = store
11
+ end
12
+
13
+ # Resolve a name to a fully qualified namespace or constant.
14
+ #
15
+ # @param name [String]
16
+ # @param gates [Array<Array<String>, String>]
17
+ # @return [String, nil]
18
+ def resolve(name, *gates)
19
+ return store.get_path_pins(name[2..]).first&.path if name.start_with?('::')
20
+
21
+ flat = gates.flatten
22
+ flat.push '' if flat.empty?
23
+ cached_resolve[[name, flat]] || resolve_and_cache(name, flat)
24
+ end
25
+
26
+ # Get a fully qualified namespace from a reference pin.
27
+ #
28
+ # @param pin [Pin::Reference]
29
+ # @return [String, nil]
30
+ def dereference pin
31
+ resolve(pin.name, pin.reference_gates)
32
+ end
33
+
34
+ # Collect a list of all constants defined in the specified gates.
35
+ #
36
+ # @param gates [Array<Array<String>, String>]
37
+ # @return [Array<Pin::Base>]
38
+ def collect(*gates)
39
+ flat = gates.flatten
40
+ cached_collect[flat] || collect_and_cache(flat)
41
+ end
42
+
43
+ # Determine fully qualified tag for a given tag used inside the
44
+ # definition of another tag ("context"). This method will start
45
+ # the search in the specified context until it finds a match for
46
+ # the tag.
47
+ #
48
+ # Does not recurse into qualifying the type parameters, but
49
+ # returns any which were passed in unchanged.
50
+ #
51
+ # @param tag [String, nil] The namespace to
52
+ # match, complete with generic parameters set to appropriate
53
+ # values if available
54
+ # @param context_tag [String] The fully qualified context in which
55
+ # the tag was referenced; start from here to resolve the name.
56
+ # Should not be prefixed with '::'.
57
+ # @return [String, nil] fully qualified tag
58
+ def qualify tag, context_tag = ''
59
+ return tag if ['Boolean', 'self', nil].include?(tag)
60
+
61
+ type = ComplexType.try_parse(tag)
62
+ return unless type.defined?
63
+ return tag if type.literal?
64
+
65
+ context_type = ComplexType.try_parse(context_tag)
66
+ return unless context_type.defined?
67
+
68
+ fqns = qualify_namespace(type.rooted_namespace, context_type.rooted_namespace)
69
+ return unless fqns
70
+
71
+ fqns + type.substring
72
+ end
73
+
74
+ # @return [void]
75
+ def clear
76
+ [cached_collect, cached_resolve].each(&:clear)
77
+ end
78
+
79
+ private
80
+
81
+ # @return [Store]
82
+ attr_reader :store
83
+
84
+ # @param name [String]
85
+ # @param gates [Array<String>]
86
+ # @return [String, nil]
87
+ def resolve_and_cache name, gates
88
+ cached_resolve[[name, gates]] = resolve_uncached(name, gates)
89
+ end
90
+
91
+ # @param name [String]
92
+ # @param gates [Array<String>]
93
+ # @return [String, nil]
94
+ def resolve_uncached name, gates
95
+ parts = name.split('::')
96
+ here = parts.shift
97
+ resolved = simple_resolve(here, gates)
98
+ return resolved if parts.empty? || resolved.nil?
99
+
100
+ final = "#{resolved}::#{parts.join('::')}".sub(/^::/, '')
101
+ final if store.namespace_exists?(final)
102
+ end
103
+
104
+ # @param name [String]
105
+ # @param gates [Array<String>]
106
+ # @return [String, nil]
107
+ def simple_resolve name, gates
108
+ gates.each do |gate|
109
+ here = "#{gate}::#{name}".sub(/^::/, '').sub(/::$/, '')
110
+ return here if store.namespace_exists?(here)
111
+ end
112
+ nil
113
+ end
114
+
115
+ # @param gates [Array<String>]
116
+ # @return [Array<Pin::Base>]
117
+ def collect_and_cache gates
118
+ skip = Set.new
119
+ cached_collect[gates] = gates.flat_map do |gate|
120
+ inner_get_constants(gate, %i[public private], skip)
121
+ end
122
+ end
123
+
124
+ # @return [Hash{Array(Name, Array<String>) => String, nil}]
125
+ def cached_resolve
126
+ @cached_resolve ||= {}
127
+ end
128
+
129
+ # @return [Hash{Array<String> => Array<Pin::Base>}]
130
+ def cached_collect
131
+ @cached_collect ||= {}
132
+ end
133
+
134
+ # Determine fully qualified namespace for a given namespace used
135
+ # inside the definition of another tag ("context"). This method
136
+ # will start the search in the specified context until it finds a
137
+ # match for the namespace.
138
+ #
139
+ # @param namespace [String, nil] The namespace to
140
+ # match
141
+ # @param context_namespace [String] The context namespace in which the
142
+ # tag was referenced; start from here to resolve the name
143
+ # @return [String, nil] fully qualified namespace
144
+ def qualify_namespace namespace, context_namespace = ''
145
+ if namespace.start_with?('::')
146
+ inner_qualify(namespace[2..], '', Set.new)
147
+ else
148
+ inner_qualify(namespace, context_namespace, Set.new)
149
+ end
150
+ end
151
+
152
+ # @param name [String] Namespace to fully qualify
153
+ # @param root [String] The context to search
154
+ # @param skip [Set<String>] Contexts already searched
155
+ # @return [String, nil] Fully qualified ("rooted") namespace
156
+ def inner_qualify name, root, skip
157
+ return name if name == ComplexType::GENERIC_TAG_NAME
158
+ return nil if name.nil?
159
+ return nil if skip.include?(root)
160
+ skip.add root
161
+ possibles = []
162
+ if name == ''
163
+ return '' if root == ''
164
+
165
+ inner_qualify(root, '', skip)
166
+ else
167
+ return name if root == '' && store.namespace_exists?(name)
168
+ roots = root.to_s.split('::')
169
+ while roots.length.positive?
170
+ fqns = "#{roots.join('::')}::#{name}"
171
+ return fqns if store.namespace_exists?(fqns)
172
+ incs = store.get_includes(roots.join('::'))
173
+ incs.each do |inc|
174
+ foundinc = inner_qualify(name, inc.parametrized_tag.to_s, skip)
175
+ possibles.push foundinc unless foundinc.nil?
176
+ end
177
+ roots.pop
178
+ end
179
+ if possibles.empty?
180
+ incs = store.get_includes('')
181
+ incs.each do |inc|
182
+ foundinc = inner_qualify(name, inc.parametrized_tag.to_s, skip)
183
+ possibles.push foundinc unless foundinc.nil?
184
+ end
185
+ end
186
+ return name if store.namespace_exists?(name)
187
+ possibles.last
188
+ end
189
+ end
190
+
191
+ # @param fqns [String]
192
+ # @param visibility [Array<Symbol>]
193
+ # @param skip [Set<String>]
194
+ # @return [Array<Pin::Base>]
195
+ def inner_get_constants fqns, visibility, skip
196
+ return [] if fqns.nil? || skip.include?(fqns)
197
+ skip.add fqns
198
+ result = []
199
+
200
+ store.get_prepends(fqns).each do |pre|
201
+ pre_fqns = resolve(pre.name, pre.closure.gates - skip.to_a)
202
+ result.concat inner_get_constants(pre_fqns, [:public], skip)
203
+ end
204
+ result.concat(store.get_constants(fqns, visibility).sort { |a, b| a.name <=> b.name })
205
+ store.get_includes(fqns).each do |pin|
206
+ inc_fqns = resolve(pin.name, pin.closure.gates - skip.to_a)
207
+ result.concat inner_get_constants(inc_fqns, [:public], skip)
208
+ end
209
+ sc_ref = store.get_superclass(fqns)
210
+ if sc_ref
211
+ fqsc = dereference(sc_ref)
212
+ result.concat inner_get_constants(fqsc, [:public], skip) unless %w[Object BasicObject].include?(fqsc)
213
+ end
214
+ result
215
+ end
216
+ end
217
+ end
218
+ end