oleg-shilo / Favorites.vscode

VSCode extension for managing Favorites
MIT License
23 stars 6 forks source link

Favorite local files in a remote session cannot be opened #31

Closed carlfriedrich closed 2 years ago

carlfriedrich commented 2 years ago

I am working with VS Code on Windows connecting to a Linux machine via the remote SSH extension. Adding remote files to favorites works fine (e.g. /home/myuser/notes.txt). When I open a local file in VS code (e.g. D:\notes.txt) , I am able to add it to the favorites and it appears in the favorites list. But I cannot open it it via the list afterwards. Nothing happens when I double-click on the file. Is it possible to add support for favoriting local files as well?

oleg-shilo commented 2 years ago

Which version of the extension are you using? In the last prerelease there is some experimenting "open path" code that needs to be rectified.

If it is an older version then local files are supposed to work just fine. But let's check what version you are on

carlfriedrich commented 2 years ago

Thanks for the quick reply. I installed the current version from the marketplace, which is v1.5.8.

oleg-shilo commented 2 years ago

Hm...

I am working on this issue https://github.com/oleg-shilo/Favorites.vscode/issues/29 It is about opening folders in new window. in the post https://github.com/oleg-shilo/Favorites.vscode/issues/29#issuecomment-1018419903 I have shared unexpected sides of the vscode.open API. Quite possible you are also a victim of this. I.e. if the file is already open.

You see, opening local files was a default use-case from the very first release of the extension. As you can see it below:

favs_31

I suggest you repeat your test again after closing all VSCode windows, files and folders. Just to eliminate any unknowns.

carlfriedrich commented 2 years ago

I closed and re-opened VS code. This is how it looks like for me (notice the difference between the remote file and the local file):

Animation

oleg-shilo commented 2 years ago

your default.list.txt looks strange.

Two paths that you have there do not make sense together. I mean on Linux notizen.txt does not exist and if you are on windows then it is /home/tim.jacks/.profile that is invalid.

one path is expressed as win filesystem path and another as a linux one.

Any chance you have WSL extension is active? If it is the case then VSCode will be doing some magic by reconciling two subsystems under the hood. And then does not do it back when you try to open a file by its path.

When you click and to favs button, the extension simply asks the editor "give me the name of the current opened file" and then saves it in the default.list.txt
When you click the new node on the tree the same file path is passed to vscode open and VSCode does not like it. :( Basically:

// pseudocode
var file = vscode.currentdoc.path;
// close the file manually
vscode.open(file) // does not work
carlfriedrich commented 2 years ago

Yes, that's true, one is a Windows path and one is a Linux path. As I wrote in my first post I am using remote SSH (so not WSL but an actual Linux machine).

When I am connected to my Linux machine in VS Code, Linux file paths are used. However, I can still open local files from my Windows machine, e.g. using drag & drop from my Windows explorer to the VS Code window, resulting in local files and remote files being opened side by side in one single VS Code window. The same is possible if I click on the "Show local" button that appears when I call File -> Open File.

So if VS code basically can open local files in a remote session via the UI, I assume it should have some internal API call to open these local files programatically as well, doesn't it?

carlfriedrich commented 2 years ago

I did a bit of research and testing and found out that the following works for opening a local file:

const file = "vscode-local:///Y:/aktuell.txt"
commands.executeCommand('vscode.open', Uri.parse(file));

In your code I found:

commands.executeCommand('vscode.open', Uri.file(file));

Which only differs in Uri.file(file) instead of Uri.parse(file). With the former, the vscode-local:// prefix does not work. Would it be an option to change this in your code? Or will this possibly break something? Remote files still work with Uri.parse(file) in my case.

oleg-shilo commented 2 years ago

Great. Thank you. This is exactly what was that missing puzzle piece

What you are saying makes sense. Since your vscode instance is in remote mode. Then it opens the remote file via uri capturing the raw path natively and the local file via the URI with the scheme vscode-local.

I tested it and indeed this scheme works just fine. But... only if VSCode is in the remote connection mode. And of course, in the normal/local mode vscode-local scheme is not valid.

let file = "vscode-local:///d:/test.cs";
commands.executeCommand('vscode.open', Uri.parse(file));

It always throws the exception: image

Though it is OK as it can be controlled at the time of the creation of the list item (add method) by preserving the schema in the path.

This is my default list in the remote connection mode: image

All good. Now I need to pack it all and retest #29 and we are ready to release.

carlfriedrich commented 2 years ago

Great, thanks a lot for taking care of this!

oleg-shilo commented 2 years ago

And thank you for helping with that scheme vscode-local