Strip 'file ' prefix from all filenames in RdocToYard #585
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #473 (at least for me, see extended notes below).
The core issue is that the
obj.filename
property would sometimes be prefixed with the string "file ", which then causesYardMap::Mapper#map
to remove the pins:solargraph/lib/solargraph/yard_map/mapper.rb
Line 26 in 18854d7
This change adds the prefix stripping regardless of whether we get a filename from
in_files
orfilename
.lots of notes about debugging this, feel free to skip
Reviving this thread, as I'm trying to fix iftheshoefritz/solargraph-rails#34. Here is what I observe:
Preamble
Part 1 - generating YARD objects
Starting from scratch:
Good start, the cached documentation in
~/.solargraph/cache
is contains the expected method definitions.However,
solargraph scan -v
does not show e.g.QueryMethods#where
:So it seems as though somewhere the yardoc from
~/.solargraph/cache
is either not loaded, or is unloaded.Part 2 - when do we load the cache?
Usages of
cache_dir
solargraph/lib/solargraph/yard_map.rb
Line 309 in 87f6275
The correct (cached) yardoc is found, because it gets loaded when I break in YardMap#process_yardoc with the condition
y =~ /activerecord/
The yardoc contains the method objects at the time the yardoc is loaded (checked by breaking in
YardMap::Mapper#map
whenco.name == :where
)However the
@pins.keep_if
line is removing 1596 pins, because many of the pins have alocation.filename
that looks like "<correct_gem_path>/activerecord-7.0.2.4/file lib/active_record/" (emphasis on the "file " in there).Eventually we call
process_yardoc
So, I hacked up YardMap::Helpers#object_location to strip the "file " prefix from
code_object.file
like so:After this
solargraph scan -v
shows the missing methods, and auto-complete works!Part 3 - a real fix?
So it's pretty weird that yard code objects contain an invalid path like that. Especially considering that these code objects should have been produced by Solargraphs own RdocToYard conversion. Taking a peek at
RdocToYard.find_file
reveals the issue:Turns out there was already code to strip the "file " prefix, but it only exists in one of the two branches. Hence this PR.