Skip to content

Give gem caches the workspace plugins - #149

Draft
apiology wants to merge 95 commits into
gem-without-yardfrom
load-plugins-when-caching-gems
Draft

apiology wants to merge 95 commits into
gem-without-yardfrom
load-plugins-when-caching-gems

Conversation

@apiology

@apiology apiology commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem:

In the language server, cached gem pins never include a plugin's additions:

# .solargraph.yml
plugins:
  - solargraph-rails

# the server caches each gem in a subprocess that never requires the plugin:
$ solargraph cache responders

An in-process typecheck sees the plugin's pins but the editor doesn't, and because the cache key ignores plugins, adding or upgrading one keeps serving the old pins.

Solution:

solargraph cache and uncache require the plugins configured for --directory, and CacheDir.gem_dir includes each loaded plugin's name and version, so pins built with different plugin sets never share a directory.

With no plugin loaded, gem_dir is unchanged. Stacked on castwide#1378.

castwide and others added 4 commits October 5, 2026 20:13
…ide#1273)

* Fix order-dependent generic resolution for same-class union receivers

When a receivers declared type unions multiple instantiations of the
same generic class (e.g. Box<Integer>, Box<String>), Chain::Call#resolve
looked up a method pin per union member, then deduped the results by
path alone. Since both members resolve to the same method path
(Box#get) but had already been resolved to different, correct return
types for their own context, the dedup silently discarded every member
but the first - so the inferred type depended on declaration order
instead of being a real union.

Fixes castwide#1272

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoPQ2EZUCHYMwDr13PBsc4

* Trigger CI

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoPQ2EZUCHYMwDr13PBsc4

* Address review comments on generic union dedup fix

Drop the bare issue-reference comment above a non-pending spec, and
replace the block-local @PARAM tag with a proper @sg-ignore: the
receiver's element type resolves fine for Array#first but isn't
propagated into uniq's block parameter, a real Solargraph inference
gap rather than something a YARD tag should paper over.

* Key call dedup on rooted_tags, not first member

ComplexType has no #tag of its own, so return_type.tag fell through
method_missing to @Items.first.tag. On a union return type the key
therefore saw only the first member: "Integer, String" and
"Integer, Float" both keyed as "Integer", so two pins whose resolved
return types genuinely differ were collapsed into one.

rooted_tags maps every member and keeps the namespace rooting, so the
key reflects the whole resolved type.

Also drops the parenthetical from the ignore marker and cuts the
comment to three lines, per review.

Typecheck is unchanged by this: 591 problems before and after in the
same worktree, zero added and zero removed.

* Lead dedup comment with what the line does

Reorder so the comment states the action before the rationale, per
review.

Also replaces the ignore marker's reason. The previous wording blamed
uniq, but the block param is untyped because Array#flatten is declared
in core RBS as returning a bare Array: arr.flatten infers to ::Array
where arr.compact infers to ::Array<::String>. With no element type on
the receiver there is nothing for uniq's block param to bind to.

No open PR covers this. The nearest two address different shapes:
castwide#1326 is a method-level generic bound by an argument
alongside a block, and castwide#1274 is a generic return
type lost when the declaring method takes a block. Left as prose rather
than citing a URL that does not match.

* Cut dedup comment to why it is needed

Three lines became one. The removed clause, "keying on path alone
drops all but the first", described what the code used to do rather
than what it does, so it belongs here rather than in the source.

That prior version keyed the uniq on path only, which collapsed the
per-member pins whose resolved return types differ, and this branch
changed the key to path plus return type. A reader coming to the
method cold does not need that history; they need to know duplicates
are possible at all, which the surviving line states.

* Catalogue the flatten ignore string in rules.rb

Trim the marker to its reason and register that reason in the
catalogued list, so it groups with the other tracked strings on a
census instead of reading as one-off wording.

It joins "flow sensitive typing could handle", which is where the
comparable core-typing gaps already sit -- "Need better handling of
#compact" and "Should better support meaning of '&' in RBS" are the
same shape -- and that group's total goes from 96 to 97.

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Gem pins are mapped from gem source and serialized, so a plugin's
conventions shape what lands in the gem cache. The language server
caches gems by running `solargraph cache` in a subprocess, which never
loaded the workspace's plugins, so the cache it wrote could differ from
the one an in-process typecheck builds.

`cache` and `uncache` now require the plugins configured for the
directory, through a Workspace::Config#require_plugins that Workspace
also delegates to. Each loaded plugin and its gem version are recorded
in CacheDir, and gem_dir includes them, so loading or upgrading a
plugin rebuilds the gem cache instead of reusing pins made without it.

The @sg-ignore in CacheDir.add_plugin records a typecheck defect:
Hash#each_value.find types the block parameter as the value type
unioned with the hash itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhUSLUimEYJyCZv8NdQGKb
castwide and others added 2 commits October 12, 2026 23:13
* Map gems without YARD

* Isolate YardMap::Mapper specs

* Adjust LocalVariable spec to find correct block pin

* Gem path source cache

* External selects RBS collection gems from current loaded gems (castwide#1379)

* RbsCollection

* Gem caching in External spec

* RbsCollection specs

* Stale code

* Linting

* Add nil guard to TextDocument::Hover#process

* Generate pins for overloads declared in macros

* Memory cache for RBS collection pins

* External combines RBS collection pins

* Collection::Gem process macros

* Linting

* SourceMap::Mapper allows `@method` directive syntax

* Allow successive pin combinations

* Typo

* Map qualified mixins and class_attribute accessors

The no-YARD gem mapper lost pins that YARD used to produce:

* Mixins called on an explicit receiver. Only receiverless include/extend/prepend
  were mapped, so ActiveSupport's `Object.prepend(self)` (which is how
  `require_dependency` reaches every class) and
  `Integer.prepend ActiveSupport::NumericWithFormat` made all the methods those
  modules add to core classes invisible.

* ActiveSupport's `class_attribute`, whose accessors are created at run time.
  Rails documents them with `## :singleton-method:` comment directives that YARD
  turned into methods. `process_class_attribute` generates the same accessors and
  honors instance_accessor/instance_reader/instance_writer/instance_predicate.

Fixes several solargraph-rails definitions (require_dependency on ActiveJob,
Rails::Application, ActionDispatch::Routing::Mapper and ActiveRecord; ActionController
callbacks; ActiveRecord::Base.enumerate_columns_in_select_statements;
ActiveRecord::Base#signed_id_verifier_secret; Integer#to_formatted_s).

* Find RBS collection signatures by closest version and load stdlib sets

External now selects collection entries for the gems it loads, but the lookup
expected a collection directory whose version matches the installed gem. Two
kinds of signature sets were silently dropped:

* Gems whose signatures are published under a different version than the gem.
  gem_rbs_collection ships `actionpack/6.0` for every Rails 6 and 7 release and
  `devise/4.9` for Devise 4 and 5, so actionpack 7.0.10 and devise 5.0.4 got no
  signatures at all (this is what hid the ActionController callback DSL).
  RbsCollection#best_key now falls back to the closest version the collection
  provides for that gem, preferring the highest one that does not exceed it.

* Stdlib entries in the lockfile (`date/0`, `json/0`, ...). They are not
  associated with a gem in the bundle, and `rbs collection install` resolves
  them to the signatures that ship with the rbs gem instead of copying them into
  the collection directory, so they can never be matched by a gem lookup.
  RbsCollection#stdlib_names exposes them and External loads them with
  Collection::Stdlib, which restores e.g. `Date#xmlschema -> String`.

Also guards External#rbs_collection_lockfile against a nil directory, which
previously short-circuited before the collection was touched.

* Remove Collection::Rbs

* Remove autoload

---------

Co-authored-by: Dexter Deezen <dexter@castwide.com>
@apiology apiology changed the title Give gem caches the workspace's plugins Give gem caches the workspace plugins Oct 16, 2026
apiology and others added 12 commits October 17, 2026 07:20
…al (castwide#1269)

* Fix false positive: Struct.new(keyword_init: true) members are optional

Solargraph generated a :kwarg (required) parameter pin for every member of
a Struct.new(..., keyword_init: true) class, so typecheck --level strong
reported "Missing keyword argument" when a call site omitted one. At
runtime, keyword_init Struct members default to nil like ordinary Struct
members, so they should be :kwoptarg (optional) instead.

Fixes castwide#1268

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TqwAY5yf6K1ZQdYoSZDkmy

* Drop unneeded @type cast in struct optional-kwarg spec

Removing it does not change strong typecheck output (531 problems,
same set, before and after) -- inference already resolves this
correctly, so no @sg-ignore is needed either.

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…astwide#1309)

reduce_to_value_nodes flattened an :or node into both operand nodes, so
each was typed independently and unioned -- bypassing Chain::Or, which
already strips nil from the union when the right operand is not
nullable. A bare 'x || fallback' method tail inferred correctly, but the
same expression as an if/else branch value leaked the left operand's nil
into the method's inferred return type.

Keep the :or node whole so it routes through Chain::Or like any other
or-expression.
* Map Forwardable delegations to DelegatedMethod pins

def_delegator and def_delegators define real methods whose behavior comes
from the method they forward to, but Solargraph mapped neither, so every
call to a delegated method was unresolved and any method returning one
could not infer its return type.

SendNode now maps both into Pin::DelegatedMethod - the pin class added in
602 and until now only constructed by external plugins - which resolves
the receiver chain and the forwarded method lazily, so the delegated
method reports the forwarded method's parameters, return type and
signatures. Instance-variable, class-variable and method receivers are
supported, as is def_delegator's optional alias argument. Expansion only
fires in a namespace that extends Forwardable; SingleForwardable's
class-scope delegation is not covered.

Method pins synthesized from a class-body statement cover that
statement's range but have no body of their own, so treating them as
closures makes the declaring statement resolve in instance scope.
_locate_pin already skipped attribute pins for this reason; aliases and
delegations need the same treatment. Without it, `alias_method :a, :b` in
a class body reports "Unresolved call to alias_method" at strong level on
master today, and def_delegators would have reported the same.

Specs catalog a Bench with external_requires so Forwardable's own pins
are loaded, which TypeChecker.load_string does not do; that lets each
delegation spec assert an empty problem list.

Full suite: 1541 examples, 0 failures, 59 pending.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H1FEjW6nMpZrWPmeWX9miT

SKIP=Solargraph,RuboCop: both hooks fail on problems present on master
for the touched files (verified by restoring each file to master and
re-running); the strong-typecheck message set is identical before and
after this change (42 problems, same messages).

* Take the @!method tag for an unresolvable delegation

A project using Forwardable gets a "Missing @return tag" at strong level for
every def_delegators name whose receiver cannot be resolved statically. On
plate-spinner that is 42 errors across 15 files, on lines that already carry
an @!method/@return directive supplying the type - the directive was written
there precisely because the delegation target is unreachable.

castwide#1311 mints a Pin::DelegatedMethod per def_delegators name.
Where the receiver reaches a method_missing dispatcher, or any object whose
declaration cannot be followed, that pin's return type stays undefined.

The report comes from TypeChecker#method_tag_problems, which iterates
source_map.pins_by_class(Pin::Method) - the raw per-file pin set, not the
ApiMap's combined view. It therefore sees the undefined DelegatedMethod pin
and never the documented Pin::Method sharing its path.
method_return_type_problems_for then special-cases exactly one pin class,
`return [] if pin.is_a?(Pin::MethodAlias)`, with no Pin::DelegatedMethod case.

Add that case, guarded on resolvable?, which Pin::DelegatedMethod already
provides. A delegation that cannot resolve its receiver has no declaration
site a @return tag could be written at - the type belongs to the target
method, elsewhere - so it is skipped for the same reason MethodAlias is
skipped on the line above. Delegations that do resolve are untouched and
still enforce their target's type at call sites. Where nothing declares a
type, the receiver's own missing tag is still reported, so the root is named
once rather than once per delegated name.

Negative result, recorded so it is not retried: Store#combine_duplicate_method_pins
was tried first, preferring a documented Pin::Method over a same-path
DelegatedMethod. It works - the group collapses and get_methods returns the
typed pin - and it has no effect on this diagnostic, because
method_tag_problems never consults the combined view. That approach was
abandoned, not left unfinished.

Measured on plate-spinner whole-project at strong: 54 problems in 23 of 501
files before, 12 in 10 after, with all 42 Missing @return cleared. The
remaining 12 are @sg-ignore markers other merged fixes made unneeded.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H1FEjW6nMpZrWPmeWX9miT

* Use the RBS pins already built for an uncached default gem

DocMap#deserialize_combined_pin_cache builds an RbsMap to get a cache
key, then looks for RBS pins in a cache file rather than in the map it
just built. For a require resolving to a Ruby default gem such as
forwardable, nothing writes that file during cataloging, so the pins
are discarded and the gem reads as undocumented -
Forwardable#def_delegators is unresolvable - until `solargraph gems`
runs and writes a combined cache.

Where the standard library is what describes the gem, the map in hand
holds those pins, so return them when neither cache file is there.

They are not written to combined_pins_in_memory. That hash is
process-wide and keyed only by gem name and version, so a provisional
set stored there would go on being served for the life of the process,
including after the build that supersedes it. deserialize_rbs_collection_cache
still records the gemspec in @uncached_rbs_collection_gemspecs, so the
deferred build is unchanged.

* Address review: rename body_less?/forwardable_extended?, trim comment

Rename body_less? to has_body? (inverted) across Method,
DelegatedMethod, and MethodAlias, and forwardable_extended? to
extends_forwardable?, per review comments. Cut filler wording
from the def_delegators comment in method_return_type_problems_for.
Record the literal typecheck errors on the two is_a?-narrowing
@sg-ignore markers in send_node.rb.

* Add coverage for class-variable Forwardable delegation

delegation_receiver_chain has an @@ branch (ClassVariable) with no
test; only the @ivar and bare-method-name branches were covered.

* Address review comments on PR 1311

Trim four docstrings/comments to the 1-3 line budget, note that
extends_forwardable? matches by name only (fooled by a same-named
local module), and rename has_body? to body? throughout, dropping
the now-unneeded Naming/PredicatePrefix rubocop disable/enable pairs.

* Use catalogued sg-ignore reason in symbol_word

The two @sg-ignore markers in
Parser::ParserGem::NodeProcessors::SendNode#symbol_word carried
multi-line free-text reasoning. The repo convention is a single line
drawn from the catalogued list in TypeChecker::Rules.

Both suppress a gap already catalogued there: an is_a? guard that
fails to narrow the receiver, so a later call on it is reported
unresolved. node_methods.rb already uses that same entry 15 times for
the identical shape, guarding .type and .children calls on a
::Parser::AST::Node.

Bump that entry and its group total by two to cover these.

* Cache the required gem in the delegation spec helper

type_checker_with_gems built a bare ApiMap and cataloged a Bench, which
loads a gem's pins only if some earlier run already wrote a combined
cache entry for it. Against a cold cache the delegation examples saw
Unresolved constant Forwardable and Unresolved call to def_delegators.

Cache and re-catalog the way ApiMap.load_with_cache does. The ApiMap
knows only the requires the example names, so this builds forwardable
and nothing else.

That removes this branch's need for the DocMap fallback it had been
carrying. The fallback addresses a general default-gem gap rather than
anything about delegation, so doc_map.rb, rbs_map.rb and
rbs_map/stdlib_map.rb are untouched here again.

* Drop spec call to ApiMap method removed by castwide#1369

Merging master into this branch produced a semantic conflict git could
not see. Master's castwide#1369 (External gem dependency management, 24d9ec6)
deleted ApiMap#cache_all_for_doc_map! and DocMap#cache_all!, while this
branch added the only surviving caller -- the type_checker_with_gems
spec helper -- in a different file. Both sides merged cleanly and left
a call to a method that no longer exists.

Every example using the helper raised:

  NoMethodError: undefined method `cache_all_for_doc_map!' for
  Solargraph::ApiMap:Solargraph::ApiMap

That failed all nine delegation examples, and with them `rake spec`,
which is the single unmasked step shared by the undercover, regression,
rails and plugin rspec jobs, and by every rspec matrix cell.

The removed pair was cache-then-re-catalog, and it protected against a
cold gem cache: External#process_gem adds a cacheable gem to
unloaded_gems and loads no pins when Collection::Gem.cached? is false,
so the pins only appear on a later catalog once something has built the
cache. That protection is not needed here. Every one of these examples
requires only 'forwardable', and External#load_requires routes a path
satisfying RbsMap::Stdlib.has? through Collection::Stdlib.load, which
loads unconditionally and never reaches process_gem. A single catalog
is therefore sufficient for this helper however cold the gem cache is,
and the comment is reworded to claim only that.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* Resolve an RBS `self` return type per union arm

A method whose RBS return type is `self` must resolve to the arm of a
union receiver that supplied the pin, not to the whole union.

    # @PARAM check_name [String, Symbol]
    # @return [Symbol]
    def to_sym_union(check_name)
      check_name.to_sym    # inferred ::Symbol, ::String
    end

`String#to_sym` is `-> ::Symbol` and `Symbol#to_sym` is `-> self`.
Chain::Call#resolve split the binder into arms only to collect method
pins, then flattened them and called #inferred_pins once with a name_pin
still bound to the whole union, so `self` expanded to `String, Symbol`.

Resolve each arm's pins against that arm, then dedup on both path and
resolved return type so a shared self-returning pin (e.g. Kernel#itself)
still contributes every arm.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H1FEjW6nMpZrWPmeWX9miT

* Cover the YARD `@return [self]` path with specs

The per-arm resolution added in the previous commit is not RBS-specific:
`self_to_type` runs on the pin's parsed `ComplexType`, so a YARD
`@return [self]` tag reaches the same code as an RBS `-> self`. On a
pure-YARD file with no RBS involved, `solargraph typecheck --level
strong` reports on master:

    Declared return type ::Symbol, ::Beta does not match inferred type
    ::Symbol, ::Alpha, ::Beta for #probe_union

and reports no problems here.

Add two specs pinning that path: `@return [self]` on one arm of a
two-class union, and `@return [Array<self>]` shared by both arms, where
`self` inside a generic distributes to `Array<Alpha>, Array<Beta>`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CXmnT5gSB1PheL9UbiGEVA

* Drop an `@sg-ignore` that per-arm `self` resolution makes unneeded

`Diagnostics::TypeCheck#diagnose` computes `level` as `String, Symbol`
(`args.reverse.find { ... } || :normal`) and passes `level.to_sym` to
`TypeChecker.new`. `String#to_sym` is `-> ::Symbol` and `Symbol#to_sym`
is `-> self`, so while `self` resolved against the whole union the call
inferred `Symbol, String` and the result needed suppressing.

Resolving each arm's pin against that arm alone narrows it to `Symbol`.
The comment now suppresses nothing, and `--level strong` reports it as
an unneeded `@sg-ignore`. Removing it brings this branch to 529
problems in 90 of 250 files, matching master at 8fda633.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CXmnT5gSB1PheL9UbiGEVA

* Carry the per-arm self binder on the name_pin

Chain::Call#inferred_pins took a separate self_binder parameter for
resolving self on a union receiver, but only two of its three
name_pin.binder reads were switched to use it. The Class#new special
case still read name_pin.binder directly, so it saw the whole union
instead of the arm being resolved - the resolution of a Class#new
call on a bare Class arm could pick up a type from an unrelated
Class<X> arm elsewhere in the same union, and the result depended on
which arm was listed first.

Pass a name_pin wrapped in a ProxyType whose binder is the current
arm instead of a separate parameter. Every name_pin.binder read
inside inferred_pins - including the Class#new case - then sees only
that arm, with no per-callsite parameter to keep in sync. The
wrapper keeps the context, closure, and gates of the original
name_pin unchanged; only the binder differs, matching the
working_pin construction Chain#define already uses between links.

Pin::Base#binder cannot be overridden on a copy of name_pin
directly: Pin::Namespace#binder ignores the @binder ivar and always
returns full_context, Pin::InstanceVariable#binder delegates to
closure.binder, and Pin::Block#binder prefers @Rebind when set. None
of these respect a plain dup with @binder reassigned. A fresh
ProxyType sidesteps all three, since its own binder implementation
carries none of those overrides.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012wZ4e1Y1TmTJhbfjSnL9iM

* Trim union-arm resolution comments to one line

Vince flagged four comments in the RBS self-union PR review as
over the 1-line budget. Condense each to a single line without
losing the why.

* Trim the new call_spec comments to one line

The union-arm examples each carried a two-to-five line comment above
the expectation. Each is now one line stating why the expected tag is
what it is, and the comment on the arm-order example is gone
entirely: it restated the example name rather than adding a reason.

Comment-only; the six blocks are the only lines touched.

* Replace the arm coinage with existing type terms

"Arm" was introduced by this branch and appeared nowhere else in lib or
spec. It also flattened two different things: what #each_unique_type
yields, and what a union is made of. Resolve now says "unique type",
which is what the iterator actually hands back whatever kind the binder
is, and the specs say "union member", since they are specifically about
unions.

The loop never asked what kind the binder was: #each_unique_type is
implemented per kind, so ComplexType walks its items and UniqueType
yields itself, and a single-type binder degenerates to one pass. What
is union-shaped is the composition at the end, and the comment there
now says so instead of leaving it implied.

The @PARAM on #inferred_pins described what this branch changed about
its callers rather than the contract it enforces, so it is now one line
stating only that.

No behavior change: typecheck reports 530 problems before and after,
identical apart from the elapsed-time line, and call_spec still runs 38
examples with 0 failures.

* Guard self narrowing in union return types

Call#resolve dedups per-member inferred pins on
[path, return_type.rooted_tags]. ComplexType has no #tag of its own:
TypeMethods#tag arrives through method_missing, which forwards to
@Items.first, so #tag names only a union's first member and collapses
two distinct unions that happen to share one.

Where a single inherited pin serves several union members and its
declared return is a union with self in a non-first position, each
member must contribute its own self. Keyed on #tag the later members
are dropped silently: Base#pick declared [String, self] over an
[Alpha, Beta] binder yields ::String, ::Alpha rather than
::String, ::Alpha, ::Beta.

The full suite passed under both keys before this spec, so nothing
would have caught a revert of the dedup key.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011YRhTKhBfJqqfV1eN9vbbb

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
…astwide#1316)

RBS attaches %a{implicitly-returns-nil} to an individual overload.
method_def_to_sigs read it from decl.overloads.first and then applied that
one boolean to every overload of the method and to every block return type.

For Array#max, rbs 4.1.3 annotates only the zero-argument overloads:

  def max: %a{implicitly-returns-nil} () -> E
         | %a{implicitly-returns-nil} () { (E a, E b) -> _CompareToZero } -> E
         | %a{implicitly-returns-nil} %a{warning: ...} ()
             { (E a, E b) -> _CompareToZero? } -> E
         | (::int count) -> ::Array[E]
         | (::int count) { (E a, E b) -> _CompareToZero } -> ::Array[E]
         | %a{warning: ...} (::int count)
             { (E a, E b) -> _CompareToZero? } -> ::Array[E]

Solargraph produced ::Array[E], nil for the (count) overloads, so this
failed --level strong:

  # @return [Array<String>]
  def probe
    a = ['x', 'y']
    a.max(1)
  end

  probe.rb:2: Declared return type ::Array<::String> does not match
  inferred type ::Array, nil for #probe

The block return type is a separate matter: the annotation describes what
the method returns when it finds no value, not what the block itself may
return. A block whose return type is nullable says so in RBS with `?`, as
the third and sixth Array#max overloads do.


Claude-Session: https://claude.ai/code/session_01CXmnT5gSB1PheL9UbiGEVA

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
`bundle exec rbs validate` was masked with `continue-on-error: true`
in 09be4a6 (castwide#1200) along with seven other steps,
marked "expect to revert in 0.60". 0.60.0 through 0.60.3 have shipped.

The step passes on every run sampled: the master push at 8fda633
and five recent pull-request runs. Nothing is being suppressed, so
the flag only hides the verdict of a check that already reports
accurately.

The other steps from that commit still exit non-zero and are left
alone.


Claude-Session: https://claude.ai/code/session_01CXmnT5gSB1PheL9UbiGEVA

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
…e#1306)

* Index `X = Class.new(Super)` constant assignments as classes

Gems commonly build classes with an anonymous-class assignment instead of
a `class` keyword, e.g. Asana's error hierarchy:

    module Vendor
      Specific = Class.new(StandardError) do
        # @return [Integer]
        def retry_after
          5
        end
      end
    end

`ParserGem::NodeProcessors::CasgnNode` mapped that `casgn` to an untyped
`Pin::Constant`, and the methods in the block landed on the enclosing
namespace, so `Vendor::Specific#retry_after` did not resolve:
`Unresolved call to retry_after on Vendor::Specific` at level strong.

Adds `Convention::ClassDefinition`, following the existing
`Convention::StructDefinition` / `Convention::DataDefinition` pattern: a
`casgn` node processor that recognizes `Class.new(...)` (with or without
a block), pushes a `Pin::Namespace` named after the constant, pushes a
`Pin::Reference::Superclass` when the argument is a constant, and
processes the block body with that namespace as the closure.

The processor is registered for `:casgn` after the Struct and Data
processors -- which keep winning for `Struct.new` / `Data.define` -- and
before `CasgnNode`, which still handles every other constant assignment
because the new processor returns true on non-match.

Fixes castwide#1303

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MEDQFCJ2M7gaYkUQVpiQzn

* Add coverage for namespace-qualified Class.new assignment

class_name has an explicit-namespace branch (Foo::Bar = Class.new(...))
with no test; only the unqualified-constant branch was covered.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* Map gems without YARD

* Isolate YardMap::Mapper specs

* Adjust LocalVariable spec to find correct block pin

* Gem path source cache

* External selects RBS collection gems from current loaded gems (castwide#1379)

* RbsCollection

* Gem caching in External spec

* RbsCollection specs

* Stale code

* Linting

* Add nil guard to TextDocument::Hover#process

* Generate pins for overloads declared in macros

* Memory cache for RBS collection pins

* External combines RBS collection pins

* Collection::Gem process macros

* Linting

* SourceMap::Mapper allows `@method` directive syntax

* Allow successive pin combinations

* Typo

* Map qualified mixins and class_attribute accessors

The no-YARD gem mapper lost pins that YARD used to produce:

* Mixins called on an explicit receiver. Only receiverless include/extend/prepend
  were mapped, so ActiveSupport's `Object.prepend(self)` (which is how
  `require_dependency` reaches every class) and
  `Integer.prepend ActiveSupport::NumericWithFormat` made all the methods those
  modules add to core classes invisible.

* ActiveSupport's `class_attribute`, whose accessors are created at run time.
  Rails documents them with `## :singleton-method:` comment directives that YARD
  turned into methods. `process_class_attribute` generates the same accessors and
  honors instance_accessor/instance_reader/instance_writer/instance_predicate.

Fixes several solargraph-rails definitions (require_dependency on ActiveJob,
Rails::Application, ActionDispatch::Routing::Mapper and ActiveRecord; ActionController
callbacks; ActiveRecord::Base.enumerate_columns_in_select_statements;
ActiveRecord::Base#signed_id_verifier_secret; Integer#to_formatted_s).

* Find RBS collection signatures by closest version and load stdlib sets

External now selects collection entries for the gems it loads, but the lookup
expected a collection directory whose version matches the installed gem. Two
kinds of signature sets were silently dropped:

* Gems whose signatures are published under a different version than the gem.
  gem_rbs_collection ships `actionpack/6.0` for every Rails 6 and 7 release and
  `devise/4.9` for Devise 4 and 5, so actionpack 7.0.10 and devise 5.0.4 got no
  signatures at all (this is what hid the ActionController callback DSL).
  RbsCollection#best_key now falls back to the closest version the collection
  provides for that gem, preferring the highest one that does not exceed it.

* Stdlib entries in the lockfile (`date/0`, `json/0`, ...). They are not
  associated with a gem in the bundle, and `rbs collection install` resolves
  them to the signatures that ship with the rbs gem instead of copying them into
  the collection directory, so they can never be matched by a gem lookup.
  RbsCollection#stdlib_names exposes them and External loads them with
  Collection::Stdlib, which restores e.g. `Date#xmlschema -> String`.

Also guards External#rbs_collection_lockfile against a nil directory, which
previously short-circuited before the collection was touched.

* External combines RBS collection pins immediately after gem load

* Stale code

* External loads stdlib dependencies from gems

* Skip spec

* Remove Collection::Rbs

* Array order discrepancy

* Rescue FileNotFoundError for source maps not in workspace

---------

Co-authored-by: Dexter Deezen <dexter@castwide.com>
* Build rugged on ubuntu-latest runners again

GitHub moved ubuntu-latest to Ubuntu 26.04 on 2026-10-19, and every
job that bundles this repo's Gemfile failed installing rugged (needed
by undercover). rugged links its vendored libgit2 with the output of
`pkg-config --libs --static`, and 26.04's libcrypto.pc adds
-l:libjitterentropy.a to that, which libssl-dev does not install:

    ld.bfd: cannot find -l:libjitterentropy.a: No such file or directory

Installing libjitterentropy3-dev provides the archive; rugged 1.9.6
then builds and loads on 26.04.

ruby/setup-ruby has no Ruby 3.1 build for 26.04 (3.1 does not compile
with GCC 15, ruby/setup-ruby#922), so the 3.1 rspec entry stays on
ubuntu-24.04 while 3.1 is the gemspec's minimum.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AbUPEHCkoQLiHDUweLhQSX

* Install libjitterentropy only where libcrypto needs it

GitHub is moving ubuntu-latest to 26.04 gradually through 2026-11-19,
and castwide/solargraph jobs still get 24.04, where apt has no
libjitterentropy3-dev and the step failed with "Unable to locate
package". Install it only when libcrypto.pc lists jitterentropy, which
also covers the Ruby 3.1 job on 24.04 without a matrix condition.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AbUPEHCkoQLiHDUweLhQSX

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
@apiology
apiology force-pushed the load-plugins-when-caching-gems branch from fd049d2 to 2a0c289 Compare October 21, 2026 16:35
apiology and others added 5 commits October 21, 2026 14:16
A plugin was recorded in the gem cache key only when the workspace
config required it. A process that requires the plugin directly, such
as a plugin spec suite using a workspace without config, mapped gems
with the plugin loaded but read and wrote the plain gems directory,
so it missed caches built by `solargraph gems` with the plugin
configured.

Record the gem that defines each registered convention, and key
config-required plugins by gem name so both paths give the same key.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
Keep the natural Hash iteration and mark the Solargraph gap: the
each_value block param is typed as the Hash pair, not the value.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
The parent keys gem_dir on the plugins it has loaded, while
`solargraph cache` re-read the --directory config. When the two sets
differ (a workspace built with another config, a plugin loaded by
plain require, or several workspaces in one process), the subprocess
writes its pins to a directory the parent never reads, and
Library#cache_next_gemspec re-caches the gem forever.

Record what to require for each plugin and pass that list with
--plugins, so the subprocess loads the same set and writes to the
same gem_dir.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
Undercover flagged the block in Shell#require_plugins that requires
each plugin named by --plugins: the only spec passed an empty string,
so the require, CacheDir.add_plugin and LoadError branches never ran.
Add specs for a loadable plugin and a missing one, and clear the
plugin from CacheDir.plugin_requires after each example.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
Specs that build a workspace at the repo root load the plugins in its
.solargraph.yml, as the plugin CI jobs configure, and require_plugins
then records them with CacheDir.add_plugin. That switched
CacheDir.gem_dir to a cold plugin-keyed directory for the rest of the
spec process. Save, clear and restore CacheDir.plugins and
plugin_requires around every example, which also makes the per-spec
CacheDir cleanup in shell_spec and config_spec redundant.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
apiology and others added 30 commits November 4, 2026 21:02
* Update to rdoc ~> 8.1

* Update to rdoc >= 7.2

* Update to rdoc >= 7.2
Master's library spec now has its own #cache_next_gemspec group,
cache_next_gemspec no longer checks Yardoc.processing?, and
unloaded_gems is a Set. Give the plugin example its own group name,
drop the unused stub and return a Set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
The language server passes the plugins its workspace loaded with
--plugins. A plugin the subprocess could not load was only warned
about and left out of the gem cache key, so the subprocess cached
the gem where the server never reads it. Exit with an error instead.
Plugins read from .solargraph.yml still only warn, as the workspace
does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
When the cache subprocess succeeds but its gem cache key differs
from the workspace's, the gem stays uncached and the server ran the
same command again without end. Record it as a cache error, naming
the directory it expected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
$/solargraph/documentGems ran the gems command with no --directory or
--plugins, so it keyed the gem cache on the server's working directory
instead of each workspace. Run it once per workspace with the plugins
that workspace loaded, as the background gem caching does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
Cache a gem with a fixture plugin whose convention adds a pin to every
mapped file, then read the cache for that plugin set: the pin is
there, and absent from the cache built without the plugin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
castwide#1400, merged in from master, stops flagging
argument forwarding, so the castwide#1108 sg-ignores on
the Collection::Gem.load and uncache calls report as unneeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
The merge of load-plugins-when-caching-gems took the plain names,
undoing its rename. Requiring plugins is still a side effect, so use
require_plugins! again for Workspace, Workspace::Config (instance and
class method) and the Shell helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
What .solargraph.yml lists under plugins was called paths and
plugin_paths. Call it plugins: the require_plugins! parameter and
Workspace#plugins, and document that each entry is a require path,
usually the plugin gem's name. The hash of loaded plugin gem names
and versions that keys the gem cache, formerly Workspace#plugins,
becomes plugin_versions in Workspace, External, Collection::Gem,
CacheDir.gem_dir and Shell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
The plugin_versions YARD defined the term by itself. Say what the
hash holds: Solargraph plugin gem name to version, nil when the
plugin was not loaded from a gem, with the full definition on
Workspace#plugin_versions. Rename DocumentGems#commands to
commands_by_workspace and document that it returns one argv per
workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
The require was left behind when s.date was removed in 0.59.0. Loading
the gemspec from the Gemfile activates the newest installed date gem
before Bundler.setup, so bundle exec fails with "You have already
activated date 3.6.0, but your Gemfile requires date 3.5.1" whenever
the lockfile pins an older date.
rbs-inline accepts `# @RBS () -> T` as well as `#: () -> T` for a
method type, and a YARD macro that expands to `@!method $1` with an
`@rbs` line already carries that line into the method pin's comments.
Only `#:` lines were read, so those methods had no return type.

Other `@rbs` forms (`@rbs x: Integer`, `@rbs return: T`) are not method
types and are still ignored, so they cannot break a `#:` signature on
the same method.
* Declare array literal types Solargraph can't infer

Solargraph does not yet infer element types of array literals, so
calls on their elements were unresolved and needed sg-ignores.
Assign each literal to a local with an @type tag instead, and drop
the sg-ignores this makes unneeded.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguFV8m5C72EvjeEFx96

* Declare the files array in Library#references_from

Its elements were untyped, so every call on the references found
through them went unresolved.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguFV8m5C72EvjeEFx96

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…twide#1467)

* Match calls against overloads an RBS reopen adds to

An RBS `def -: (BigDecimal) -> BigDecimal | ...` adds overloads to
the core Integer#- declaration, but Chain::Call#resolve only took the
first pin in the method stack. With the bigdecimal RBS loaded,
`n - 1` on an Integer therefore inferred BigDecimal and reported
"Wrong argument type for Integer#-".

Record RBS's overloading flag on method pins. When the first pin in
the stack is overloading, match the call against the signatures of
every overloading declaration of that method plus those of the first
declaration it reopens. The stack can hold the same declaration more
than once (a gem's sig and its stdlib copy) and not always in load
order, so collect by path rather than walking adjacent pins. A
declaration without `...` still replaces the earlier one.

* Merge RBS overloads regardless of method stack order

CI put core's Integer#- ahead of the declaration overloading it, so
checking only the first pin for the overloading flag missed it. Look
for overloading RBS declarations among every same-path RBS pin in the
stack instead. Drop duplicate signatures, which a gem's sig and its
stdlib copy both declare.

The replace-semantics spec asserted which of two non-overloading
declarations wins, which depends on stack order; assert only that
their overloads are not combined.
A Workspace with no directory has no workspace config of its own to
name plugins (where an empty directory loads no .solargraph.yml, its
plugin_versions are empty), so its ApiMap read the plain gems cache
directory even when the process had loaded a plugin by require. The
solargraph gems command, run where .solargraph.yml lists that plugin,
writes to the plugin-keyed directory, so solargraph-rspec specs found
no cached gems and lost RSpec completions.

Such a workspace now also keys on the gems that define the registered
conventions (Convention.plugin_versions), which matches the key
Config.require_plugins! gives the same plugin gem. Workspaces with a
directory still key only on their configured plugins.
* Parse Gemfile.lock in Repo#build_from_directory

Replace the subprocess that executed Bundler.definition with direct
parsing of Gemfile.lock via Bundler::LockfileParser. Locked specs are
resolved against gems installed in the bundle path (if configured) or
the system gems, with support for path and git sources. Gemfile.lock
does not record bundle groups, so direct dependencies are treated as
members of the :default group.

* Gemfile.lock in fixture

* Gemspec development dependency spec

* External spec should not delete lockfiles in fixtures

* Linting

* Repo falls back to available system gem

* Cache all bundled gems

* Use bundler definition if loaded

* Test solargraph-rspec with solargraph bundle

* SOLARGRAPH_WITH_BUNDLER env variable

* Move env variable in solargraph-rspec job

* RSpec job uses bundle exec for solargraph bundle

* Call Repo#use_bundler?

* Update Gemfile.lock in spec fixture

* Update lockfiles in fixtures

* Keep fixture lockfiles updated

* Linting

* Repo rescues missing specs

* Install spec fixture bundles in rspec job

* Update spec fixture bundles in spec_helper

* Fix broken step

---------

Co-authored-by: Dexter Deezen <dexter@castwide.com>
CI runs the suite with solargraph-rspec loaded, so a configless
workspace also keys on it. Check only that the probe plugin is in the
key.
castwide master added solargraph bundle, which caches every bundled gem
but read and wrote the plain gems directory. A workspace whose
.solargraph.yml lists plugins reads the plugin-keyed directory, so
gems cached by solargraph bundle looked missing there, as in the
solargraph-rspec plugin specs. Pass the plugins it requires to
Collection::Gem.cached? and .load, as the cache command does.
Check that solargraph bundle prints and caches a bundled gem that is
not cached yet, in the plugin-keyed gem cache directory.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguFV8m5C72EvjeEFx96
* Parse Gemfile.lock in Repo#build_from_directory

Replace the subprocess that executed Bundler.definition with direct
parsing of Gemfile.lock via Bundler::LockfileParser. Locked specs are
resolved against gems installed in the bundle path (if configured) or
the system gems, with support for path and git sources. Gemfile.lock
does not record bundle groups, so direct dependencies are treated as
members of the :default group.

* Gemfile.lock in fixture

* Gemspec development dependency spec

* External spec should not delete lockfiles in fixtures

* Linting

* Repo falls back to available system gem

* Cache all bundled gems

* Use bundler definition if loaded

* Test solargraph-rspec with solargraph bundle

* SOLARGRAPH_WITH_BUNDLER env variable

* Move env variable in solargraph-rspec job

* RSpec job uses bundle exec for solargraph bundle

* Call Repo#use_bundler?

* Parse gemspecs statically

* Update Gemfile.lock in spec fixture

* Update lockfiles in fixtures

* Keep fixture lockfiles updated

* Linting

* Linting

* Repo rescues missing specs

* Install spec fixture bundles in rspec job

* Update spec fixture bundles in spec_helper

* Fix broken step

* Parse gemspecs statically instead of loading them (castwide#1501)

* Parse gemspecs statically

* Linting

---------

Co-authored-by: Dexter Deezen <dexter@castwide.com>
YARD has no @!domain directive registered, so its parser drops the tag
before Solargraph sees it: DomainDirective never ran, and
Namespace#domains, Store#domains and the ApiMap loop over them only ever
saw empty arrays. Remove them and the @!domain entry in the mapper
regexp.

Also remove YardMap::Cache, which nothing references, and
External#rbs_collection_paths and #rbs_collection_config_path, which
have no callers and would raise NoMethodError on
read_rbs_collection_paths if called.

Conventions still contribute domains through Environ; that path is
unchanged.

Split out of castwide#1245.
Master removed External#rbs_collection_paths and
#rbs_collection_config_path (unused), so the specs this branch added
for the config path call a method that no longer exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants