This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Long RuboCop/Standard output JSON does not parse correctly #435
Copy link
Copy link
Closed
Labels
bugBug reportsBug reports
Description
Your environment
vscode-rubyversion: 0.22.0- Ruby version: 2.1.2
- Ruby version manager (if any): asdf 0.6.3
- VS Code version: 1.31.1
- Operating System: Mac OS 10.14.3
- Using language server? Yes
Expected behavior
Rubocop will lint a file
Actual behavior
Rubocop doesn't lint a file. And I have next error in Ruby language server output:
[Info - 2:30:00 PM] Initializing Ruby language server...
[Info - 2:30:00 PM] Rebuilding tree-sitter for local Electron version
[Info - 2:30:00 PM] Rebuild succeeded!
Lint: executing rubocop -s <path_to_file> -f json -R -l...
/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/util/hostReportError.js:4
setTimeout(function () { throw err; });
^
TypeError: LINTER_MAP[name] is not a constructor
at getLinter (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/out/Linter.js:24:12)
at MergeMapSubscriber.rxjs_1.from.pipe.operators_1.mergeMap.l [as project] (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/out/Linter.js:31:37)
at MergeMapSubscriber._tryNext (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/operators/mergeMap.js:69:27)
at MergeMapSubscriber._next (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/operators/mergeMap.js:59:18)
at MergeMapSubscriber.Subscriber.next (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/Subscriber.js:66:18)
at Observable._subscribe (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/util/subscribeToArray.js:5:20)
at Observable._trySubscribe (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/Observable.js:44:25)
at Observable.subscribe (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/Observable.js:30:22)
at MergeMapOperator.call (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/operators/mergeMap.js:39:23)
at Observable.subscribe (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/server/node_modules/rxjs/internal/Observable.js:25:31)
[Info - 2:30:01 PM] Connection to server got closed. Server will restart.
[Error - 2:30:01 PM] Request textDocument/foldingRange failed.
Error: Connection got disposed.
at Object.dispose (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/main.js:876:25)
at Object.dispose (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-languageclient/lib/client.js:71:35)
at LanguageClient.handleConnectionClosed (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-languageclient/lib/client.js:2150:42)
at LanguageClient.handleConnectionClosed (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-languageclient/lib/main.js:150:15)
at closeHandler (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-languageclient/lib/client.js:2137:18)
at CallbackList.invoke (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/events.js:62:39)
at Emitter.fire (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/events.js:120:36)
at closeHandler (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/main.js:226:26)
at CallbackList.invoke (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/events.js:62:39)
at Emitter.fire (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/events.js:120:36)
at IPCMessageReader.fireClose (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/messageReader.js:111:27)
at ChildProcess.constructor.eventEmitter.on (/Users/shir/.vscode/extensions/rebornix.ruby-0.22.0/client/node_modules/vscode-jsonrpc/lib/messageReader.js:213:45)
at ChildProcess.emit (events.js:187:15)
at maybeClose (internal/child_process.js:961:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
And this message appears several times
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug reportsBug reports
Activity
shir commentedon Feb 21, 2019
Plugin configuration:
wingrunr21 commentedon Feb 21, 2019
Can you post your configuration?
Great thanks!
shir commentedon Feb 21, 2019
@wingrunr21 see above
wingrunr21 commentedon Feb 21, 2019
If you remove the Ruby lint entry does the error resolve? It’s redundant with rubocop and I’m not supporting it in the language server.
shir commentedon Feb 21, 2019
@wingrunr21 yes. Error have disappeared. But have next message in logs and I don't see lint errors:
Is it because of old rubocop version (0.57.2)? I can't use more modern rubocop because this version is last which supports ruby 2.1
shir commentedon Feb 21, 2019
nevermind. Look like it's an issue with asdf which I use as ruby version manager
wingrunr21 commentedon Feb 21, 2019
Ah, mind telling me what the issue is? I'd like to support that if I can
shir commentedon Feb 21, 2019
@wingrunr21 rubocop is run via asdf as a shim. Asdf determine which ruby version to use based on the current working directory and
.ruby-versionfile in this directory. Maybe the issue is that the rubocop is run not within the project directory. Which directory do you use to run rubocop?wingrunr21 commentedon Feb 21, 2019
Is the
.ruby-versionfile in the workspace root? That's where the environment detection spawns a shell to see what the ruby environment should be in that directory.How does asdf expose which ruby to run? Does it modify the environment?
shir commentedon Feb 21, 2019
I made some debugging. Looks like when rubocop is called no environment variable are set. asdf depends on
$HOMEvariable to set asdf data directory but$HOMEis empty and the data directory is set to/.asdfinstead~/.asdf. And it can't find any installed plugins. Theoretically, it may be set via settingASDF_DATA_DIRenvironment variable but I don't know how to set it in this case.In a normal environment, this variable (with other configs) is set via a special script which is called from
.bashrc/.bash_profile.shir commentedon Feb 21, 2019
Could you provide the ability to set custom environment variables for linters? I believe it will also allow to fix any issues with running rubocop with rvm too.
wingrunr21 commentedon Feb 21, 2019
The environment variables need to be whitelisted into the environment detection
wingrunr21 commentedon Feb 21, 2019
HOMEis now whitelisted on v0.22.1. Can you see if that works for you?2 remaining items
wingrunr21 commentedon Feb 24, 2019
Ok, your original issue of
LINTER_MAP[name] is not a constructoris fixed inv0.22.2.Would you mind giving that version another try for your RuboCop linting? I made some additional changes to the environment detection.
If that doesn't work, are you using a shell that's different from your user's default shell?
shir commentedon Feb 25, 2019
@wingrunr21 now rubocop run successfully but I have a error about invalid json. But output json seems legit to me.
If I add settings to enable only lint and rails:
{ "ruby.lint": { "rubocop": { "lint": true, "rails": true, } }, "ruby.useLanguageServer": true, }then I don't have any errors and see rubocop errors in vscode but only a few (2 instead 55 like in json above). Look like not all rules are applied.
shir commentedon Feb 25, 2019
I've outputted error on JSON parse (BTW, I think it will be useful for debugging to show it by default but not only "Lint: Received invalid JSON from rubocop") and get next errors:
Looks like a rubocop output is split into several chunks and is not later combined in one whole.
cameck commentedon Feb 27, 2019
fwiw, I'm seeing the same error as above ^.
vscode-ruby: 0.22.2
rvm: 1.29.3
vscode: 1.31.1
mac os: 10.14.1
It will lint as expected on files with only a few offenses, but when there are many, it throws this error.
wingrunr21 commentedon Feb 27, 2019
Ya, I've traced this to
stdoutbeing chunked back into the node process. I'll have to implement a buffer to the output so the whole JSON response can be parsed at once.[-]Failed on lint with rubocop[/-][+]Long RuboCop output JSON does not parse correctly[/+][-]Long RuboCop output JSON does not parse correctly[/-][+]Long RuboCop/Standard output JSON does not parse correctly[/+]wingrunr21 commentedon Mar 6, 2019
v0.22.3 has the bugfix for this
shir commentedon Mar 7, 2019
@wingrunr21 now everything works as expected. Thank you a lot!
wingrunr21 commentedon Mar 7, 2019
Great! Thanks for all your help and patience working through these bugs!