Conversion between dashes in gemspec name and slashes in required paths #697
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.
I was faced with a strange behavior and finally found the possible root cause of it.
Background
As recommended by Rubygems.org "Name your gem", there is a conventional correspondence between dashes
-
in a gem name and slashes/
in a required path.For example, if you want to use
net-smtp
gem,first you have to add to your Gemfile
and second you require it:
Problem
However, I noticed that solargraph did not suggest to me the source code comments on
net-smtp
.In the code above I expected solargraph to show me the signature of
Net::SMTP.start()
but it did not.I found that the root cause of this phenomenon was how solargraph treated
require
d paths.Currently it regards the first part of slash-separated
require
d path as the name of the gem.https://github.com/castwide/solargraph/blob/master/lib/solargraph/yard_map.rb#L285
Therefore, when it finds
sentence, the regarded gem name is not
net-smtp
butnet
.So there is no way for solargraph to detect gems whose names are dash-concatenated and whose actual relative paths are NOT dash-concatenated but slash-separated.
Proposal
Here I propose another algorithm to determine the name of the gem.
require
d path by slashes/
-
and let it be the candidate of the name of the gemFor example, with this algorithm, when solargraph encounters the line
["net", "smtp", "authenticator"]
net-smtp-authenticator
net-smtp-authenticator
exist? No it does not.net-smtp
exists? Yes it does.After I applied this algorithm to my environment, solargraph showed me source code comments in
Net::SMTP
as I expected.Any possible drawbacks?