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

Cannot specify LANG or RUBYOPT, resulting in unintended RuboCop formatting #3091

Open
ogawa65a opened this issue Jan 24, 2025 · 7 comments
Open
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@ogawa65a
Copy link

Description

Ruby LSP Information

VS Code Version

1.96.4

Ruby LSP Extension Version

0.8.18

Ruby LSP Server Version

0.23.6

Ruby LSP Add-ons

  • Ruby LSP Rails

Ruby Version

3.4.1

Ruby Version Manager

rbenv

Installed Extensions

Click to expand
  • azure-dev (0.8.4)
  • black-formatter (2024.4.0)
  • copilot (1.259.0)
  • copilot-chat (0.23.2)
  • debugpy (2024.14.0)
  • flake8 (2023.10.0)
  • gc-excelviewer (4.2.62)
  • gitlens (16.2.1)
  • markdown-mermaid (1.27.0)
  • packer (0.3.0)
  • prettier-vscode (11.0.0)
  • python (2024.22.2)
  • remote-explorer (0.4.3)
  • remote-ssh (0.116.1)
  • remote-ssh-edit (0.87.0)
  • ruby-lsp (0.8.18)
  • ruff (2025.4.0)
  • sql-formatter-vsc (4.1.6)
  • terraform (2.34.3)
  • vim (1.29.0)
  • vscode-azureappservice (0.25.4)
  • vscode-azurecontainerapps (0.8.0)
  • vscode-azurefunctions (1.16.1)
  • vscode-azureresourcegroups (0.10.3)
  • vscode-azurestaticwebapps (0.13.0)
  • vscode-azurevirtualmachines (0.6.6)
  • vscode-cosmosdb (0.24.2)
  • vscode-eslint (3.0.10)
  • vscode-language-pack-ja (1.96.2024121109)
  • vscode-node-azure-pack (1.2.0)
  • vscode-pylance (2024.12.1)
  • vscode-stylelint (1.4.0)
  • vsnotes (0.7.1)

Ruby LSP Settings

Click to expand
Workspace
{
  "formatter": "auto"
}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "featureFlags": {}
}

Reproduction steps

  1. Start the Ruby LSP using VSCode
  2. Open a Ruby file like below
  3. Format Document with Ruby LSP (RuboCop) by issuing VSCode command
  4. It will be formatted into"\u3066\u3059\u3068" although it's expected to be "てすと"

Code snippet or error message

'てすと'

This problem is related to the issue below, and it can be resolved by properly configuring LANG or RUBYOPT. In fact, if I run the command with LANG=ja_JP.UTF-8 /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code, it behaves as expected, but this approach is inconvenient. Is it possible to specify LANG or RUBYOPT? Or is there another solution?

@ogawa65a ogawa65a added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Jan 24, 2025
@ogawa65a ogawa65a changed the title Cannot specify LANG or RUBYOPT, resulting in unintended RuboCop formatting Cannot specify LANG or RUBYOPT, resulting in unintended RuboCop formatting Jan 24, 2025
@andyw8
Copy link
Contributor

andyw8 commented Jan 24, 2025

👋 I'm unable to reproduce this behaviour. What happens if you run RuboCop on the command-line?

@ogawa65a
Copy link
Author

@andyw8 Thank you for your reply!

It depends on the configuration, so how about the following?

$ cat <<EOF > .rubocop_double_quotes.yml
Style/StringLiterals:
  EnforcedStyle: double_quotes
EOF

$ echo "'てすと'" > some.rb

$ LANG=C rubocop --config .rubocop_double_quotes.yml --only Style/StringLiterals -A some.rb
Inspecting 1 file
C

Offenses:

some.rb:1:1: C: [Corrected] Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
'てすと'
^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

$ cat some.rb
"\u3066\u3059\u3068"

Using LANG=ja_JP.UTF-8 instead of LANG=C results in the expected behavior, e.g. "てすと".

@andyw8
Copy link
Contributor

andyw8 commented Jan 24, 2025

Would you mind opening an issue on the RuboCop repo about this? I am not too familiar with extended character sets, and @koic may have a better opinion on the correct approach.

@ogawa65a
Copy link
Author

@Earlopain
Copy link
Contributor

LANG is correctly set to ja_JP.UTF-8 outside of VSCode, right? It is the terminal in vscode that doesn't properly reflect your actual environment?

I would guess so, or at least that extensions don't have access to the real environment. microsoft/vscode#227467 looks very relevant. I think ruby-lsp would need to use such an API and pass the original LANG along to the server.

@ogawa65a
Copy link
Author

@Earlopain Thank you for your help!

LANG is correctly set to ja_JP.UTF-8 outside of VSCode, right?

Yes.

It is the terminal in vscode that doesn't properly reflect your actual environment?

No, in the terminal in VSCode, LANG is correctly set to ja_JP.UTF-8.
It is the execution environment used by the Ruby LSP extension during format on save that doesn’t properly reflect my actual environment.

I would guess so, or at least that extensions don't have access to the real environment. microsoft/vscode#227467 looks very relevant. I think ruby-lsp would need to use such an API and pass the original LANG along to the server.

I agree with you.

@vinistock
Copy link
Member

In general, the Ruby LSP doesn't know about most things configured in the shell, exactly because the NodeJS process running extensions has no knowledge about them either.

microsoft/vscode#227467 will be an incredibly beneficial change, because it might allow us to simplify all Ruby activation and rely on the shell environment instead, which is guaranteed to take into account user configurations.

While that API is not ready for use yet, is there any way you can specify the LANG via some VS Code configuration that would make the editor aware of it? Maybe there's some setting available to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

No branches or pull requests

4 participants