PlatformIO Toolbar not showing up in VSCode - visual-studio-code

As seen in the picture: I have PIO installed and active, but it don't shows it's toolbar for uploading the project. Yesterday a simple restart of VSCode fixed it, today nothing changed after a lot of restarts. https://i.stack.imgur.com/Xc63R.png

In case someone else comes upon this. I had a similar problem. It is more a workaround than a solution. (I'm running VSCode on Ubuntu)
{ctrl+alt+t} #Open a terminal
$ cd {folder location} #Change directory to the location where your src folder and platformio.ini file is located
$ code . #Launch VSCode from the terminal window
My icon to upload and launch serial monitor now show on the bottom.

Related

Error loading webview: Error: Could not register service workers: TypeError: Failed to register a ServiceWorker for scope

When I update my VSCode to v1.56.2 and open webview, I get these messages:
Error loading webview: Error: Could not register service workers:
TypeError: Failed to register a ServiceWorker for scope
('vscode-webview://867f875b-c5a3-4504-8de2-2e8614bdc0f8/') with script
('vscode-webview://867f875b-c5a3-4504-8de2-2e8614bdc0f8/service-worker.js?platform=electron&id=867f875b-c5a3-4504-8de2-2e8614bdc0f8&vscode-resource-origin=https%3A%2F%2F867f875b-c5a3-4504-8de2-2e8614bdc0f8.vscode-webview-test.com'):
ServiceWorker cannot be started.
How can I solve this issue?
If you are using Ubuntu, there is probably another (maybe hidden) vscode process, which is causing the problem.
Close the vs code first and in terminal try: killall code.
In Windows, you can simply fix this error by clearing the cache for VSCode. Please follow the steps below:
Close VSCode and also kill any background processes running in the task manager.
Go to the file explorer and to the path C:\Users\<user_name>\AppData\Roaming\Code and clear the contents of the folders Cache, CachedData, CachedExtensions, CachedExtensionVSIXs (if this folder exists) and Code Cache.
Open VSCode and you are good to go.
I encountered this issue and am not a Windows user, so this is my resolution:
I found that there was an instance of VS Code open that was erroneously not shown on my dock. I closed this instance and opened a new instance. The problem was gone.
I think the issue happened because I had a VS Code instance open, allowed a software update to run in the background, postponed the restart, opened a new and updated VS Code instance, and the old instance remained open causing conflicts.
OS: Ubuntu 20.04.2 LTS
#tritemio on GitHub has a great answer:
https://github.com/microsoft/vscode/issues/125993#issuecomment-912439561
in short, delete cache folder:
rm -rf ~/.config/Code/Cache
This is a known bug in VS Code 1.56. It happens for some Windows users when running VS Code as an administrator
As a workaround, you can try launching VS Code with the --no-sandbox command line flag:
$ code --no-sandbox
#tritemio, thanks for sharing.
This also seemed to solve my issues on Windows for "Extensions - Details View", "VS Code Release Notes View", "Gitlab integrated Interactive Rebase Editor", etc.
I followed your suggestion and deleted the following folders;
%appdata%\Code - Insiders\Cache
%appdata%\Code - Insiders\Code Cache
On *nix systems, first close VS Code app then run pgrep -f '/Applications/Visual Studio Code.app' | xargs kill to clean up vscode's processes. Reopen vscode and the issue will be gone.
If on macOS, you can run the above command verbatim. If you're not on macOS or installed vscode on a different location, you need to change the argument passed to pgrep. You can run ps auxww | command grep -i --color code to find the path of vscode's running processes.
Happened to me when started code in windows cmd. Closed vs code and opened it from my taskbar shortcut instead, and the error was gone
The simplest solution for this problem in any version of Linux is simply to close other instances of VS code and use only one instance of VS code.
OS: Linux 20.04.3 LTS
I've also encountered the same "Error loading web view" Error.
I've solved this issue by moving "vscode.app" into "Application folder" instead of "Download folder" on macOS.
I'll describe my "symptom" here.
OS: macOS 12.0.1
Installed 2 versions of vscode somehow, 1 under "Application folder", another under "download folder"
Run both vscode at the same time, the "download folder" version has no error display plugin pages, the "Application folder" version has the "Error loading webview" error
Checked and see 2 vscode instances running in the background
What I tried to solve this issue:
Tried to kill "download folder" instance, and the error remains for "application folder" instance
Moved "download folder" to "application folder" and both vscode works correctly on plugin page!
What I suspect on what the problem is?
Maybe these 2 vscode are sharing the same resource(could be some shared file), however they have different permissions since one is under application folder and another is under download folder.
This answer applies if using VSCode in GitHub Codespaces in Firefox or Brave browsers. I had to disable "Enhanced Tracking Protection" for the site, and that is all. To do so, click on the shield icon which is to the left of the displayed web address.
If anyone is using Brave, please turn off the brave shields as well.
For Mac/Apple computer Monteray version the following steps worked for me:
Delete VSCode from downloads folder.
Turn off VSCode
Open Activity Monitor and delete VSCode "Code" process.
Try closing all the process cmd+qof vscode and reopen vscode and everything should work well.
I have just restarted VS code and it worked for me. OS was Windows 10.

Not able to open VS Code from Terminal in my MacBook BigSur11.3.1

Good day community. I have installed VS Code in my MacBook Air M1 chip running on BigSur 11.3.1 but whenever I set the code command in PATH (using Command+Shift+P) it only appears to be working for current session and doesn't work if I restart VSCode. I have to set the code command in PATH again. Please help me in configuring code command permanently so that i can open VSCode from any directory whenever I want. Thanks
I think I have got the solution. After installing VSCode in your Mac (which will be in download folder) move VS Studio Code.app file to Application Folder and then again install the code command in PATH from VSCode(using Command+Shift+P) and thats it.

VSCode complains that resolving my environment takes too long

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
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
Open VS Code from a terminal:
code .
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.
OSX Work-around
Background
If VS Code is started via an OSX (or Linux) GUI interface and there's a shell rc process that takes more than 10 seconds to complete during start-up (e.g. nvm) VS Code simply stops trying to start-up that shell.
Work-around
The two known solutions are to either get rid of the process that takes more than 10 seconds or start VS Code from the command line (i.e. code .).
This work-around is for those of us on OSX who —for whatever reason— explicitly don't/can't get rid of the 10+ second process and who —again, for whatever reason— start VS Code via the GUI.
While the following is less desirable than VS Code just having a configuration that we can change, it's still better than having to remember to run code . from the terminal, and it's much, much better than not using nvm (or switching to an alternative).
Note: The file extension does need to be changed between .command and .app several times — this is not a mistake! ;)
Create a new file with the following:
#!/bin/sh
code .
Save the file with a .command extension in your "Applications" directory, e.g. ~/Applications/vs-code-cli-starter.command.
In a terminal, change that new file's permissions:
chmod +x fileName.command
From Finder, right click-on your new app/command and select "Get Info", then repeat with your actual VS Code application.
Drag the big icon from the "Preview" section of the actual VS Code's "Get Info" to the small icon in the upper-left of your newly created app/command's "Get Info".
Close the two "Get Info" panels.
In the "Applications" directory, update the file extension from .command to .app, e.g. vs-code-cli-starter.app.
Drag the newly created app's icon to your dock.
In the "Applications" directory, swap the file extension back from .app to .command, e.g. vs-code-cli-starter.command.
Enjoy
For Linux:
if [[ "$VSCODE_PID" = "" ]]; then
echo "slow or blocking operations"
fi
Thanks to Hemisu's answer.
For those who uses zsh, .ohmyzsh and powerlevel10k prompt:
Get all your exports EXCEPT export ZSH= and nvm stuff and put them in the bottom of .zshrc file.
Insert this line at the top: if [[ "$VSCODE_PID" = "" ]]; then
Before your exports at the bottom, insert an fi (end if)
Now, all your ohmyzsh, nvm and ohmyzsh themes are not loaded when VSCode initializes (the built in terminal still works fine, with ohmyzsh).
In my case, outside that if/fi there is only exports for PATH, LDFLAGS and CPPFLAGS.
Thanks to M Imam Pratama answer.
In Linux, you can open "alacarte" and make a new shortcut with the command "code" and click the box "Open in a terminal".
Go to project location and open with code . in terminal (if you are in linux) or cmd (if you are in windows.) That should resolve this issue.
When directly opened from vscode app it happens, even I have faced this.
it's a very common error or we can say complain by vs code
so here is the solution - do not open vs code directly from its icon or directly from application instead you can do is just open vs code from terminal/cmd obviously for linux/windows respectively by typing this command -> $ code .
if this command is not working then reinstall the vs code and check all the boxes before installing it will also allows you to open vs code from folder directly by clicking right side of mouse and just click open this folder with other application and select vs code.

How to change folder that opened by default in VSCode?

I have small problem with VSCode folder, that opened by default.
Problem description: I start new instance of VSCode (trough File->New Window), and then if I choose File->Open Folder it opens dialog with my Windows user folder as starting point (C:\Users\MyUser)
Question: How can I change that folder in settings (if it possible)? So by default it will show as start point for example D:\development\ ?
At the time I write this answer, this is not possible. There are two problems on Windows, and one problem on Mac and Linux:
VS Code does not provide a default path to the file dialog 1. It does remember the last folder that you opened a file in, but that path cannot be used as a default because it is overwritten constantly.
On Windows only, Electron ignores the default path when creating a file dialog if the default path is a directory 2.
An extension also cannot solve this, because extensions are not allowed to modify the File menu 3.
I think the best option at this point is to pin a folder to the Quick Access area in Windows Explorer, as suggested in a comment, or to put an actual shortcut in the user profile folder.
Workspaces and File > Open Recent may also be helpful if you often open the same folders.
Your main problem is that you are unable to open your specific folder in VScode.
To solve that you can simply open the terminal/cmd in that specific window by just typing cmd in your search bar or just by pressing shift+right-click in that folder.
Now your cmd is open and you just have to type "code ." in the cmd and press enter to open the current folder in your VSCode.
In case that code . doesn't work for you then you have to add the Vscode in the environment variables of your windows.
Visual Studio doesn't provide a specific feature to open a specific path. But there is a solution to your problem. You are saying that you want D:\develpment as a default when you open VS Code. You can go to that specific directory or create shortcut to desktop then click right click on that folder and then click on open with code. If you didnot see open with code then reinstall your VS code and check on open with code when you are reinstalling VS Code.
make a shortcut on the desktop for vscode and then modify it and add the folder after the .exe command. This will default open that folder when you double click on it.
Visual Studio Code can be installed in two ways - User setup and System setup. I strongly believe you have User setup installed in your PC. Try re-installing it System-wide. That should probably fix your problem.
For more information: https://code.visualstudio.com/docs/setup/windows#_user-setup-versus-system-setup
PS: A lot more information is needed, you can share a screenshot of the window and elaborate more on it.

How to open folders in VSCode via Terminal in a fresh state?

It appears that VSCode always opens a folder in with the last UI state it had.
I'm looking for something like Sublime's remember_open_files: false, or in other words, I would like VSCode to open up with a clean UI state regardless of what state the UI was in the last time the folder was open.
What's happening now:
cd my-project-folder/
code .
# VSCode opens folder with saved UI state
What I want:
cd my-project-folder/
code .
# VSCode opens folder with fresh UI state
I tried to do it through command line using the command
code -n .
which should have opened VS code in current folder with a new session but it does not seem to work at all. I believe that code . seems to ignore the -n new session option and restores the previous session for the folder. So this feature is probably not implemented in VS code.
(Refer here for the commandline options for VS code.)
this is the command that works for me on windows
code -r .
From inside VS Code built-in terminal, cd into your project folder/directory and enter command:
code -a .
Note period at end.
This will open your current directory/project folder without opening a new window.
Part of the answer on this thread worked for me. Basically, make sure VSC is in the Applications folder. Then open the Command Palette (F1 or ⇧⌘P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart Visual Studio Code if it's open. In terminal, navigate to the folder you want to open in VSC, and type code .. Hopefully it should work for you.
If you are using a Mac, you need to first install the VSCode command amongst the shell command list.
Do this:
Open VSCode
press CMD + SHIFT + P
type shell command
select Install code command in path
navigate to any project from the terminal and type code .
code . opens VS Code at the current terminal folder
If you are using VS Code [Version: 1.50.0] then open your command prompt and go to your project's directory and just run the command:
code -a .
i.e. [Also can see the photo]
[1]: https://i.stack.imgur.com/sMmkH.png
$ code . --user-data-dir=.
This will open Visual Studio Code in current working directory. I use Bash with Ubuntu 16.04LTS.
I am using VS Code Version 1.24.1 (As of the time of original posting).
If you want to open a folder through the terminal, you can execute the command:
code -n name_of_your_folder/
or
code -n path_to your_folder/
Same thing goes for a file, and these open VS Code in a new window.
Also, note that you should have VS Code installed.
You're welcome!
I checked through all of the settings available in the VSCode preferences for me, and I don't think there is a way to do this.
There are some settings related to what VSCode window instance that folders will open into, but nothing that seems similar to Sublime Text's remember_open_files setting.
The closest thing I found was running code --user-data-dir . (feel free to replace . with some other directory so you don't pollute your current working directory) from the terminal to specify that VSCode shouldn't remember ANY previous settings, but this seems like overkill for what you're trying to accomplish (as VSCode will literally run as if it's the first time it's being run after a fresh install).
EDIT: I just discovered a View: Close All Editors command in the command palette (CMD + SHIFT + P). The keyboard shortcut for OSX is CMD + K, CMD + W, and this will close all the files you have opened!
I have the same problem on Mac.
I solved it in the following steps:
I opened the "Command Pallete" on the VSCode. This can be done by CMD + SHIFT + P
Type "shell"
Click on 'Install code command in path'
Give an administrator password
You will get a message that it has been installed
Now run "code ."
NB: Make sure you already cd into the folder you want to open before you run code .
If you want to open folder with vscode, you just go to folder ( you can user terminal or file explorer) with terminal, and do "code ."
To get the right folder in VS Code v 1.50.1 Terminal I tried a lot of options which didn't work for me. At the end I found very easy solution. I went to File->Open Workspace and found that my Workspace had the wrong folders inside it, which I simply deleted (from Workspace only!). Then I opened the folder I needed in my Workspace, opened Terminal->New Terminal, and everything worked perfectly well. Please let me know if this will work for someone else.
This command works to open a specific folder in VS code using terminal
code -r Documents/VS/C++/
here -r switch is used to open a file or a folder in an already opened VS code window
and then you specify the path of the file or folder you want to open
if you want to open it in a new window use -n switch instead of -r
This works for me with VSCode on Linux:
cd path/to/project
codium .
I tried every mentioned answers, what's work from me is this:-
I created a shell script to open folders.
$ sudo nano /usr/local/sbin/code2
/usr/bin/code-oss -n --user-data-dir '/home/myusername/.config/Code - OSS2/' -a $#
$ sudo chmod +x /usr/local/sbin/code2
You can remove --user-data-dir '/home/myusername/.config/Code - OSS2/' from the script if you want to use default code-oss config folder.
When I want to open a folder, I use the command like this :-
$ code2 .
I add this command code2 to open with option thunar to open folders directly from files manger.
Go to the directory in the command pallet on your computer the navigate to the the specific folder using cd
the type code . and that will open the folder and the files in it inside vs code. works like a charm.
If Visual Studio Code is installed using flatpak then a bash alias can help launch the application from the terminal.
alias code="flatpak run com.visualstudio.code"
I did it a simpler way just by three steps. I am currently in a project folder and want to open another folder in vs code using the cli or terminal. What I first did is navigated in the folder which I wanna open in vs code inside the terminal. Once I m inside that particular directory or folder I simply typed the command :
start code .
This will open that directory or folder in a new vs code window.
The complete process is :
open the terminal is vs code
navigate to the folder u want to open
once u r inside that particular folder type the command :
start code .