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

Rubocop formatting does not work #83

Closed
gencer opened this issue Oct 12, 2018 · 26 comments
Closed

Rubocop formatting does not work #83

gencer opened this issue Oct 12, 2018 · 26 comments

Comments

@gencer
Copy link

gencer commented Oct 12, 2018

I want to fix, clean and format my *.rb files when I press Format Document. However, it doesn't work. It was working before but today I want to format few files and it just doesn't work.

.solargraph.yml:

	---
	include:
	- "**/*.rb"
	exclude:
	- spec/**/*
	- test/**/*
	- vendor/**/*
	- ".bundle/**/*"
	require: []
	domains: []
	reporters:
	- rubocop
	- require_not_found
	plugins:
	- runtime
	max_files: 5000

No rubocop.yml file present in folder. Simply press F1 and select Format Document. ruby.exe starts in the background and exits after few seconds. No formatting done to the document. No logs (including in debug console) indicating any error. This is my settings:

	// "ruby.format": "rubocop",
	"solargraph.formatting": true,
	"editor.formatOnSave": true,
	"files.insertFinalNewline": true,
	"files.autoSave": "onFocusChange",
	"ruby.lint": {
		"reek": false,
		"rubocop": {
			"lint": true,
			"rails": true
		},
		"ruby": {
			"unicode": true
		},
		"fasterer": false,
		"debride": false,
		"ruby-lint": false
	},
	"editor.formatOnSaveTimeout": 20000,
	"[ruby]": {
		"editor.formatOnSave": true
	},

VScode + OS Env:

	Version: 1.28.1 (user setup)
	Commit: 3368db6750222d319c851f6d90eb619d886e08f5
	Date: 2018-10-11T18:13:53.910Z
	Electron: 2.0.9
	Chrome: 61.0.3163.100
	Node.js: 8.9.3
	V8: 6.1.534.41
	Architecture: x64 Windows 10
@castwide
Copy link
Owner

Confirmed. The server responds with the formatted document and a null range, which is supposed to mean that the whole document should be replaced. Apparently the client ignores edits without ranges. I'll fix it in the gem for the next release.

@gencer
Copy link
Author

gencer commented Oct 12, 2018

@castwide, Thank you so much. I was driving nuts by thinking if I did something wrong with config.

Hopefully, wait for a fix now.

Gencer.

@castwide
Copy link
Owner

Fixed in gem v0.28.3.

@gencer
Copy link
Author

gencer commented Oct 22, 2018

@castwide , I do not know what other fixes/additions other than this fix happen in master branch but at the moment everytime I open VSCode and work on Ruby, solargraph (actually ruby.exe) terminates itself. "Restart solargraph" does not work either.

@gencer
Copy link
Author

gencer commented Oct 22, 2018

This is only output i can find at the moment:

[2018-10-23 02:03:11.866] [renderer5] [info] no standard startup: not just one window
[2018-10-23 02:03:27.727] [renderer5] [error] An unknown error occurred. Please consult the log for more details.
[2018-10-23 02:07:17.716] [renderer5] [error] Connection is closed.: Error: Connection is closed.
    at new ConnectionError (C:\Users\gence\.vscode\extensions\castwide.solargraph-0.17.6\node_modules\vscode-jsonrpc\lib\main.js:138:28)
    at throwIfClosedOrDisposed (C:\Users\gence\.vscode\extensions\castwide.solargraph-0.17.6\node_modules\vscode-jsonrpc\lib\main.js:613:19)
    at Object.sendNotification (C:\Users\gence\.vscode\extensions\castwide.solargraph-0.17.6\node_modules\vscode-jsonrpc\lib\main.js:667:13)
    at C:\Users\gence\.vscode\extensions\castwide.solargraph-0.17.6\node_modules\vscode-jsonrpc\lib\main.js:783:32
    at e.fire (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:99:496)
    at e.cancel (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:106:331)
    at e.cancel (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:107:51)
    at Object.l (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:639:104)
    at t._receiveCancel (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:639:864)
    at t._receiveOneMessage (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:638:387)
    at c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:635:926
    at c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:98:138
    at e.fire (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:99:496)
    at a (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:154:213)
    at Socket._socketDataListener (c:\Users\gence\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:154:432)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

@castwide
Copy link
Owner

One possibility: can you tell me the results of gem list eventmachine?

@gencer
Copy link
Author

gencer commented Oct 23, 2018

gence@GENCER MINGW64 ~/Desktop
$ gem list eventmachine
eventmachine (1.2.7)

I always uninstall eventmachine and install with system libraries as stated in README. When eventmachine is wrong, Solargraph doesnt even start. In my case, it starts, works for a while then ruby.exe exits.

@castwide
Copy link
Owner

The only time I've seen that happen is in an experimental version of the extension that uses a stdio transport. This is the first time I've seen anything similar with the socket transport.

Does it happen with any workspace you open? How about a single ruby file without a workspace?

@castwide
Copy link
Owner

Also, one other thing you can try is removing the experimental runtime plugin from your .solargraph.yml file. I don't know if it's the cause here, but it has some known issues.

@gencer
Copy link
Author

gencer commented Oct 23, 2018

Let me try both with another project and without runtime and report back. I do not want to report without being sure. If this happens again I will raise a new issue and link here.

@castwide
Copy link
Owner

@gencer I may have found the issue. The server crashes intermittently while generating additional documentation for completion items. Best I can tell, it's an access violation due to some component in the RDoc library that's not thread-safe. That would explain why you and I encounter the same bug under different circumstances.

I'll fast-track a fix and update the gem in a day or so.

@gencer
Copy link
Author

gencer commented Oct 24, 2018

@castwide, I was going to update here and saw your reply. I tested and;

  1. It crashes on every project/workspace
  2. runtime doesn't change anything.

I will follow on #97

Thank you for the reply.

@gencer
Copy link
Author

gencer commented Nov 18, 2018

I got it again:

[Error - 7:48:27 PM] Connection to server is erroring. Shutting down server.
... repeated ...

This is happen usually and especially two or more projects are open at the same time.

Any log in anywhere?

@gencer
Copy link
Author

gencer commented Nov 18, 2018

@castwide, one more thing. I am not sure if this log entry belongs to your gem but I got this:

[Error - 7:40:05 PM] Request textDocument/completion failed.
  Message: [SystemStackError] stack level too deep
  Code: -32603 
[Error - 7:58:59 PM] Connection to server is erroring. Shutting down server.
[Error - 7:58:59 PM] Connection to server is erroring. Shutting down server.
[Error - 7:58:59 PM] Connection to server is erroring. Shutting down server.
[Error - 7:58:59 PM] Connection to server is erroring. Shutting down server.
[Error - 7:58:59 PM] Connection to server is erroring. Shutting down server.
[Error - 7:58:59 PM] Connection to server is erroring. Shutting down server.

@castwide
Copy link
Owner

The stack level too deep message looks like it came from the server while trying to provide completion suggestions for something you recently typed. Any chance you can identify a snippet of code where it happens?

There might be more information in the console (Help -> Toggle Developer Tools).

@gencer
Copy link
Author

gencer commented Nov 18, 2018

Unfortunately, there is no any log in developer tools rather than I sent above.

Usually happens when I work inside each blocks. Like;

folders.each do |f|
 ...
end

@gencer
Copy link
Author

gencer commented Nov 18, 2018

@castwide, I've finally reproduced it. Here is anew GIF: (it's 1MB so maybe slow to load)

first

Probably when I copy/paste or edit such blocks, solargraph get crashed. This happens all the time.

Also in zip:
first.zip

@castwide
Copy link
Owner

@gencer Thanks. I haven't been able to reproduce it yet, but I think we're getting closer.

I tried a few different ways of copy/pasting blocks in code, including variations that result in parse errors. Nothing so far.

If you can share the file where it happens, or point me to a GitHub repo that contains the code, that might help, but I understand if it's not an option.

@gencer
Copy link
Author

gencer commented Nov 19, 2018

@castwide. This is what I did:

  1. I copied this file outside of my project and open a fresh visual studio.
  2. I dropped that file to VSCode and tried above behavior. Simply copy paste between (and including) Lines 386 - 394. r select those lines and press "m" from keyboard then Ctrl+Z (Revert).
  3. This will cause stack level too deep error. If you do this second time, server will close.

But if I try this code block only outside of that file then it works without problem. This means there is an another thing that trigger this error.

Do you have an email? I can send you that file privately. Or how can I transfer that file to you privately?

Gencer.

@gencer
Copy link
Author

gencer commented Nov 19, 2018

Update: I found your email on your profile and send to you.

@castwide
Copy link
Owner

@gencer I'm finally able to reproduce the error following the steps you posted with the file you sent. Now I'll get to work on tracking down the root cause. With any luck, I can have a fix released within a week or so. Thanks again for all your help.

@gencer
Copy link
Author

gencer commented Nov 19, 2018

@castwide, I'm glad I could help. Let me know if anything needed!

Awaiting for your fixes.

Thanks,
Gencer.

@castwide
Copy link
Owner

The root cause turned out to be a bug in how AST nodes are generated for code with unrecoverable syntax errors. It worked most of the time by sheer coincidence, but in rare instances it would result in recursive trees.

The fix is in the master branch and will be released in gem version 0.29.0.

@gencer
Copy link
Author

gencer commented Nov 21, 2018

I've tested master branch and yeah, it worked! No more crashes.

Thank you so much, Fred, for your awesome gem and help.

(P.S.: If I encounter any problem again, I will ping here and send you the whole file via email if necessary)

@castwide
Copy link
Owner

The fix is published in gem v0.29.0.

@dogweather
Copy link

Could you please close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants