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

Add completion for classes and modules #61

Closed
vinistock opened this issue Mar 29, 2022 · 10 comments · Fixed by #957
Closed

Add completion for classes and modules #61

vinistock opened this issue Mar 29, 2022 · 10 comments · Fixed by #957
Assignees
Labels
enhancement New feature or request pinned This issue or pull request is pinned and won't be marked as stale
Milestone

Comments

@vinistock
Copy link
Member

vinistock commented Mar 29, 2022

Although our LSP won't offer first class completion like Sorbet's LSP (since it would require complete typechecking), we can still offer some simple convenience auto completes.

Some ideas, but not an exhaustive list:

  • on typing do, offer to complete with two options |arg| \n end or just end
  • on proc, lambda or -> offer to complete with { |arg| } or just {}
  • on if, offer else, elsif and complete the end
  • offer to add end on other keywords, such as while, until, for
  • on require or require_relative, offer a filtered list of possible files

Documentation: https://microsoft.github.io/language-server-protocol/specification#textDocument_completion

In addition, we can investigate how IRB completion works and evaluate if we can somehow use it from inside the Ruby LSP.

@vinistock vinistock transferred this issue from another repository Apr 8, 2022
@vinistock vinistock mentioned this issue Jul 15, 2022
@inkyvoxel
Copy link

Sorry if this is the wrong place to ask (or a silly question in general), but what is the likelihood of ruby-lsp completions becoming as thorough as the completions in irb and rails console? I find both of those tools have incredibly fast and detailed completions. After using them, I am often left longing for my text editor to work in the same way.

Example of irb giving an immense list of methods I can call on a string:

irb

Example of rails console giving a list of all the methods I can call on my Active Record model:

rails-console

Is this something that ruby-lsp and vscode-ruby-lsp could eventually achieve? Or are completions like this the responsibility of a different sort of tool?

@vinistock
Copy link
Member Author

Not a silly question at all! I'm not sure how these new IRB completions work internally, but they are indeed very useful - and it would be a great experience for the Ruby LSP.

I think it could be achieved, but it does require some exploration to understand how it's done. Maybe it could even be shared between IRB and the Ruby LSP? I'll add this idea to the issue description.

@st0012
Copy link
Member

st0012 commented Aug 30, 2022

@vinistock is #253 part of this ticket?

@vinistock
Copy link
Member Author

@st0012 no, onTypeFormatting is for formatting code as the user is typing - like automatically adding the end or adjusting indentation. This ticket is for completion on method invocations.

@st0012
Copy link
Member

st0012 commented Aug 30, 2022

offer to add end on other keywords, such as while, until, for

Ah ok. I saw #253 adds end keyword so I assumed they are the same as the above.
I guess the difference is #253 always append a word based on pattern, but this one is to provide completion options?

@vinistock
Copy link
Member Author

Yes, one is for automatic formatting and the other one is to provide completion options (since we can't know ahead of time which method the user is looking for).

@inkyvoxel
Copy link

Not a silly question at all! I'm not sure how these new IRB completions work internally, but they are indeed very useful - and it would be a great experience for the Ruby LSP.

I think it could be achieved, but it does require some exploration to understand how it's done. Maybe it could even be shared between IRB and the Ruby LSP? I'll add this idea to the issue description.

That is exciting! Thanks for considering it.

I was curious how the completions work in the tools I mentioned:

I am new to Ruby, so this may just be fluff 😁 Hopefully it can start some discussion in the future. I am interested in learning more!

@gobijan
Copy link

gobijan commented Sep 22, 2022

I think a while ago JetBrains had an experimental completion plugin for Rubymine that instantiated the application in the background and offered completions based on what is available in the runtime. This was actually painfully slow. But given Ruby's character of meta programming this is probably the only approach that can offer 100% accurate code completion.
Feel free to correct me when there are better approaches available to have exact autocompletion.

@vinistock
Copy link
Member Author

It would indeed be much more accurate, but I think it would be unbearably slow for large Rails applications. Also, it would require the LSP to know how to boot the application, since it may not necessarily be a Rails app.

If we can figure out a way to offer completions based on static analysis only, it should be a lot faster, more maintainable and application agnostic.

@eyar
Copy link

eyar commented Jul 5, 2023

it would be unbearably slow for large Rails applications

Wouldn't it be possible to cache all models and their methods, and just modify the cache on changes? doesn't sound like a huge list.

@vinistock vinistock changed the title Add simple completion to the ruby-lsp Add completion for classes and modules Jul 10, 2023
@vinistock vinistock added this to the 2023-Q3 milestone Jul 10, 2023
@vinistock vinistock added enhancement New feature or request pinned This issue or pull request is pinned and won't be marked as stale labels Jul 20, 2023
@vinistock vinistock self-assigned this Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned This issue or pull request is pinned and won't be marked as stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants