rigortype 0.1.5 → 0.1.6

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -50
  3. data/lib/rigor/analysis/buffer_binding.rb +36 -0
  4. data/lib/rigor/analysis/check_rules.rb +11 -1
  5. data/lib/rigor/analysis/dependency_source_inference/index.rb +14 -1
  6. data/lib/rigor/analysis/dependency_source_inference/return_type_heuristic.rb +105 -0
  7. data/lib/rigor/analysis/dependency_source_inference/walker.rb +32 -12
  8. data/lib/rigor/analysis/project_scan.rb +39 -0
  9. data/lib/rigor/analysis/runner.rb +309 -22
  10. data/lib/rigor/analysis/worker_session.rb +14 -2
  11. data/lib/rigor/builtins/hkt_builtins.rb +342 -0
  12. data/lib/rigor/builtins/static_return_refinements.rb +120 -0
  13. data/lib/rigor/cache/store.rb +33 -3
  14. data/lib/rigor/cli/lsp_command.rb +129 -0
  15. data/lib/rigor/cli/type_of_command.rb +44 -5
  16. data/lib/rigor/cli.rb +74 -12
  17. data/lib/rigor/configuration.rb +38 -2
  18. data/lib/rigor/environment/hkt_registry_holder.rb +33 -0
  19. data/lib/rigor/environment/rbs_coverage_report.rb +1 -1
  20. data/lib/rigor/environment/rbs_loader.rb +45 -2
  21. data/lib/rigor/environment/reporters.rb +40 -0
  22. data/lib/rigor/environment.rb +106 -9
  23. data/lib/rigor/inference/acceptance.rb +48 -3
  24. data/lib/rigor/inference/expression_typer.rb +47 -0
  25. data/lib/rigor/inference/hkt_body.rb +171 -0
  26. data/lib/rigor/inference/hkt_body_parser.rb +363 -0
  27. data/lib/rigor/inference/hkt_reducer.rb +256 -0
  28. data/lib/rigor/inference/hkt_registry.rb +223 -0
  29. data/lib/rigor/inference/method_dispatcher/overload_selector.rb +125 -30
  30. data/lib/rigor/inference/method_dispatcher/receiver_affinity.rb +87 -0
  31. data/lib/rigor/inference/method_dispatcher.rb +154 -3
  32. data/lib/rigor/inference/project_patched_methods.rb +70 -0
  33. data/lib/rigor/inference/project_patched_scanner.rb +210 -0
  34. data/lib/rigor/inference/scope_indexer.rb +156 -12
  35. data/lib/rigor/inference/statement_evaluator.rb +106 -6
  36. data/lib/rigor/inference/synthetic_method_scanner.rb +94 -16
  37. data/lib/rigor/language_server/buffer_table.rb +63 -0
  38. data/lib/rigor/language_server/completion_provider.rb +438 -0
  39. data/lib/rigor/language_server/debouncer.rb +86 -0
  40. data/lib/rigor/language_server/diagnostic_publisher.rb +167 -0
  41. data/lib/rigor/language_server/document_symbol_provider.rb +142 -0
  42. data/lib/rigor/language_server/folding_range_provider.rb +75 -0
  43. data/lib/rigor/language_server/hover_provider.rb +74 -0
  44. data/lib/rigor/language_server/hover_renderer.rb +312 -0
  45. data/lib/rigor/language_server/loop.rb +71 -0
  46. data/lib/rigor/language_server/project_context.rb +145 -0
  47. data/lib/rigor/language_server/selection_range_provider.rb +93 -0
  48. data/lib/rigor/language_server/server.rb +384 -0
  49. data/lib/rigor/language_server/signature_help_provider.rb +249 -0
  50. data/lib/rigor/language_server/synchronized_writer.rb +28 -0
  51. data/lib/rigor/language_server/uri.rb +40 -0
  52. data/lib/rigor/language_server.rb +29 -0
  53. data/lib/rigor/plugin/base.rb +63 -0
  54. data/lib/rigor/plugin/macro/heredoc_template.rb +125 -11
  55. data/lib/rigor/plugin/manifest.rb +54 -7
  56. data/lib/rigor/plugin/registry.rb +19 -0
  57. data/lib/rigor/rbs_extended/hkt_directives.rb +326 -0
  58. data/lib/rigor/rbs_extended.rb +82 -2
  59. data/lib/rigor/sig_gen/generator.rb +12 -3
  60. data/lib/rigor/type/app.rb +107 -0
  61. data/lib/rigor/type.rb +1 -0
  62. data/lib/rigor/version.rb +1 -1
  63. data/sig/rigor/environment.rbs +8 -4
  64. data/sig/rigor/inference.rbs +2 -0
  65. data/sig/rigor.rbs +3 -1
  66. metadata +54 -1
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../trinary"
4
+
5
+ module Rigor
6
+ module Type
7
+ # A defunctionalised higher-kinded type application — the abstract
8
+ # "apply type-constructor `uri` to argument list `args`" carrier.
9
+ #
10
+ # `uri` is a namespaced `Symbol` of the form `:author::name`
11
+ # (e.g. `:"json::value"`, `:"dry_monads::result"`); the `::`
12
+ # namespace separator is mandatory per ADR-20 WD1 to prevent
13
+ # cross-plugin tag collisions.
14
+ #
15
+ # `args` is an ordered, frozen `Array` of `Rigor::Type` values
16
+ # carrying the application's argument list. At least one argument
17
+ # is required; arity-zero "HKT" forms are not modelled by this
18
+ # carrier (use a plain type alias instead).
19
+ #
20
+ # `bound` is a `Rigor::Type` representing the value Rigor MUST
21
+ # erase to when this `App` cannot be reduced — registered at
22
+ # `%a{rigor:v1:hkt_register}` time, defaulting to
23
+ # `Rigor::Type::Dynamic[Rigor::Type::Top]` per ADR-20 D5 / WD2. It
24
+ # also drives the lattice probes (`top` / `bot` / `dynamic`) and
25
+ # the acceptance fallback while no reduction is wired (Slice 1).
26
+ #
27
+ # Slice 1 ships the carrier as **opaque**: every operation
28
+ # delegates to `bound` since no reduction surface exists yet. Slice
29
+ # 2 introduces the conditional / indexed-access evaluator that
30
+ # reduces `App` to its registered body before delegating; the
31
+ # carrier shape stays identical.
32
+ #
33
+ # Display form per ADR-20 OQ5: bare RBS-style `uri[arg1, arg2]`,
34
+ # not the wrapped `App[uri, [arg1, arg2]]` faithful form. Two
35
+ # `App` values are structurally equal iff their `uri`, `args`,
36
+ # AND `bound` match.
37
+ #
38
+ # See docs/adr/20-lightweight-hkt.md.
39
+ class App
40
+ URI_SEPARATOR = "::"
41
+
42
+ attr_reader :uri, :args, :bound
43
+
44
+ def initialize(uri, args, bound:)
45
+ raise ArgumentError, "uri must be a Symbol, got #{uri.class}" unless uri.is_a?(Symbol)
46
+ unless uri.to_s.include?(URI_SEPARATOR)
47
+ raise ArgumentError,
48
+ "uri must be namespaced as `:author#{URI_SEPARATOR}name` per ADR-20 WD1, got #{uri.inspect}"
49
+ end
50
+ raise ArgumentError, "args must be an Array, got #{args.class}" unless args.is_a?(Array)
51
+ raise ArgumentError, "args must be non-empty (use a plain type alias for arity-0 forms)" if args.empty?
52
+ raise ArgumentError, "bound must be a Rigor type, got #{bound.class}" if bound.nil?
53
+
54
+ @uri = uri
55
+ @args = args.dup.freeze
56
+ @bound = bound
57
+ freeze
58
+ end
59
+
60
+ def describe(verbosity = :short)
61
+ rendered = args.map { |t| t.describe(verbosity) }.join(", ")
62
+ "#{uri}[#{rendered}]"
63
+ end
64
+
65
+ def erase_to_rbs
66
+ bound.erase_to_rbs
67
+ end
68
+
69
+ def top
70
+ bound.top
71
+ end
72
+
73
+ def bot
74
+ bound.bot
75
+ end
76
+
77
+ def dynamic
78
+ bound.dynamic
79
+ end
80
+
81
+ def accepts(other, mode: :gradual)
82
+ Inference::Acceptance.accepts(bound, other, mode: mode)
83
+ end
84
+
85
+ def ==(other)
86
+ other.is_a?(App) && uri == other.uri && args == other.args && bound == other.bound
87
+ end
88
+ alias eql? ==
89
+
90
+ def hash
91
+ [App, uri, args, bound].hash
92
+ end
93
+
94
+ def inspect
95
+ "#<Rigor::Type::App #{describe(:short)} (bound=#{bound.describe(:short)})>"
96
+ end
97
+
98
+ # ADR-20 Slice 2a — reduce this application against a
99
+ # registry. Returns the reducer's output (`bound` when
100
+ # reduction is blocked or fuel exhausts).
101
+ def reduce(registry, fuel: nil)
102
+ fuel ||= Inference::HktReducer::DEFAULT_FUEL
103
+ registry.reduce(self, fuel: fuel)
104
+ end
105
+ end
106
+ end
107
+ end
data/lib/rigor/type.rb CHANGED
@@ -23,6 +23,7 @@ require_relative "type/union"
23
23
  require_relative "type/difference"
