VSCode restore file from tmp file - visual-studio-code

I Accidentally discarded some changed files in VScode and lost alot of work. I believe I have found them saved as tmp files in the
/users/appdata/local/temp/1 directory, but when I try to open it's just symbols/binary encoding that I am not familar with. These were typescript files with the extension .tsx...when I open with VScode or notepad I just see the wierd symbols which I believe are binary encoding.
Is there a way to restore the temp file to a text or typescript file???

I had a similar problem just now and I just renamed the file, changing the extension from ".tmp" to ".cs" and it worked, I lost a few lines of code but it was fine.
I don't know if this will work for every case though.

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

Inspect at see why prettier ignores one file (that is not listed in the .prettierignore)

Prettier seems to be working just fine for all other files except this one file that I can't format without forcing it.
Tried with npx prettier --write . and the vscode extension format with... The only way to format the file is to Format with (force).
Is there a way the inspect why a file is ignored by prettier?
Why is Prettier not formating one of the .ts files? the file is only 700 lines so don't think its a speed issue.

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.

VSCode is appending unsupported text encoding on file save

Not sure what's up with VSCode after updating to Version 1.10.2 VSCode is appending weird characters automatically after saving the file.
If I try to open the file with VSCode I get the following error.
The file will not be displayed in the editor because it is either binary, very large or uses an unsupported text encoding.
This only happens sometimes, not on every single save to disk action.
I'm using a SAMBA share, not sure if that has something to do with it.
I'm on MAC 10.12.3
** Update 3/16/17 **
Here is a gif of how it's happening.

VS Code open last files

I gave a chance to Visual Studio Code as my primary editor. I had been using Notepad++ and afterwards I have been using Sublime Text 2 and 3 for few years. I do see potential of this editor and I really like it, but there is one thing I am strongly used to.
Notepad++ and Sublime Text has this feature, I can edit file and DON'T save it anywhere. After restart Notepad/Sublime Text this file is there ready for me.
Other workflow could be open any file from my local storage, close VS Code and start it again. This file will not open!
I know about that when I open folder and restart VS Code, folder is open and files as well. But is there any way how can I manage to have opened files after restart without having opened folder?
Edit: This is now implemented:
// Controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.
"files.hotExit": "onExit"
I use the insider release, and in the current version (1.3.0), vscode doesn't keep unsaved file. I think there is a feature request for that.
Got it: https://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8568343-keep-unsaved-files-after-crash
You can vote for that feature, like I did !
On the other hand, You can tell in settings if you want to re-open previously opened folders, but not files.
"window.reopenFolders": "all"