-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the document link request to link to Rails documentation #258
Comments
I'm not sure if the implementation in my head is the best solution, so I want to discuss it here: Link formatClass (or module)
Method
Information required for making the link
Implementation
|
@st0012 This sounds like a really good plan to me! I have one question: would it be possible to eliminate the use of the stack by using things like the |
I think it's not possible because we're not actually evaluating the code? We can only access names instead of the objects from syntax tree AFAIK. |
Oh, it's unfortunate that the classes and modules are a part of the URL. However, we don't need to add document links for every single method exported by Rails. Just providing this for the most common ones will probably already provide quite a bit of value. What do you think about doing something like this class DocumentLink < BaseRequest
BASE_RAILS_DOC_URL = "https://api.rubyonrails.org/v#{RAILS_VERSION}" # read the rails version from the stubs
METHOD_TO_DOC_URL = {
"belongs_to" => "classes/ActiveRecord/Associations/ClassMethods.html"
}
def visit_command(node) # Not sure if it's command, just an example
suffix = METHOD_TO_DOC_URL[node.value] # or node.message something like that
return if suffix.nil? # We don't know the doc URL for this one
target = "#{BASE_RAILS_DOC_URL}/#{suffix}#method-i-#{node.value}"
# create link from target
end
end I suggest prioritizing the following. You can start by implementing only one of them in an initial PR (e.g.: only belongs_to) to get feedback on the logic. After we settled on that, it's just a matter of adding more entries to the hash in follow up PRs.
|
Rails API guides have a search mechanism which relies on the data stored in the For example, the // ...
[
"run_callbacks",
"ActiveSupport::Callbacks",
"classes/ActiveSupport/Callbacks.html#method-i-run_callbacks",
"(kind)",
"<p>Runs the callbacks for the given event.\n<p>Calls the before and around callbacks in the order they were set, …\n"
],
// ... |
@vinistock I think the white listing approach is not ideal for Rails documentation as there are many methods and components that could use this feature. So the list will end up very long and we'll need to manually select things to be added. I'd like to avoid this if possible. @paracycle The I'll prototype the proposed flow to see if the current |
As another aspect to this issue, can we also consider adding comments to the generated RBIs for DSLs in Tapioca? Thanks to the DSL compilers, a lot of the methods created through Rails meta-programming get reified in the RBI files and appear when the user overs them. We could make the DSL compilers attach comments to the generated RBI nodes so it explains where the things come from and points to the documentation of the feature. |
Consider this: # file1.rb
class CustomJob < ApplicationJob
# ...
end # file2.rb
class SomeJob < CustomJob
# ...
end Only considering If we want to rely on the model we will have to know about the whole code base and I fear that anything not based on Sorbet will be too slow. In the meantime we can prototype with the whitelist approach but we may link things that are unrelated by accident. |
I thought this link will only be activated in
So I think the Rails document link will only happen in the
If we try to resolve the method source from application code directly, I think it'd be too inaccurate. |
After discussing with @vinistock we had these conclusion:
|
Ok is cool |
…ypescript-eslint/parser-5.40.1 Bump @typescript-eslint/parser from 5.40.0 to 5.40.1
We implemented the DocumentLink request in #58 and used it to go to method definition from gem RBIs.
As a next step, let's use this request to link to the correct Rails documentation for methods that come from the rails gem.
When a user hovers over a method that's defined in rails, there should be a link that says "go to documentation." We can use information about the method, such as the class that defines it and its ancestor chain, as well as information about the rails gem (version number) to link to the correct documentation page for that method.
The text was updated successfully, but these errors were encountered: