16

When I launch VSCode from the dock, it always complains that

Resolving your shell environment is taking very long. Please
review your shell configuration.

and then a bit later

Unable to resolve your shell environment in a reasonable time.
Please review your shell configuration.

According to this page, Resolving Shell Environment is Slow, the first message is displayed if .bashrc takes more than three seconds and the second is displayed if it takes longer than ten seconds.

I opened a terminal in VSCode and sourced my .bashrc file

dpatterson@dpconsulting$ time source ~/.bashrc
real    0m1.448s
user    0m0.524s
sys     0m0.671s

dpatterson@dpconsulting$ 

As you can see, it takes less than 1.5 seconds.

Environment:

  • MacOS Mojave 10.14.6
  • VSCode 1.53.0

Hopefully someone knows what is causing this.
Barring that, maybe someone can point me to the code that actually generates these errors.

TIA

David Patterson
  • 1,670
  • 3
  • 14
  • 38
  • That's still a really long time to source your .bashrc. Mine runs in sub-second time. A reasonable guess is that the 1.5 seconds plus whatever time it's taking to launch your shell environment (WSL maybe?) + sourcing your bashrc is exceeding the threshhold. I don't see enough info in there to do more than guess, but... maybe move your .bashrc to .bashrc-old and see if that fixes it? If it does, then you know to target your .bashrc complexity. If it doesn't, then it's whatever is happening before (like launching WSL). Or maybe you're memory constrained, etc. etc. – Nicholas Rees Feb 11 '21 at 20:40
  • WSL is definitely not involved. I'm on a Mac. – David Patterson Feb 11 '21 at 23:13
  • Yep. Something in my bash initialization (it _does_ do a lot). Is there any way for my .bashrc to know that it's VSCode starting it up? – David Patterson Feb 11 '21 at 23:19
  • oops. Didn't read far enough down to read that you said mac already. I guess you could do something like adding an if statement in your bashrc to check if the parent pid belongs to VS Code. Or you could set environment variables to pass in depending on if its VS Code or not. But if it were me I'd tend to performance tune what's going on in .bashrc first. Cause waiting even a second and a half would start driving me nuts. My raspberry pi .bashrc excutes in .072 seconds, for comparison. – Nicholas Rees Feb 12 '21 at 00:03
  • Issue is officially being tracked here https://github.com/microsoft/vscode/issues/108804. Hopefully, there should be a fix/patch/workaround soon. – Deepak Rajendran Apr 25 '21 at 05:22
  • 2
    The fix for me ended up being to comment out the nix and ghcup lines from my zshrc (haskell stuff) – Jethro Larson Nov 02 '21 at 22:43

4 Answers4

18

encountered the same situation and find the issue: https://github.com/microsoft/vscode/issues/113869#issuecomment-780072904

I extract nvm load code to the condition function ref in the issue, solved this problem:

function load-nvm {
  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
  [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  [[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
}

# nvm
if [[ "x${TERM_PROGRAM}" = "xvscode" ]]; then 
  echo 'in vscode, nvm not work; use `load-nvm`';
else 
  load-nvm
fi

Hemisu
  • 181
  • 3
4

Open VS Code from a terminal:

code .
iconoclast
  • 19,365
  • 11
  • 98
  • 131
3

Restarting VSCode on BigSur works for me.

You can also check your user settings to make sure it matches the path of the shell that your terminal uses.

Check https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch for other troubleshooting steps.

JoshX
  • 31
  • 4
  • Happened for me after a system update. VSCode was open on reboot, so it restarted it, but apparently not correctly. Restart VSCode solved the issue, as stated. – rickb Nov 03 '21 at 21:13
  • 3
    I had to close VSCode, restart my Mac and then open VSCode, then close it and reopen it again before it started working properly. But it is now working. Don't give up fellow restarters - if at first you don't succeed, restart, restart, restart again! – Geoff Davids Nov 11 '21 at 17:56
0

In Linux, you can open "alacarte" and make a new shortcut with the command "code" and click the box "Open in a terminal".

enter image description here

Jeremy Caney
  • 6,191
  • 35
  • 44
  • 70