rubyide / vscode-ruby

Provides Ruby language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby
MIT License
1.26k stars 285 forks source link

unable to execute bundle exec rubocop and reek, but the same commands work in terminal #816

Closed Juraci closed 2 years ago

Juraci commented 2 years ago

Your environment

Expected behavior

this should work from inside the editor

Lint: executing bundle exec rubocop -s '/home/juraci/personal/wy-cash-tdd/lib/money.rb' -f json...
Lint: executing bundle exec reek -f json --stdin-filename '/home/juraci/personal/wy-cash-tdd/lib/money.rb'

Actual behavior

Lint: unable to execute bundle exec rubocop -s '/home/juraci/personal/wy-cash-tdd/lib/money.rb' -f json as the command could not be found
Lint: unable to execute bundle exec reek -f json --stdin-filename '/home/juraci/personal/wy-cash-tdd/lib/money.rb' as the command could not be found

Executing the same commands manually in the terminal against the same file does work: rubocop screenshot_20220424_192233

reek screenshot_20220424_192316

my settings file:

{
  "vim.easymotion": true,
  "vim.incsearch": true,
  "vim.useSystemClipboard": true,
  "vim.useCtrlKeys": true,
  "vim.hlsearch": true,
  "vim.insertModeKeyBindings": [
    {
      "before": ["k", "j"],
      "after": ["<Esc>"]
    }
  ],
  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["<leader>", "d"],
      "after": ["d", "d" ]
    },
    {
      "before": [
        "<C-n>"
      ],
      "commands": [
        ":nohl"
      ]
    },
    {
      "before": [
        "K"
      ],
      "commands": [
        "lineBreakInsert"
      ],
      "silent": true
    }
  ],
  "vim.leader": "<space>",
  "vim.handleKeys": {
    "<C-a>": false,
    "<C-f>": false
  },
  "workbench.colorTheme": "One Dark Pro",
  "ruby.useBundler": true,
  "ruby.useLanguageServer": true,
  "ruby.lintDebounceTime": 3500,
  "ruby.lint": {
    "rubocop": {
      "useBundler": true
    },
    "reek": {
      "useBundler": true
    }
  },
  "ruby.format": "rubocop",
  "workbench.iconTheme": "material-icon-theme"
}
Juraci commented 2 years ago

Update, I think I figured it out. The way you start vs-code matters, at least in my case.

Starting vs-code from a launcher like dmenu or rofi by typing code causes the problems described in my issue.

If I instead open vs-code in the terminal by:

  1. cd to the project directory cd /home/juraci/personal/wy-cash-tdd
  2. then in the terminal I run code . (to open vscode with the current project)

Then vscode-ruby work as expected with rubocop higllights and reek suggestions.

Looks like vs-code inherits the environment where it was initiated, so launching the vs-code process from the terminal with the login shell it "just works". Launching from dmenu or rofi it doesn't.

noniq commented 2 years ago

It could be related to the shell that is used to run subprocesses. I recently stumbled upon a similar issue in https://github.com/castwide/vscode-solargraph/issues/238 , where it uses the system default shell (zsh) to run subprocesses, but the setup for my Ruby environment is in the init files of bash (because that’s the shell I use personally). And, as mentioned in the original issue, starting VSCode from the terminal makes it work, because then it inherits ENV["SHELL"] which is set to bash.

github-actions[bot] commented 2 years ago

This issue has not had activity for 30 days. It will be automatically closed in 30 days.