run file in browser from vscode - visual-studio-code

just installed vscode and I'm missing a trick which I think should be obvious but I just can't seem to find the answer.
I run apache as my local test server. When I'm in vscode and have a root folder open I would like to be able to send any file I'm editing to my browser and use the root folder name + relative path to file in the url sent to browser.
so what I actually want to send to browser is full url :
http://localhost/current-root-folder-in-vscode/relative-path-to-file
the file could be the open open one or one listed in vscode explorer which is not open.
suggestions much apprceiated.
p.s. I have searched possible vscode extensions and haven't found anything that seems to do it.

Fixed. I edited View-In-Browser extension locally to make it work the way I want.

Related

Renaming files doesn't take effect in VScode while using WSL2

I have a very annoying problem in my VScode setup.
I'm using WSL as a terminal to work on my projects and occasionally, mistype the name of one of the folder or file that I'm working with.
For example:
I accidentally created the Mainheader.js file in layout folder (without the capitalized L) therefore, I decided to rename the folder with a capital L.
Now on my React app, any changes made to MainHeader.js file will not be reflected. I did update the related import.
So I decided to delete the entire folder and recreate it with MainHeader.js but this is what I end up with.
The file is there in my folder but when I click on it, I get
"Unable to open Mainheader.js - File not found"
So I try to create it then I get this error:
Unable to create file 'wsl\path]to\MainHeader.js' that already exists when overwrite flag is not set
Has anyone run into this type of behavior in WSL before? It's quite annoying because the only workaround I've found so far is to create a completely different folder with a different name...
Any help would be appreciated. I can't really work like this.
I've been having the same problem for the past 2 days. I presume its a permissions issue, but unfortunately I don't know how to permanently fix it.
I did find this work-around though:
Open a new VS Code window. (I'd recommend closing any VS Code window that had
your project directory open.)
Create a duplicate or copy the contents of the problem file so you don't lose
your code.
Delete the problem file.
Now create the file again using VS Code. Go to File > New Text File. Next paste
in your code.
Now save your new file. Go to File > Save As and save your new file with at the same path + filename + extension that was giving you problems previously. VS Code should allow you to save the new file without any issue.
Now you can open this new VS Code window to your project directory and you should be able to continuing accessing the file that was a problem before.
Basically we just deleted the problem file and then created it again from scratch in a new VS Code window.
Hope this work-around works for you!
EDIT 09/20/2022
Following Baza86's answer here solved the issue for me. Seems like it was a permissions issue of sorts, but if you use the Remote-WSL extension VS code can directly access the linux filesystem.
How to run VScode in sudo mode in WSL2?
You may need add the case option to you options in the wsl config. The default is set to off, however you can set this to off, dir or force.
Open your wsl.conf using sudo with any text editor while running window subsystem Linux. The config file resides in /etc/wsl.conf. This file is used to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.
My default config looked like this yours may be different:
[automount]
options = "metadata"
add
[automount]
options = "metadata,case=dir"
Here is the official Microsoft docs for Advanced settings configuration in WSL - https://learn.microsoft.com/en-us/windows/wsl/wsl-config

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 come I can't open my .html with Live Server in VSCode?

I installed Live Server in VSCode for the first time and am trying to open an .html file with Live Server. I'm following the simple instructions provided here on the official installation page, but to no avail.
I right-click my file in the Explorer as instructed, but "Open With Live Server" doesn't show. I've even tried right-clicking the tab and that doesn't work either. I've quit and re-started VSCode and that didn't work. I set Chrome as my default browser in settings.json and that didn't work. I double checked to make sure Live Server is installed and enabled globally and it is. Please help me figure out what's going on! Thank you!
Oh! I figured it out. I had to open my file by selecting "Open Folder" and then open my folder from there. Then I was able to select my file under the Explorer tab and right-click to open with Live Server. I'm not sure why it worked that way.
It's happened to me few times. My problem was the folder and files names.
Check those names and don't use spaces or weird characters.

Trying to download some python scripts from PythonAnywhere to my computer but it keeps opening another browser tab instead

I have some python scripts on PythonAnywhere.com that I am trying to download into my computer. Whenever I click the download icon next to the file, it opens into another web tab (Chrome) instead. I'm not sure what I did that caused this because I've been able to download files to my computer for the last couple of weeks but suddenly I cannot. Any help would be appreciated - thank you.
Use your browser right-click menu on the download link to save the file to your disk.

VSCode looking for file in wrong directory

I'm working on Laravel project. When I want VSCode jump to class's file in vendor, just got issue that it can't open file in correct location.
My working directory is C:\wamp64\www\merchant but VSCode try to open the file from C:\wamp64\www\wallet
My question is that is there anyway to tell VSCode the correct working directory?
delete folder .phpls (~/.phpls or %USERPROFILE%\AppData\Local\PHP Language Server\ on Windows)
is the way to clear VSCode PHP extension server cache.