Skip to content
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

Support document link for Rails documentation #285

Closed
wants to merge 4 commits into from
Closed

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Sep 2, 2022

Motivation

Closes #258

Implementation

Automated Tests

Manual Tests

TODOs

  • Replace Rails version number with a placeholder
  • Mock the Rails document request in tests
  • Activate the feature based on file path, e.g. Only check activerecord's documents when the file is under a models/ folder.
  • Exclude activesupport and actionview
  • Add tests for actionpack, activemodel, and activestorage
  • Use better way for searching
  • Documentation

Demo

@st0012 st0012 added enhancement New feature or request unstable labels Sep 2, 2022
@st0012 st0012 self-assigned this Sep 2, 2022
@st0012 st0012 force-pushed the st0012-#258 branch 7 times, most recently from 3b54e29 to 1dfb2dd Compare September 6, 2022 15:23
lib/ruby_lsp/handler.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
@st0012 st0012 force-pushed the st0012-#258 branch 2 times, most recently from a7858d5 to 96704f8 Compare September 7, 2022 15:31
@vinistock
Copy link
Member

This is looking great. One final detail: do we need to pull in VCR and webmock for testing it? Would we be able to use a Minitest stub and avoid adding the dependencies? I don't foresee the LSP having too many API requests, so I'm not sure adding the dependencies will pay off.

@st0012 st0012 force-pushed the st0012-#258 branch 3 times, most recently from b039b7b to 31b7e2a Compare September 12, 2022 12:28
@st0012
Copy link
Member Author

st0012 commented Sep 12, 2022

@vinistock Given the additional logic on processing and filtering the dataset, I want the request's tests to be as realistic as possible. And in that case, the options we have are:

  1. Store the document in plain text, load it manually, and return the result with Minitest stub.
  2. Use VCR or webmock for that.

I'm ok with doing 1 instead, but I also don't think it's a big problem having vcr as "development" dependency.

@vinistock
Copy link
Member

I think we will probably not be using VCR or webmock anywhere other than this one method in document links. That's why I feel like something like this would be simpler

fake_docs = {
  "belogs_to" => ...
}

RubyLsp::Requests::DocumentLink.stub(:rails_documents, fake_docs) do
  RubyLsp::Requests::DocumentLink.new(document).run
end

@st0012
Copy link
Member Author

st0012 commented Sep 12, 2022

@vinistock As I said, I don't just want to test it agains a fake hash. The thing we got from search_index.js is a JS code. And we do a bunch of processing on it to make it work with the request, which I think should be tested too.

@st0012 st0012 marked this pull request as ready for review September 12, 2022 13:38
@st0012 st0012 requested a review from a team as a code owner September 12, 2022 13:38
@vinistock
Copy link
Member

Agreed that there's a lot of value in that, but you can also achieve it with a stub, no?

Net::Http.stub(:get_response, js_content) do
  ...
end
```

@st0012
Copy link
Member Author

st0012 commented Sep 12, 2022

Yes and I've mentioned that I'm ok with that:

Store the document in plain text, load it manually, and return the result with Minitest stub.

I'm only against testing it with a hash directly

@st0012 st0012 force-pushed the st0012-#258 branch 2 times, most recently from 492248f to bc210a1 Compare September 12, 2022 15:07
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions that came up while testing this

  • Is there an option for placing the link on top of the hover documentation? These Rails methods have a lot of documentation and we end up having to scroll through a lot before finding the links
  • Is there a way of disabling cmd click for document links only? Maybe some VS Code configuration? Right now, if you cmd click a method with links you jump to the browser and Sorbet jumps to the RBI file at the same time

lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@egiurleo egiurleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool so far! I left some questions and a suggestion!

lib/ruby_lsp/requests/base_request.rb Show resolved Hide resolved
lib/ruby_lsp/requests/base_request.rb Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
@st0012 st0012 force-pushed the st0012-#258 branch 3 times, most recently from 3a955f0 to f54712d Compare September 20, 2022 11:33
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
test/requests/document_link_expectations_test.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/document_link.rb Outdated Show resolved Hide resolved
@vinistock
Copy link
Member

I tophatted this again and it's looking great, I'm really excited for it.

The one thing I think we need to find a decent solution for is the overlap of this feature with go to definition by Sorbet. Right now, CMD + click will perform both operations at the same time. You get redirected to the browser with the documentation and when you come back to the editor you're suddenly in the RBI file.

Two possible ideas, but we need to validate that the experience is decent

  1. If it's possible, turn off CMD + click for document links
  2. Instead of attaching the document link to the entire word, use only the first character. This will make it harder to hit the conflict, but may degrade the document links experience

@st0012
Copy link
Member Author

st0012 commented Sep 26, 2022

In terms of the cmd+click behaviour, I couldn't find anything that helps it. Since cmd+click is arguably a client-specific behaviour, I think it's expected that LSP doesn't cover it. But I also don't find anything config on VSCode that can disable it based-on a specific extension.

But it looks like vscode-terraform has reported a similar problem: microsoft/vscode#147447. So the good news is that we're not alone. The bad news is that the issue was opened almost 6 months ago and still has no comments 😅

In Rails, there are too many classes/modules that can define common
method names like `#to_s`, like `ActiveController::Parameters#to_s`,
which has documentation but is usually not what the user is calling.

But becaues of the lack of typing information, `ruby-lsp` can't really
determine if the document is marked on the right method. So Rails document
link on general method calls can have a high inaccuracy and become
counter-productive.

Therefore, this commit disables marking `Call` nodes and only focuses on
DSL method calls (`Command` nodes).
@st0012
Copy link
Member Author

st0012 commented Sep 29, 2022

Close in favour of #313

@st0012 st0012 closed this Sep 29, 2022
@st0012 st0012 deleted the st0012-#258 branch September 29, 2022 15:28
vinistock pushed a commit that referenced this pull request Feb 28, 2024
…pt-eslint/eslint-plugin-5.42.1

Bump @typescript-eslint/eslint-plugin from 5.42.0 to 5.42.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use the document link request to link to Rails documentation
3 participants