Closed Fire- closed 3 years ago
I don't get an error, but formatting escapes unicode characters inside strings:
# frozen_string_literal: true
'test'
'No Coverage?'
"\xE2\x9A\xA0\xEF\xB8\x8F No Coverage?"
What version of RuboCop are you using? You can confirm which one is loaded in Solargraph by running Solargraph: Get environment info
from the command palette. My setup uses 0.80.1.
The project we're on is legacy, so currently:
System
Platform: x86_64-darwin18
Shell: /usr/local/bin/bash
Ruby Version: 2.5.1
RuboCop Version: 0.55.0
Solargraph Version: 0.38.6
Core Documentation Version: 2.5.1
Core Cache Directory: /Users/fire/.solargraph/cache
Parser Target Version: 25
Using Bundler: true
platform/shell change ( for rubocup ) when running via docker ( locally / in CI )
I tried again using RuboCop 0.55.0, but haven't been able to reproduce this error.
What setting do you have for files.encoding
in VS Code? (Mine is utf-8.)
Hope you had a good weekend! files.encoding
is utf8
here as well
@castwide I'm unsure if it's directly related, but I managed to cause this same error today by complete accident by copying the output of Pry from VSCode's terminal into a file and attempting to save. It caused the exception and then the server itself spun indefinitely until I restarted the extension host manually.
`encode': "\xC3" on US-ASCII (Encoding::InvalidByteSequenceError)
I then managed to cause it again by selecting the copied output itself and attempting to format it
`encode': "\xE2" on US-ASCII (Encoding::InvalidByteSequenceError)
just like as noted in the original report, adding Encoding.default_external = 'UTF-8'
to the gem's binary in vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.7/bin/solargraph
resolved the issue ( I'd lost it since I had updated )
New env info
System
Platform: x86_64-darwin18
Shell: /usr/local/bin/bash
Ruby Version: 2.5.1
RuboCop Version: 0.55.0
Solargraph
Solargraph Version: 0.39.7
Core Documentation Version: 2.5.1
Core Cache Directory: /Users/fire/.solargraph/cache
Parser Target Version: 25
Using Bundler: true
@Fire- Thanks for tracking that down and reminding me about Encoding.default_external
. I'll add that in the next patch.
The latest version of the gem (0.39.11) sets Encoding.default_external
.
Given a file containing:
unicodetest.rb
Download: unicodetest.rb.zip
Formatting or saving ( with formatting enabled ) causes an exception in the connected language server:
This worked fine "recently", and I'm not entirely sure what caused the regression -- as it appears that this was fixed multiple times prior -- or when, exactly, either. I simply noticed mid-project that my saves were spinning due to solargraph as a format participant, but couldn't locate a source ( as the solargraph server itself continues to run, but no longer responds to messages )
I do not believe this occurred with 0.38.4, but occurs with 0.38.5 ( first noticed ), and 0.38.6 ( updated to verify not fixed )
A "quick" fix seems to be enforcing the default external encoding before an entrypoint, such as in
bin/solargraph
:vendor/bundle/ruby/2.5.0/gems/solargraph-0.38.6/bin/solargraph
However, I'm unsure if that's really the correct way of correcting for something like this.