24
24
  require_relative "type/refined"
25
25
  require_relative "type/intersection"
26
+ require_relative "type/app"
26
27
  require_relative "type/bound_method"
27
28
  require_relative "type/accepts_result"
28
29
  require_relative "type/combinator"
data/lib/rigor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rigor
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
@@ -8,15 +8,19 @@ module Rigor
8
8
  attr_reader rbs_loader: RbsLoader?
9
9
  attr_reader plugin_registry: untyped?
10
10
  attr_reader dependency_source_index: untyped?
11
- attr_reader rbs_extended_reporter: untyped?
12
- attr_reader boundary_cross_reporter: untyped?
11
+ attr_reader reporters: untyped
13
12
  attr_reader name_scope: untyped?
14
13
  attr_reader synthetic_method_index: untyped?
14
+ attr_reader project_patched_methods: untyped?
15
+ attr_reader hkt_registry: untyped?
15
16
 
16
17
  def self.default: () -> Environment
17
- def self.for_project: (?root: String, ?libraries: Array[String], ?signature_paths: Array[String | _ToPath]?, ?cache_store: untyped?, ?plugin_registry: untyped?, ?dependency_source_index: untyped?, ?rbs_extended_reporter: untyped?, ?boundary_cross_reporter: untyped?, ?bundler_bundle_path: String?, ?bundler_auto_detect: bool, ?synthetic_method_index: untyped?) -> Environment
18
+ def self.for_project: (?root: String, ?libraries: Array[String], ?signature_paths: Array[String | _ToPath]?, ?cache_store: untyped?, ?plugin_registry: untyped?, ?dependency_source_index: untyped?, ?rbs_extended_reporter: untyped?, ?boundary_cross_reporter: untyped?, ?bundler_bundle_path: String?, ?bundler_auto_detect: bool, ?synthetic_method_index: untyped?, ?project_patched_methods: untyped?) -> Environment
18
19
 
