oleg-shilo / Favorites.vscode

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

Version 1.6.0 adds the [object Object] instead of the filename #49

Closed a-bentofreire closed 1 month ago

a-bentofreire commented 2 months ago

Hi, I'm using Favorites 1.6.0, when I click on icon "+" quite often instead of the filename being added, it adds [object Object]. Sometimes adds the correct filename but most times doesn't. I couldn't find a pattern to determine when it generates the correct filename, and when it doesn't. I'm using the latest version of VSCode on Linux.

oleg-shilo commented 2 months ago

Hi Alexandre,

Unfortunately, I cannot reproduce the problem. So if you or someone else eventually finds the way please share and I will investigate it.

Until then you can open the file list and add the path manually: image

a-bentofreire commented 2 months ago

Hi, Oleg Thank you for the quick reply. I just did multiple tests and I found a situation where always happens:

  1. Click on a item already on the favorites list, this it will open that file.
  2. On VSCode file tree double click on a file that it will open this file and replace the previous on VSCode.
  3. Click on "+" on favorites bar, it will add [object Object]. I tried this multiple times and it always has this error.
oleg-shilo commented 2 months ago

This is fantastic. Sorry, I did not respond early. Will have a look at it asap.

a-bentofreire commented 2 months ago

No worries. Thank you for replying

oleg-shilo commented 2 months ago

Do I repeat the test correctly?

capture

Somehow VSCode behaves differently...

a-bentofreire commented 2 months ago

I just made a gif to show how it happens, and it always happens doing exactly like this regardless of the files that I click. Favorites-2024-09-01_23 41 32

oleg-shilo commented 2 months ago

Your test is not really different to mine. Except for the outcome :) Can this be due to the fact that you open the workspace. Unlikely, I know. And I tested it with the workspace too.

what OS are you running it on?

a-bentofreire commented 1 month ago

Hi, I also test as a folder without a workspace and the problem is the same. with a bit more time, I will try to investigate deeper into the problem. OS: Linux Mint 22 Wilma | Cinnamon 6.2.9 VSC and your extension are both in the latest version.

oleg-shilo commented 1 month ago

Hm, maybe Linux makes the diff. Will check there too

oleg-shilo commented 1 month ago

No, the same. Work OK. I am really puzzled about that.

The notation [object Object] indicates that the it is the result of the toString() call of some object instance. And in the _add(file) scenario there is only one place where toString() is called

https://github.com/oleg-shilo/Favorites.vscode/blob/cf4689d86e33c5c8d350894d9a73ef1ce09037ae/src/extension.ts#L95 But I cannot imagine how Uri can return such a string.

a-bentofreire commented 1 month ago

If you add a few log lines in several places, zip the extension.js and place it here, I will test it.

oleg-shilo commented 1 month ago

Great. Good idea. Please take this file. It will print to the CodeMap#49 channel:

image

extension.zip

igorfrance commented 1 month ago

I have that issue too, if you need another tester :-)

Windows 11, VS Code 1.93

oleg-shilo commented 1 month ago

Hi Igor, this would be great. Logging will only get us so far. If I dare to ask, can you try to debug the extension? I am helpless without ability to reproduce it. And debugger would give us the unswer in a few mins.

If you indeed happy to help, just clone the repo, load it in VSCode. Put your breakpoint in the add method and hit F5: image

That's it. Now when you add the file to the list the breakpoint will be fired and you will be able to see what is happening there.

Please do not hesitate to say "No". We are all busy, I would p[perfectly understand.

a-bentofreire commented 1 month ago

Hi, Oleg Yeah, I have also been super busy with my own VSC extension.

I did test your extension just a minute ago, and the output is: Added to the Favorites (1): [object Object]

I saved you some back and forth, and tweaked your extension.js:

function add(fileName) {
    var _a, _b, _c;
    let log = vscode.window.createOutputChannel("CodeMap#49");
    if (fileName) {
        _add(fileName);
        log.appendLine(`Added to the Favorites (1): ${fileName}`);
        const objString = JSON.stringify(fileName);
        log.appendLine(`Added to the Favorites (2): ${objString}`);
    }

and the output was:

{
    "collapsibleState": 0,
    "label": "Americas-Journey.md",
    "command": {
        "command": "favorites.open",
        "title": "",
        "tooltip": "/home/abf/Americas-Journey.md",
        "arguments": [
            "/home/abf/Americas-Journey.md"
        ]
    },
    "children": null,
    "context": "/home/abf/Americas-Journey.md",
    "rootFolder": false,
    "contextValue": "file",
    "tooltip": "/home/abf/Americas-Journey.md",
    "resourceUri": {
        "$mid": 1,
        "path": "/home/abf/Americas-Journey.md",
        "scheme": "file"
    },
    "iconPath": null
}

I would suggest on the if to check if it's a string, and if not use the filename['resourceUri']['path'], I'm guessing that must obvious for you now.

oleg-shilo commented 1 month ago

Fantastic, thank you Alexandre Will do the fix on weekend

a-bentofreire commented 1 month ago

Awesome, looking forward.

oleg-shilo commented 1 month ago

This is really strange as your debug info proves that function add(fileName: string) instead of a string argument receives FavoriteItem. This method is a root-level method in the call stack as it is invoked by VSCode only:

image

So I have no idea how this substitution can happen.

Anyway, your suggested workaround will address the issue. Thank you.

The release v1.6.1 with the fix has been published.

a-bentofreire commented 1 month ago

I just tried the new version and now there is a new issue. It doesn't lets me add any new document. When I do the same procedure as my early gif, it will report: "The active document is already in the Favorites."

  1. If I open VSCode and add to favorites there is no problem.
  2. If I click on a document on favorites and opens on VSCode, after that I can no longer add any document.
a-bentofreire commented 1 month ago

I have been using your extension for quite a while and before it didn't have this issue, it's a recent update that cause it, probably of vscode.

oleg-shilo commented 1 month ago

I GOT IT!!! The original problem. After the last VSCode update I have it too. Great. Meaning I will be able to reproduce it. Probably I just missed that VSCode update.

image

Working on it.

oleg-shilo commented 1 month ago

I checked on two systems now and it shows a consistent result with the older version of the extension without Alexandre's workaround.. VSCode v1.92.2 works just fine. And the latest update to v1.93.1 breaks it.

After updating the extension the problem is gone and indeed a new one surfaced. Related to the duplication due to that resourceUri.path pointing to the last open document but not the active one. Though on Win the error itself is slightly different but the cause is the same (I believe).

While now I am convinced it is a VSCode problem, it's a very little comfort for the users. I'll see if I can find another workaround.

In the mean while avoid using the + button and use the command instead. It seems to work correctly:

image

oleg-shilo commented 1 month ago

Done, the extension v1.6.3 has an alternative workaround that seems to address the issue. Please let me know if it indeed does. . . . These are my findings:

This is the extension root level function as it was before the fix:

function add(fileName: string) {
    if (fileName) {
        // The function is called by another extension function `add_file` that passes a string as an arg
        // add fileName to favs
        . . .
    }
    else {
        // The function is called by VSCode shell (fileName is null)
        // add active doc to favs
        . . .
    }
}

VSCode v1.92.2 always passed null if the method is invoked by the VSCode shell. Easy. Though at least from v1.93.1 they started passing the Favorites explorer selected mode. And this obviously breaks the logic.

Now it's fixed by explicit checking of fileName for being a string type.

a-bentofreire commented 1 month ago

Sounds like you were thrilled about it. I already checked and all it seems good now. Great job! I'm going to close the issue, I will reopen if I find some.