Skip to content

Let callers choose where a gem yardoc is built - #102

Draft
apiology wants to merge 2 commits into
masterfrom
yardoc-path-as-argument
Draft

apiology wants to merge 2 commits into
masterfrom
yardoc-path-as-argument

Conversation

@apiology

@apiology apiology commented Sep 9, 2026

Copy link
Copy Markdown
Owner

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

Problem: Solargraph::Yardoc can only ever read and write one directory per gem, the one PinCache picks, because every method works the path out from a gemspec instead of being told it. A caller that wants a gem yardoc somewhere else, including the spec suite, has no way to ask for one.

Yardoc.cache([], gemspec)   # builds into PinCache.yardoc_path(gemspec)
Yardoc.cached?(gemspec)     # asks about that same path, and no other
Yardoc.load!(gemspec)       # loads that same path, and no other

That is why spec/yardoc_spec.rb covered a single method: exercising the rest meant writing into the real user cache.

Solution: Each Yardoc method now takes the gem yardoc path as its first argument, and GemPins and Library compute it with PinCache.yardoc_path(gemspec) at the call site.

cache becomes build_docs, cached? becomes docs_built?, and a new build_pins takes over the load-and-map step from GemPins.build_yard_pins. The spec builds into a tmpdir and now covers build_docs, processing? and load!.

Every Yardoc method worked out the gem yardoc directory itself by
calling PinCache.yardoc_path on a gemspec, so the module could only
ever read and write the one location PinCache picks. Callers now
compute that path and pass it in, which lets any caller point Yardoc
at a directory of its own and lets the spec build into a tmpdir
instead of the real user cache.

cache becomes build_docs and no longer returns the path; cached?
becomes docs_built?; processing? and load! take the path instead of a
gemspec. build_pins takes over the load-and-map step from
GemPins.build_yard_pins, which now computes the path once and calls
the path-taking methods.

Extracted from the parked PinCache rewrite so it can land without the
module-to-instance conversion that branch also carries.
apiology added a commit that referenced this pull request Sep 9, 2026
Brings in #102: let callers choose where a gem
yardoc is built, by passing the path into every Yardoc method rather
than deriving it from the gemspec inside.

No conflicts. The two call sites it rewrites sit clear of the regions
the earlier four merges touched: GemPins.build_yard_pins is untouched
by any of them, and its edit to Library#cache_next_gemspec lands about
twenty lines above the retry guard pincache-instance added to the same
method.

Checked the new API took everywhere rather than only where git merged
it. Every Yardoc call site now passes a path -- build_docs and
docs_built? and build_pins in gem_pins.rb, processing? in library.rb,
load! in the mapper spec -- and none of the old gemspec-taking names
survive anywhere in lib or spec. PinCache.yardoc_path, which supplies
that path, is still a class method: pincache-instance moved combined
and RBS collection entries onto the instance and left the yardoc path
where it was.

Full suite: 1685 examples, 0 failures, 68 pending.
A YARD plugin decides what a gem documentation contains, and the caller
now says which ones it wants. The cache did not: yardoc_path named one
plugin and its version as a literal, while yard_gem_path and
combined_path named none, so the three entries a gem needs were shared
by every declared set. Build docs once and Yardoc.build_docs returns
early for the next caller, which then reads pins built under someone
else plugins with no way to ask for its own.

That is the first of the five failures #103 lists:
gem types go stale after a YARD plugin upgrade until you clear the cache
by hand.

Each of the three keys now carries the plugin set, so a workspace is
served what its own conventions declared. Both spellings a caller may
use reach the same key, activesupport-concern and the
yard-activesupport-concern its gem carries, because the command line
passes one and Convention::ActiveSupportConcern the other; a key built
verbatim would give them separate caches for identical documentation.
The plugin version rides along, so an upgrade invalidates. uncache
clears every set for a gem, which is what asking for a gem by name
means.

The spec asks a workspace for a method the activesupport-concern plugin
lifts out of a class_methods block. Declared, the workspace resolves it;
dropped, it must not, and on this branch before the change it did. The
fixture gem exists to carry that method: nothing in the bundle is
written in the ActiveSupport::Concern style, and the plugin changes
nothing without it.

Verified in both directions. With lib reverted the example reports
[1, 1] against an expected [1, 0]. spec/pin/method_spec.rb:552 fails on
this branch either way, an Integer#+ signature count that predates this
change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E8ckZEYYMDXe9eDNnyxaim
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.

1 participant