19
- def initialize: (?class_registry: ClassRegistry, ?rbs_loader: RbsLoader?, ?plugin_registry: untyped?, ?dependency_source_index: untyped?, ?rbs_extended_reporter: untyped?, ?boundary_cross_reporter: untyped?, ?synthetic_method_index: untyped?) -> void
20
+ def initialize: (?class_registry: ClassRegistry, ?rbs_loader: RbsLoader?, ?plugin_registry: untyped?, ?dependency_source_index: untyped?, ?rbs_extended_reporter: untyped?, ?boundary_cross_reporter: untyped?, ?synthetic_method_index: untyped?, ?project_patched_methods: untyped?) -> void
21
+ def rbs_extended_reporter: () -> untyped?
22
+ def boundary_cross_reporter: () -> untyped?
23
+ def attach_reporters!: (rbs_extended_reporter: untyped?, boundary_cross_reporter: untyped?) -> nil
20
24
  def nominal_for_name: (String | Symbol name) -> Type::Nominal?
21
25
  def singleton_for_name: (String | Symbol name) -> Type::Singleton?
22
26
  def constant_for_name: (String | Symbol name) -> Type::t?
@@ -134,6 +134,8 @@ module Rigor
134
134
  def self?.index: (untyped root, default_scope: Scope) -> Hash[untyped, Scope]
135
135
  def self?.build_declaration_overrides: (untyped root) -> Hash[untyped, Type::t]
136
136
  def self?.record_declarations: (untyped node, Array[String] qualified_prefix, Hash[untyped, Type::t] identity_table, Hash[String, Type::t] discovered) -> void
137
+ def self?.discovered_classes_for_paths: (Array[String] paths, ?buffer: untyped) -> Hash[String, Type::t]
138
+ def self?.collect_class_decls: (untyped node, Array[String] qualified_prefix, Hash[String, Type::t] accumulator) -> void
137
139
  def self?.qualified_name_for: (untyped constant_path_node) -> String?
138
140
  def self?.render_constant_path: (untyped node) -> String
139
141
  def self?.propagate: (untyped node, Hash[untyped, Scope] table, Scope parent_scope) -> void
data/sig/rigor.rbs CHANGED
@@ -104,8 +104,10 @@ module Rigor
104
104
  # otherwise raises `RBS::UnknownTypeName` for the named type.
105
105
  attr_reader cache_store: untyped
106
106
  attr_reader plugin_registry: untyped
107
- def initialize: (configuration: Configuration, ?explain: bool, ?cache_store: untyped, ?plugin_requirer: untyped, ?workers: Integer, ?collect_stats: bool) -> void
107
+ attr_reader buffer: untyped
108
+ def initialize: (configuration: Configuration, ?explain: bool, ?cache_store: untyped, ?plugin_requirer: untyped, ?workers: Integer, ?collect_stats: bool, ?buffer: untyped, ?prebuilt: untyped, ?environment: untyped) -> void
108
109
  def run: (?Array[String] paths) -> Result
110
+ def prepare_project_scan: (?paths: Array[String]) -> untyped
109
111
  end
110
112
  end
111
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigortype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rigor contributors
@@ -9,6 +9,26 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-01 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: language_server-protocol
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '3.17'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '3.17'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '4.0'
12
32
  - !ruby/object:Gem::Dependency
13
33
  name: prism
14
34
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +223,7 @@ files:
203
223
  - data/builtins/ruby_core/time.yml
204
224
  - exe/rigor
205
225
  - lib/rigor.rb
226
+ - lib/rigor/analysis/buffer_binding.rb
206
227
  - lib/rigor/analysis/check_rules.rb
207
228
  - lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb
208
229
  - lib/rigor/analysis/check_rules/dead_assignment_collector.rb
@@ -212,9 +233,11 @@ files:
212
233
  - lib/rigor/analysis/dependency_source_inference/builder.rb
213
234
  - lib/rigor/analysis/dependency_source_inference/gem_resolver.rb
214
235
  - lib/rigor/analysis/dependency_source_inference/index.rb
236
+ - lib/rigor/analysis/dependency_source_inference/return_type_heuristic.rb
215
237
  - lib/rigor/analysis/dependency_source_inference/walker.rb
216
238
  - lib/rigor/analysis/diagnostic.rb
217
239
  - lib/rigor/analysis/fact_store.rb
240
+ - lib/rigor/analysis/project_scan.rb
218
241
  - lib/rigor/analysis/result.rb
219
242
  - lib/rigor/analysis/rule_catalog.rb
220
243
  - lib/rigor/analysis/run_stats.rb
@@ -222,8 +245,10 @@ files:
222
245
  - lib/rigor/analysis/worker_session.rb
223
246
  - lib/rigor/ast.rb
224
247
  - lib/rigor/ast/type_node.rb
248
+ - lib/rigor/builtins/hkt_builtins.rb
225
249
  - lib/rigor/builtins/imported_refinements.rb
226
250
  - lib/rigor/builtins/regex_refinement.rb
251
+ - lib/rigor/builtins/static_return_refinements.rb
227
252
  - lib/rigor/cache/descriptor.rb
228
253
  - lib/rigor/cache/rbs_class_ancestor_table.rb
229
254
  - lib/rigor/cache/rbs_class_type_param_names.rb
@@ -237,6 +262,7 @@ files:
237
262
  - lib/rigor/cli.rb
238
263
  - lib/rigor/cli/diff_command.rb
239
264
  - lib/rigor/cli/explain_command.rb
265
+ - lib/rigor/cli/lsp_command.rb
240
266
  - lib/rigor/cli/sig_gen_command.rb
241
267
  - lib/rigor/cli/type_of_command.rb
242
268
  - lib/rigor/cli/type_of_renderer.rb
@@ -249,12 +275,14 @@ files:
249
275
  - lib/rigor/environment.rb
250
276
  - lib/rigor/environment/bundle_sig_discovery.rb
251
277
  - lib/rigor/environment/class_registry.rb
278
+ - lib/rigor/environment/hkt_registry_holder.rb
252
279
  - lib/rigor/environment/lockfile_resolver.rb
253
280
  - lib/rigor/environment/rbs_collection_discovery.rb
254
281
  - lib/rigor/environment/rbs_coverage_report.rb
255
282
  - lib/rigor/environment/rbs_hierarchy.rb
256
283
  - lib/rigor/environment/rbs_loader.rb
257
284
  - lib/rigor/environment/reflection.rb
285
+ - lib/rigor/environment/reporters.rb
258
286
  - lib/rigor/flow_contribution.rb
259
287
  - lib/rigor/flow_contribution/conflict.rb
260
288
  - lib/rigor/flow_contribution/element.rb
@@ -288,6 +316,10 @@ files:
288
316
  - lib/rigor/inference/expression_typer.rb
289
317
  - lib/rigor/inference/fallback.rb
290
318
  - lib/rigor/inference/fallback_tracer.rb
319
+ - lib/rigor/inference/hkt_body.rb
320
+ - lib/rigor/inference/hkt_body_parser.rb
321
+ - lib/rigor/inference/hkt_reducer.rb
322
+ - lib/rigor/inference/hkt_registry.rb
291
323
  - lib/rigor/inference/macro_block_self_type.rb
292
324
  - lib/rigor/inference/method_dispatcher.rb
293
325
  - lib/rigor/inference/method_dispatcher/block_folding.rb
@@ -299,16 +331,35 @@ files:
299
331
  - lib/rigor/inference/method_dispatcher/method_folding.rb
300
332
  - lib/rigor/inference/method_dispatcher/overload_selector.rb
301
333
  - lib/rigor/inference/method_dispatcher/rbs_dispatch.rb
334
+ - lib/rigor/inference/method_dispatcher/receiver_affinity.rb
302
335
  - lib/rigor/inference/method_dispatcher/shape_dispatch.rb
303
336
  - lib/rigor/inference/method_parameter_binder.rb
304
337
  - lib/rigor/inference/multi_target_binder.rb
305
338
  - lib/rigor/inference/narrowing.rb
339
+ - lib/rigor/inference/project_patched_methods.rb
340
+ - lib/rigor/inference/project_patched_scanner.rb
306
341
  - lib/rigor/inference/rbs_type_translator.rb
307
342
  - lib/rigor/inference/scope_indexer.rb
308
343
  - lib/rigor/inference/statement_evaluator.rb
309
344
  - lib/rigor/inference/synthetic_method.rb
310
345
  - lib/rigor/inference/synthetic_method_index.rb
311
346
  - lib/rigor/inference/synthetic_method_scanner.rb
347
+ - lib/rigor/language_server.rb
348
+ - lib/rigor/language_server/buffer_table.rb
349
+ - lib/rigor/language_server/completion_provider.rb
350
+ - lib/rigor/language_server/debouncer.rb
351
+ - lib/rigor/language_server/diagnostic_publisher.rb
352
+ - lib/rigor/language_server/document_symbol_provider.rb
353
+ - lib/rigor/language_server/folding_range_provider.rb
354
+ - lib/rigor/language_server/hover_provider.rb
355
+ - lib/rigor/language_server/hover_renderer.rb
356
+ - lib/rigor/language_server/loop.rb
357
+ - lib/rigor/language_server/project_context.rb
358
+ - lib/rigor/language_server/selection_range_provider.rb
359
+ - lib/rigor/language_server/server.rb
360
+ - lib/rigor/language_server/signature_help_provider.rb
361
+ - lib/rigor/language_server/synchronized_writer.rb
362
+ - lib/rigor/language_server/uri.rb
312
363
  - lib/rigor/plugin.rb
313
364
  - lib/rigor/plugin/access_denied_error.rb
314
365
  - lib/rigor/plugin/base.rb
@@ -328,6 +379,7 @@ files:
328
379
  - lib/rigor/plugin/trust_policy.rb
329
380
  - lib/rigor/plugin/type_node_resolver.rb
330
381
  - lib/rigor/rbs_extended.rb
382
+ - lib/rigor/rbs_extended/hkt_directives.rb
331
383
  - lib/rigor/rbs_extended/reporter.rb
332
384
  - lib/rigor/reflection.rb
333
385
  - lib/rigor/scope.rb
@@ -350,6 +402,7 @@ files:
350
402
  - lib/rigor/trinary.rb
351
403
  - lib/rigor/type.rb
352
404
  - lib/rigor/type/accepts_result.rb
405
+ - lib/rigor/type/app.rb
353
406
  - lib/rigor/type/bot.rb
354
407
  - lib/rigor/type/bound_method.rb
355
408
  - lib/rigor/type/combinator.rb