castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.89k stars 159 forks source link

Autocomplete stopped working for specific class #212

Closed gencer closed 4 years ago

gencer commented 5 years ago

1

I have no idea why this happens. I already sent you the project file with reproducible sample via Email (due to its private).

castwide commented 5 years ago

There's a minor issue with type inference during active editing. A fix is in the master branch and will be released in v0.35.0 tomorrow.

castwide commented 5 years ago

Hmm, it looks like there might be something else going on here. With the latest version, I still don't get type inference for the cnt variable. I'll keep looking.

castwide commented 5 years ago

It looks like the type inference problem was an artifact from another feature branch. I released gem 0.35.0 today. The reproducible sample works correctly in my tests.

gencer commented 5 years ago

@castwide I couldn't test this until now. No, unfortunately, not working. I installed 0.35.0 gem directly via bundler (not master branch) and also tested against master branch and both are not working for my case.

castwide commented 5 years ago

Is it possible you're not opening the folder that contains the files? If you open individual files but not their underlying workspace, completion will still work, but each file won't have access to the other's code.

(A future update should make it possible for main.rb to see container.rb through the require_relative call.)

minkir014 commented 5 years ago

I realized too it's not completing new keyword.

gencer commented 5 years ago

I realized too it's not completing new keyword.

Not just new. Lets say you have an acceptable sze of but large project. And you're working on a single but large class. its members get autocomplete lately. i had to trigger few times to get popup list properly.

castwide commented 5 years ago

I think I found the root cause. When a variable assignment's method call has arguments without parentheses, its type gets inferred from the wrong node. It should work if you put parentheses around the arguments:

cnt = Container.new(param1, param2)

I'm working on a fix. It's a little tricky due to a related issue with method calls that yield blocks, but I should be able to include it in the next patch release.

minkir014 commented 5 years ago

I realized too it's not completing new keyword.

Not just new. Lets say you have an acceptable sze of but large project. And you're working on a single but large class. its members get autocomplete lately. i had to trigger few times to get popup list properly.

I mean in all classes it's not completing keyword new. @castwide I think that this is not hard to be done to make the extension detect classes ands adds new keyword to the list.

castwide commented 5 years ago

@minkir014 Please open a new issue and provide an example. The bug you're describing is unrelated to this one, and I'm not able to reproduce it.

gencer commented 5 years ago

@castwide I will wait for a fix on master branch because there are thousands of declarations like this. I cannot wrap them all at once :/

castwide commented 5 years ago

@gencer The fix is in the master branch. I'll probably release it in v0.35.1 this Friday.

gencer commented 5 years ago

Works here. Thank you so much for quick fix.

castwide commented 5 years ago

Released in v0.35.1.

gencer commented 5 years ago

@castwide, Auto complete is so slow. Lets say I wrote;

class Abc
  def a_method
    return 1
  end

  def b_method
    a_ # <-- at this point if project is large, autocomplete does not shows up. I have to manually trigger via Ctrl+Space. I'm doing this always, because autocomplete is horribly slow.
  end
end

On small projects no problem at all. This happens on a large project (Especially the project files i already sent to you before.)

It was fast. It was working. Since last few release, its not.

castwide commented 5 years ago

At first I thought it might be an issue with type inference, but your example wouldn't trigger it at that point. I'll try to profile for bottlenecks.

One thing that might help, if you haven't done it, is limiting which files you include in your .solargraph.yml. More information: https://solargraph.org/guides/performance

gencer commented 5 years ago

I'll be glad if you can track it down.

As you can see there is also folder variable. Not just a method starts with folder_. And both not get listed.

1

minkir014 commented 5 years ago

When you see those snippets scroll down I think you will find variables you want. As I remember this happened to me with JavaScript and when I scrolled down and found my variables.

gencer commented 5 years ago

Nope.

minkir014 commented 5 years ago

Is that failed or no I don't understand you?

gencer commented 5 years ago

It does not list my variables and functions until I do Ctrl+space or wait for longer.

Issue here is not "Not listing". Issue here we are talking at the moment is slow response.

I get my variables and functions but with a huge delay and sometimes, I need to poke via ctrl+space.

castwide commented 5 years ago

Are you using more than one language server or completion provider?

gencer commented 5 years ago

Ruby (Solargraph) and TypeScript (internal) language servers are used and active on this workspace. I also disabled some rails auto-complete helpers. (And will disable more related and test)

1

I pressed Ctrl+space here. Not wait. If you wait there will be no auto-complete. So need to poke.

castwide commented 5 years ago

