codefori / vscode-ibmi

🌍 IBM i development extension for VS Code
https://codefori.github.io/docs/#/
MIT License
288 stars 95 forks source link

Member - copy member path from tab #2090

Open jkdavew opened 6 months ago

jkdavew commented 6 months ago

Type: Bug

When right-clicking on an open member, there are two options that seem to have an issue

Copy Path Copy Relative Path

Using these adds the wrong slashes \ instead of /.

Also noticing that the relative path behaves the same as the other option (I'd think it would leave off the member name).

Using the option is convenient because the copied/clipboard information can then be used with the Ctrl+Alt+P feature to quickly find other members.

Thanks!!

Extension version: 2.10.1 VS Code version: Code 1.89.1 (dc96b837cf6bb4af9cd736aa3af08cf8279f7685, 2024-05-07T05:13:33.891Z) OS version: Windows_NT x64 10.0.22631 Modes:

chrjorgensen commented 6 months ago

@jkdavew The two functions are provided by VS Code and not from this extension - and VS Code formats the path according to the OS you're running on. That's why slashes are converted to backslashes - because you're on Windows. On a Linux (and probably Mac) system the slashes are kept as slashes.

We may have a look into this - to see if we can change this behavior...

worksofliam commented 5 months ago

I don't believe there to be a way we can change this by default. Though, perhaps there is something in the FS API that allows us to force which slash to use.

jkdavew commented 5 months ago

Ahh, I see. Since you may not be able to change that, could another context menu option be added: "Copy Member Path" and you'd have full control over that?

jkdavew commented 5 months ago

I'm sure there are many more important things to work on with this extension, but I found the following will work to allow for a new "Copy Member Path" context menu option when a member is open (when clicking on the tab, or in the source).

extension.js

    context.subscriptions.push(vscode.commands.registerCommand('code-for-ibmi.copy_member_path', function (input) {
        try{
            vscode.env.clipboard.writeText(input.path.substring(1)).then(()=>{
                vscode.window.showInformationMessage('Member path has been copied');
            });
        }catch(e){}
    }));

package.json (add "commands" and "menus" as a properties within the "contributes" property)

        "commands": [
            {
                "command": "code-for-ibmi.copy_member_path",
                "title": "Copy Member Path"
            }
        ],
        "menus": {
            "editor/title/context": [
                {
                    "command": "code-for-ibmi.copy_member_path",
                    "when": "resourceScheme == member",
                    "group": "1_copypath@1"
                }
            ],
            "editor/context": [
                {
                    "command": "code-for-ibmi.copy_member_path",
                    "when": "resourceScheme == member",
                    "group": "1_copypath@1"
                }
            ]
        },