Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved] Compare selected folders command failed when using shortcut #66

Closed
DnnMitko opened this issue Feb 19, 2021 · 9 comments · Fixed by #67
Closed

[Solved] Compare selected folders command failed when using shortcut #66

DnnMitko opened this issue Feb 19, 2021 · 9 comments · Fixed by #67
Assignees

Comments

@DnnMitko
Copy link

DnnMitko commented Feb 19, 2021

I wrote in my keybindings.json:
{ "key": "shift+alt+d", "command": "foldersCompare.compareSelectedFolders", "when": "explorerViewletVisible && filesExplorerFocus && !inputFocus" }

I selected 2 folders in my file explorer and when I clicked the keybind, I got a notification:

Running the contributed command: 'foldersCompare.compareSelectedFolders' failed.

In the extension host logs, I got this error:
[exthost] [error] TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) at CompareFoldersProvider.compareSelectedFolders (/home/default/.vscode/extensions/moshfeu.compare-folders-0.20.1/out/providers/foldersCompareProvider.js:58:39) at b._executeContributedCommand (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:88517) at b.$executeContributedCommand (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:88849) at p._doInvokeHandler (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:10276) at p._invokeHandler (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:9968) at p._receiveRequest (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:8638) at p._receiveOneMessage (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:7440) at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:89:5568 at v.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:55:1836) at d.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:63:15515) at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:104:29104 at v.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:55:1836) at d.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:63:15515) at t._receiveMessage (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:63:20765) at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:63:17659 at v.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:55:1836) at u.acceptChunk (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:63:12880) at /usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:63:12228 at Socket.m (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:104:12375) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at Pipe.onStreamRead (internal/stream_base_commons.js:186:23) foldersCompare.compareSelectedFolders

I'm running on Debian. Let me know if you'd need anything more.
Hope this can get fixed easily, as it's way more convenient for me to use the command through a keybind.

@moshfeu moshfeu added the bug Something isn't working label Feb 19, 2021
@moshfeu
Copy link
Owner

moshfeu commented Feb 19, 2021

Thanks.
I'll investigate this soon.

@moshfeu
Copy link
Owner

moshfeu commented Feb 20, 2021

Unfortunately, it's not possible to create a shortcut for this command (See the issue link above).
For a better user experience I'm gonna show an error message when the user triggers this command using keybindings.

Thanks for the report and sorry for that limitation. I wish I could fix this.

@moshfeu
Copy link
Owner

moshfeu commented Feb 20, 2021

Here is how it looks

Screen Shot 2021-02-20 at 2 39 42

Can you verify please?

compare-folders-0.20.2.vsix.zip

@DnnMitko
Copy link
Author

That is too bad, guess it can't be helped.
But there might be another way. I've been trying to get it to work via macros.
Using the Macro Commander extension, I wrote:

"compareFolders": [
            {
                "javascript": [
                    "await vscode.commands.executeCommand('copyFilePath')",
                    "const folders = await vscode.env.clipboard.readText()",
                    "const first = await vscode.Uri.file(folders.split(''\\n'')[0])",
                    "const second = await vscode.Uri.file(folders.split('\\n')[1])",
                    "if(first && second) { await vscode.commands.executeCommand('foldersCompare.compareSelectedFolders', first, [first, second]) }"
                ]
            }
        ]

I tried manually getting and parsing the URIs for the command but maybe I'm missing something. Any ideas?

@moshfeu
Copy link
Owner

moshfeu commented Feb 22, 2021

Interesting approach! I don't use macros actually.

await vscode.commands.executeCommand('copyFilePath')

is copying the opened editor path, isn't?
You need the path of the 2 folders.
I can't find a command for copying the selected folders in the explorer panel.

I wonder however what is the use case? Are you selecting 2 folders with the mouse and want to compare with the keyboard?
Do you usually compare the same pair of folders or every time you compare 2 different ones?

@DnnMitko
Copy link
Author

The extension lets me run javascript, including the vscode API, as part of the macros.
I'm selecting two in the explorer, then running it. The copyFilePath command will copy both selections' paths. Then simply split by newline to get each separately.
After that, I try making the URI myself and give it to the command as args though I might be messing up in how i pass them.

@DnnMitko
Copy link
Author

This is what I have so far, just trying to figure out how to get the last part to work.
The executeCommand with foldersCompare.compareSelectedFolders

"javascript": [
                    "await vscode.commands.executeCommand('copyFilePath')",
                    "const folders = await vscode.env.clipboard.readText()",
                    "const first = folders.split(''\\n'')[0]",
                    "const second = folders.split('\\n')[1]",
                    "const firstUri = await vscode.Uri.file(first)",
                    "const secondUri = await vscode.Uri.file(second)",
                    "if(first && second) { await vscode.commands.executeCommand('foldersCompare.compareSelectedFolders', firstUri, [firstUri, secondUri]) }"
                ]

@DnnMitko
Copy link
Author

I got it to work!!
Instead of
executeCommand('foldersCompare.compareSelectedFolders', firstUri, [firstUri, secondUri]) }
I have to give it:
executeCommand('foldersCompare.compareSelectedFolders', secondUri, [firstUri, secondUri]) }

To summarize for those looking for a temporary solution:
Use the Macro Commander extension: https://marketplace.visualstudio.com/items?itemName=jeff-hykin.macro-commander
Put in your settings.json:

"macros": {
    "compareFolders": [
        {
            "javascript": [
                "await vscode.commands.executeCommand('copyFilePath')",
                "const folders = await vscode.env.clipboard.readText()",
                "const first = folders.split('\\n')[0]",
                "const second = folders.split('\\n')[1]",
                "const firstUri = await vscode.Uri.file(first)",
                "const secondUri = await vscode.Uri.file(second)",
                "await vscode.commands.executeCommand('foldersCompare.compareSelectedFolders', secondUri, [firstUri, secondUri])"
            ]
        }
    ]

Then in your keybindings.json:

{
  "key": KEY_BIND,
  "command": "macros.compareFolders",
  "when": "filesExplorerFocus && explorerResourceIsFolder && listDoubleSelection"
}

Then simply select two folders in the file explorer and use the shortcut.

@moshfeu moshfeu removed the bug Something isn't working label Feb 23, 2021
@moshfeu moshfeu pinned this issue Feb 23, 2021
@moshfeu
Copy link
Owner

moshfeu commented Feb 23, 2021

Very nice!
Thanks for the trick. I pinned it for future asker.
Good job 👍

@moshfeu moshfeu closed this as completed Feb 23, 2021
@moshfeu moshfeu changed the title Compare selected folders command failed when using shortcut [Solved] Compare selected folders command failed when using shortcut Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants