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

Intellisense with Ruby-LSP #19143

Closed
rad10 opened this issue Apr 27, 2024 · 10 comments
Closed

Intellisense with Ruby-LSP #19143

rad10 opened this issue Apr 27, 2024 · 10 comments
Labels
suggestion-docs New documentation suggestions

Comments

@rad10
Copy link
Contributor

rad10 commented Apr 27, 2024

Summary

So I've been on this problem for months now. I understand that most of Rapid7 uses rubymine which is basically intellij. But I use vscode for developing ruby, which is why I included configs for solargraph that made it read lib and ignoring modules. Fast forward to today and solargraph no longer works (no matter how much I scream at my screen to make it so.)

The next best choice to replace it that most of the ruby community is hopping on now is Ruby-LSP. In theory, it is the best choice for this purpose, but its falling for the same issues solargraph had without configs. LSP needs to be configured to read the modules from lib and ignore any functions defined in modules besides whats in the current file.

This is where I've been stuck because Ruby-LSP's documentation has been a nightmare to say the least and even with whatever configs they give, I cannot get it to include/exclude the right files and modules.

The TL;DR on this is that it would be nice to get some configs in the workspace to allow people using LSP to easily intellisense and format in whatever IDE that they're using.

Motivation

Beside the fact that only some developers use rubymine, everyone has their own preference on IDE *cough* *cough* neovim. It would be helpful to all developers if we had an easier way to read documentation and write modules.

Steps to resolve this issue

I've already done a lot of the heavy lifting. We just need a configuration file to limit LSP's scope on the project to only what we as developers need. That would make IDE's load faster and have little to no overloads.

Configs for other IDE's to use LSP would also be helpful. Such as a settings.json and extensions.json to go in the vscode folder to use lsp and intellisense immediately (since I cant get it to work with vscode without it crashing 3 times)

@rad10 rad10 added the suggestion-docs New documentation suggestions label Apr 27, 2024
@adfoster-r7
Copy link
Contributor

If you create a PR similar to #17991 we could take a look? I'm not convinced we should be providing these files for end-users, but if you're able to create a PR we could review it and potentially merge it

@rad10
Copy link
Contributor Author

rad10 commented Apr 27, 2024

I can definitely put out a pull request with what I have, but ultimately this is a cry for help. I'm having issues setting this up and I'm unsure if it's because lsp is still very new or if my workspace has been messed up. I want to throw this out in case someone else might have found the solution or at least part of it. Baby steps to get back to solargraph

@adfoster-r7
Copy link
Contributor

I cant get it to work with vscode without it crashing 3 times

If you have replication steps, we could maybe take a look - it might be an issue with the projects you're using; and if that's the case you'd probably want to file an issue over there

@rad10
Copy link
Contributor Author

rad10 commented Apr 29, 2024

So after rebuilding my workspace to recreate my steps, it has finally started to work.

I started by installing rbenv and installing the ruby version used in the repo. Afterwards, I Installed Ruby-LSP for vscode and let it build, I finally got it working. Now it technically works. It doesnt find the proper definition for functions nor does it tell what type variables are. I'm unsure if its too new for it to recognize it but I'm unsure. I made a branch with the settings for test.

@rad10
Copy link
Contributor Author

rad10 commented May 1, 2024

Just wanted to check in. Has anyone attempted to recreate the steps that I proposed? Is anyone else having the same issues that I'm having with ruby-lsp?

I know that the exclusions need to be improved because with the current config, every module will have any external functions have no file definition. This only changes when the - "**/modules/**/*.rb" line it removed. However, when it autocompletes for given functions, it will autocomplete for definitions in other module files. I cannot get it to use lib to save my life and I'm stuck as to why.

image

This could be an options issue, but then I'm having issues with seeing class functions for standard ruby. If I do ''. It will not give me a list of ruby functions that affect the string library. File. Gives me nothing.

This is probably a settings issue (its also probably an issue that its kinda trash at what its supposed to do) but I do not understand how the indexer works to make better inclusions and exclusions. I also have no idea what could possibly be missing to prevent it from doing intellisense on standard ruby.

@adfoster-r7
Copy link
Contributor

I can confirm that RubyMine provides code completion in that scenario:

image

And from reading ruby-lsp'd docs, it looks like method code completion isn't supported:

The Ruby LSP features include

  • Semantic highlighting
  • Symbol search and code outline
  • RuboCop errors and warnings (diagnostics)
  • Format on save (with RuboCop or Syntax Tree)
  • Format on type
  • Debugging support
  • Running and debugging tests through VS Code's UI
  • Go to definition for classes, modules, constants and required files
  • Showing documentaton on hover for classes, modules and constants
  • Completion for classes, modules, constants and require paths
  • Fuzzy search classes, modules and constants anywhere in the project and its dependencies (workspace symbol)

Adding method support for definition, completion, hover and workspace symbol is planned, but not yet completed.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

https://github.com/Shopify/ruby-lsp/tree/722e4a8c8853d042253069a2002fd010a77a8a1c/vscode#features

@rad10
Copy link
Contributor Author

rad10 commented May 3, 2024

I can confirm that RubyMine provides code completion in that scenario:

image

And from reading ruby-lsp'd docs, it looks like method code completion isn't supported:

The Ruby LSP features include

  • Semantic highlighting
  • Symbol search and code outline
  • RuboCop errors and warnings (diagnostics)
  • Format on save (with RuboCop or Syntax Tree)
  • Format on type
  • Debugging support
  • Running and debugging tests through VS Code's UI
  • Go to definition for classes, modules, constants and required files
  • Showing documentaton on hover for classes, modules and constants
  • Completion for classes, modules, constants and require paths
  • Fuzzy search classes, modules and constants anywhere in the project and its dependencies (workspace symbol)

Adding method support for definition, completion, hover and workspace symbol is planned, but not yet completed.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
https://github.com/Shopify/ruby-lsp/tree/722e4a8c8853d042253069a2002fd010a77a8a1c/vscode#features

Is that rubymine with lsp? It sounds like lsp is just terrible and not ready for use just yet. Not sure what to do about intellisense on vscode/other IDE's since solargraph doesnt particularly work anymore. Does rubymine have something specific that it uses for intellisense or is it all built in?

@adfoster-r7
Copy link
Contributor

Does rubymine have something specific that it uses for intellisense or is it all built in?

It's all built in, they don't use LSP - but their own PSI (Program Structure Interface) implementation instead. There's a thread here about why don't really offer LSP integration support:

The LSP doesn’t allow to build outstanding support for a language, it allows to build the “least common denominator” support only.
https://discuss.kotlinlang.org/t/any-plan-for-supporting-language-server-protocol/2471/2

In this case it looks like Shopify's LSP for Ruby doesn't provide the expected level of support out of the box, but maybe it will in the future

@adfoster-r7
Copy link
Contributor

Let me know if there's anything else to help with here or if we should close it off. I think we could document that Ruby-LSP doesn't offer full support to the user; or maybe there's some additional debugging steps required here to see if there's config changes we need to make?

solargraph no longer works

@rad10
Copy link
Contributor Author

rad10 commented May 8, 2024

Well its meant to fix intellisense and we have all of the configuration. I cannot properly test that it works as intended (yet), but everything needed on this side should already be done.

In that regard, what I can do to resolve this without it being forgotten is close as not planned and we could come back to it when ruby-lsp actually works.

@rad10 rad10 closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion-docs New documentation suggestions
Projects
None yet
Development

No branches or pull requests

2 participants