oleg-shilo / Favorites.vscode

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

Loading a Workspace from Favorites loads the folder and not the VS Code Workspace #28

Closed ratkinson-prh closed 2 years ago

ratkinson-prh commented 2 years ago

If I load a workspace file (*.code-workspace) from Explorer, VS Code shows it's a Code Workspace in the explorer. The workspace name has '(Workspace)' next to it.

If I load the same workspace from the Favorites tab, the folder is loaded, not the workspace file. VS Code also pops up a warning that a workspace file is available, and do I want to load it.

I'm running VS Code v1.63.0 and Favorites v1.5.6

oleg-shilo commented 2 years ago

It is a very interesting problem that is difficult to understand.

I am using the same VSCode and the same extension and it does work as expected. Just in case I went step by and indeed the workspace file is detected and opened. Though...

I noticed that the command that is executed is vscode.openFolder, which opens the workspace file if it is passed as a command parameter: https://github.com/oleg-shilo/Favorites.vscode/blob/918c8c02afd5a30a21ffe950b0986e643e4331b1/src/extension.ts#L246

When I have implemented this feature first time only vscode.openFolder was working. And in fact, it still does, at least for me.

Anyway, I have tried to use the more generic command vscode.open and... it works too.

And since vscode.open is a more natural API fit I prefer the change (https://github.com/oleg-shilo/Favorites.vscode/commit/8fca5d8b9fb1a8a0f5c23aafe6f4168480661d47) to go into the extension codebase.

But can you please test it before I build the patch? This is the pre-release for you to test

ratkinson-prh commented 2 years ago

Hi Oleg. I've downloaded and installed the 1.5.7 pre-release, but I'm still getting the same outcome as before. Would it be useful to record something for you so you can see exactly what's happening? Maybe you'll spot a difference between my environment and yours.

ratkinson-prh commented 2 years ago

I've just installed this extension, which is effectively a simplified version of your 'openFolder' code - https://github.com/auchenberg/vscode-open-file-folder

It doesn't appear to be working on my laptop either, so I took a look at the VS source code. I'm not convinced you're using the correct function though (my knowledge of VS internals is very limited, I would add). I think you should be using workbench.action.openWorkspace()

The reason I say that is if I use 'Open Folder' from the VS Code File menu, it opens the folder and not the workspace, exactly as your code does. If I use 'Open workspace from file', it ultimately opens the workspace. That menu command appears to use openWorkspace() and not openFolder().

ratkinson-prh commented 2 years ago

After some tests and trials, this code works as expected :-

var cmd = vscode.commands.registerCommand('extension.openFileFolder', function (e) {
    let folderName = path.dirname(e.path);
    let folderUrl = vscode.Uri.file(folderName)
    folderUrl = vscode.Uri.file(path.join(folderUrl.fsPath, "TEST.code-workspace"))
    vscode.commands.executeCommand("vscode.openFolder", folderUrl)

Basically, despite what the API documentation says, it appears you have to pass the workspace file in the openFolder() command.

I've logged #139010 with the VS Code community to see what they think, but would be nice if you can add code to your extension to scan for a valid workspace file and pass that as part of the path if one exists please.

Thanks, Rob.

ratkinson-prh commented 2 years ago

I've just gone back to your code, and I can see open_path() is already trying to append the workspace file to the URI :-

let workspace = Utils.get_workspace_file(path);

Is there a bug in that code somewhere that's not returning workspace properly?

oleg-shilo commented 2 years ago

Yes, this is the code that is supposed to find the workspace file. I could not make it fail, even though you could. This is the implementation:

static get_workspace_file(folder: string): string {
        let result = null;
        fs.readdirSync(folder).forEach(fileName => {
            if (result == null && fileName.endsWith(".code-workspace"))
                result = path.join(folder, fileName);
        });
        return result;
    }

If it does not detect workspace file then it will open the folder.

Is it possible you have *.CODE-WORKSPACE instead of *.code-workspace?

ratkinson-prh commented 2 years ago

To answer your question, they are all lowercase...

U:\WindowsPowerShell\Powershell Projects\Scratch Area>dir *.*work*

 Directory of U:\WindowsPowerShell\Powershell Projects\Scratch Area

25/11/2021  10:53                43 Scratch Area.code-workspace
               1 File(s)             43 bytes
               0 Dir(s)  117,379,207,168 bytes free

U:\WindowsPowerShell\Powershell Projects\Scratch Area>

I've spent the day trying to get a Typescript development environment up and running so I can try and debug the problem myself outside of VS Code, but it's being annoying and not finding the modules in the node_modules directory properly.

Do you want to generate a VSIX with some debugging in that I can run?

oleg-shilo commented 2 years ago

Debugging VSIX is stright forward and ironically much simpler by running the extension ib VSCode compared to running any custom builds. You can just clone this repo, open the folder in VSCode, place breakpoint and press F5.

Though I have a suspicion that the latest release might be fine in your environment. There is a good chance it will address your problem as I found it difficult to see what can go wrong. :) How many times have we all heard that.

ratkinson-prh commented 2 years ago

Hi Oleg. I've run the extension in debug with this small change...

let workspace_file = Uri.file(workspace)
commands.executeCommand('vscode.open', workspace_file, newWindow)

The (Uri object) value of workspace_file is...

 {
  scheme: "file",
  authority: "",
  path: "/u:/WindowsPowerShell/Powershell Projects/Scratch Area/Scratch Area.code-workspace",
  query: "",
  fragment: "",
  _formatted: null,
  _fsPath: null,
}

Can you do the same for a mapped drive and see if the properties look the same on your pc/server please?

Thanks, Rob.

oleg-shilo commented 2 years ago

Hi Rob,

Love VSSode. Updates it (v1.63.2) and the extension stopped working with workspace cose PI has changed :( vscode.open has a different signature now. Had to roll it back to vscode.openFolder. Seems to work again.

Anyway, your question... yes mapped folder is handled: image

oleg-shilo commented 2 years ago

BTW using openFolder is the right API in this case: image Meaning, will need to change it and rerelease. I was too jumpy when did the change to vscode.open :)

ratkinson-prh commented 2 years ago

Thanks again for the help Oleg. Unfortunately for me, this is looking like a local environmental issue. My corporate laptop is completely locked down, so it's likely something is interfering with the underlying Javascript code used by openFolder().

I've closed down the VSCode bug report, happy if you'd like to do the same with this one.

Cheers, Rob.

oleg-shilo commented 2 years ago

Not a problem. Sorry about your laptop. It is actually quite common :(