Can you give me a list of your extensions? (The issue is still likely to be in Solargraph itself, but I'd like to see if some other feature is exacerbating it.)

gencer commented 5 years ago

Sure, here:

aki77.rails-partial
aki77.rails-routes # disabled in workspace
alefragnani.project-manager
angryobject.react-pure-to-class-vscode
austin.code-gnu-global
bierner.markdown-preview-github-styles
bung87.rails # disabled in workspace
bung87.vscode-gemfile
bungcip.better-toml
capaj.vscode-exports-autocomplete
castwide.solargraph
ccimage.jsonviewer
christian-kohler.npm-intellisense
codezombiech.gitignore
dannymidnight.vscode-buildkite
dbaeumer.vscode-eslint
donjayamanne.githistory
eamodio.gitlens
eg2.vscode-npm-script
emilast.LogFileHighlighter
Equinusocio.vsc-material-theme
felixfbecker.php-debug
felixfbecker.php-intellisense
felixfbecker.php-pack
formulahendry.code-runner
gamunu.vscode-yarn
gencer.buildkite-ci-status
gencer.html-slim-scss-css-class-completion
GitHub.vscode-pull-request-github
golang.gopls
gottfired.css2react
hangxingliu.vscode-nginx-conf-hint
Hridoy.rails-snippets # disabled in workspace
IBM.output-colorizer
jduponchelle.rainbow-end
jpoissonnier.vscode-styled-components
kaiwood.endwise
karunamurti.haml
Kasik96.latte
kevinkyang.auto-comment-blocks
kodetech.electron-debug
mariusschulz.yarn-lock-syntax
mbessey.vscode-rufo
mblode.twig-language-2
michelemelluso.code-beautifier
mikestead.dotenv
mjmcloug.vscode-elixir
mkloubert.vscode-deploy-reloaded
mrmlnc.vscode-scss
ms-azuretools.vscode-docker
ms-mssql.mssql
ms-python.python
ms-vscode-remote.remote-containers
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode-remote.remote-ssh-explorer
ms-vscode-remote.remote-wsl
ms-vscode-remote.vscode-remote-extensionpack
ms-vscode.cpptools
ms-vscode.github-issues-prs
ms-vscode.Go
ms-vscode.powershell
ms-vscode.vscode-typescript-tslint-plugin
msjsdiag.vscode-react-native
paulmolluzzo.convert-css-in-js
pavlitsky.yard
PKief.material-icon-theme
pranaygp.vscode-css-peek
quicktype.quicktype
raynigon.nginx-formatter
rebornix.ruby
redhat.vscode-yaml
robinbentley.sass-indented
rubbersheep.gi
rust-lang.rust
shanehofstetter.rails-i18n
shanoor.vscode-nginx
shinnn.stylelint
sianglim.slim
TheNouillet.symfony-vscode
wwm.better-align
yzhang.markdown-all-in-one

I've marked extensions that disabled. Also all extensions related to PHP also disabled.

I also disabled many extensions that "might" be affect responsiveness. Still slow.

castwide commented 5 years ago

Thanks. I'll see what profiling tells me.

castwide commented 5 years ago

One of the changes since 0.35 was to the library that Solargraph uses to convert documentation to Markdown. I didn't expect that to be the problem here, but now I think it might be. I ran some tests on a few different codebases and several of them encountered problems generating the Markdown.

The current master branch replaces the old conversion with a simpler one. As a result, sometimes unexpected markup will get rendered as plain text, such as these HTML tags in the String.new documentation:

image

I'd much prefer to convert them to Markdown, but it's easier said than done. There doesn't even appear to be a definitive standard for how Markdown should be rendered in LSP clients (e.g., discussion here and here). For the time being, I'd rather display the markup than sacrifice performance or reliability.

gencer commented 5 years ago

@castwide, there is a huge difference now. When I type something and press Ctrl+Space to get intellisense popup list, it list immediately -instantly-. Before your changes, even ctrl+space was so slow to list my autocomplete popup.

However, I still do not get anything when i write a local variable or local method. I discovered that it only happens on local items. For calling outside classes or methods are instant. Let me show you local variables and methods then i will call them on another file (class). See the difference.

  1. Local variable and method completion:

1

  1. Call variables and methods from other class. (and call other classes)

2 3

castwide commented 5 years ago

Could it be an issue with your editor.quickSuggestions setting? This is mine (which I think is also the default):

"editor.quickSuggestions": {
  "other": true,
  "comments": false,
  "strings": false
}

When other is false, autocompletion is triggered by dots, but not by letters. ctrl+space works as expected either way.

gencer commented 5 years ago

Nope. I do not use that option. But tried yours. No difference. Anything local is not triggered by letters. I need to do Ctrl+Space. Or dot ., underscore _ or starts with Uppercase (Like Rails, SecureRandom, Cont...).

gencer commented 5 years ago

I think not just local but anything starts with lowercase is not working. Even @ triggers.

See:

4

I hit Ctrl+Space at end of abort.


If I move that file to a new project (a workspace), it works. But with my current workspace, its not. Im gone crazy.

castwide commented 5 years ago

Does that workspace have a .vscode/settings.json file?

gencer commented 5 years ago

Yes, it only contains deploy related tasks.

gencer commented 5 years ago

Found it! This guy: https://github.com/shanehofstetter/rails-i18n-vscode

I will open an issue there.


Fred, I am so sorry for the trouble I made. I deeply sorry for taking your time on this.

Once again, I confirm that this is issue of rails-i18n-vscode related (or maybe solargraph do something i don't know). But disabling that extension solved all problems.

gencer commented 5 years ago

@castwide, may i ask just one simple more question regarding to autocomplete?

IntelliJ successfully shows me the correct suggestions but Solargraph fails to do that. You can try this on any environment:

SecureRandom.uu #> This should suggest "uuid"
SecureRandom.byt #> This should suggest "bytes" and methods starts with "bytes...".

This is just an example, there are more samples like this but this SecureRandom is the first thing that came to my mind. Is there a specific reason for this to not get listed?

And yeah, I did solargraph bundle

castwide commented 5 years ago

The problem is how the Ruby core composes the SecureRandom module. It should be extended with another module called Random::Formatter, but YARD doesn't find it.

If you add this code, it works:

require 'securerandom'
# @!parse
#   module SecureRandom
#     extend Random::Formatter
#   end

I should be able to fix it automatically from the gem. I'll look into it.

castwide commented 5 years ago

The fix for documentation generation is published in v0.37.2.

gencer commented 5 years ago

The fix for documentation generation is published in v0.37.2.

Thanks!

The problem is how the Ruby core composes the SecureRandom module. It should be extended with another module called Random::Formatter, but YARD doesn't find it.

If you add this code, it works:

require 'securerandom'
# @!parse
#   module SecureRandom
#     extend Random::Formatter
#   end

I should be able to fix it automatically from the gem. I'll look into it.

I put this to rails.rb on my workspace and worked very well. But there are more like this so internal fix will be great.

And congrats! This is 100th release :)

castwide commented 4 years ago

The latest versions of the core documentation include Random::Formatter in the SecureRandom module, so autocompletion finds the uuid method.

I'll close this issue since the original problem was resolved. If you run into any new issues with the updated documentation, please post a comment in #259.

gencer commented 3 years ago

Hey @castwide! One more thing:

This issue and #119 came back again. SevcureRandom and FileUtils (and perhaps other core modules too) has missing xsome members like uuid or rm_rf respectively.

I am using ruby 3.0.1 and downloaded core files for 2.7.2. Could this be the problem?

castwide commented 3 years ago

Both SecureRandom.uuid and FileUtils.rm_rf show up for me using Ruby 3.0.1. I plan to get 3.0.x documentation available soon, but using 2.7.2 in the meantime shouldn't be a problem.

gencer commented 3 years ago

Hm.. Not for me here. See:

Animation

I do not run solargraph bundle. I just do yard gems which gives me more autocomplete then running bundle. But, I also tried via that usage. Same behavior.

castwide commented 3 years ago

Try running solargraph clear && solargraph download-core. The problem might be a stale or corrupted cache.

FileUtils and SecureRandom are in the stdlib, so solargraph bundle shouldn't be necessary here.

gencer commented 3 years ago

Interestingly still have that problem. But, Now it goes further.

I closed my original project and created a new folder (called aaa/) and put one file in it a.rb.

See action:

image

Not even SecureRandom namespace gets listed :/. Something is seriously broken.

I couldn't find anything yet. But it works for few namespaces:

image

BTW, I am on Remote SSH. Windows 10 connected to Ubuntu-20.04

castwide commented 3 years ago

Dang. I haven't been able to replicate this problem, even using Remote SSH (Windows 10 connected to CentOS 7.6).

gencer commented 3 years ago

Let me try one by one changing settings and disabling extensions. I am using rbenv to manage ruby versions and do not use solargraph in Gemfile but globally.

However, On Windows 10, Locally, I am able to see uuid and other things. It works on Windows but not on remote. Something interfere remotely. Let me check further. But If you have any idea, please let me know while I am working on it.

castwide commented 3 years ago

One thing you can try is running "Solargraph: Get environment info" from the VS Code command palette to make sure you're running the version of Ruby you expect. The extension should work with rbenv but problems are possible.

gencer commented 3 years ago
Solargraph Environment Info
System
Platform: x86_64-linux
Shell: /bin/bash
Ruby Version: 3.0.1
RuboCop Version: 1.14.0
Solargraph
Solargraph Version: 0.42.3
Core Documentation Version: 2.7.2
Core Cache Directory: /home/gencer/.solargraph/cache
Using Bundler: false
Project
Config: {"completion"=>true, "hover"=>true, "symbols"=>true, "definitions"=>true, "rename"=>true, "references"=>true, "autoformat"=>false, "diagnostics"=>true, "formatting"=>false, "folding"=>true, "logLevel"=>"warn", "enablePages"=>true, "viewsPath"=>"/home/gencer/.vscode-server/extensions/castwide.solargraph-0.23.0/views", "transport"=>"socket", "externalServer"=>{"host"=>"localhost", "port"=>7658}, "commandPath"=>"solargraph", "useBundler"=>false, "bundlerPath"=>"bundle", "checkGemVersion"=>true}
Workspace folders: ["/home/gencer/sources/nienbo/aaa"]

Seems fine :/

castwide commented 3 years ago

Seems fine :/

I agree. Please let me know if you figure it out.

gencer commented 3 years ago

Seems fine :/

I agree. Please let me know if you figure it out.

Updated for Solution

@castwide. I've tried RVM and system ruby. All worked as expected. Then I dig more and found that root cause of this issue is running: yard gems

If I remove securerandom-0.1.0 folder from /home/gencer/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems everything works perfectly.