Skip to content

support WSL #46

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

Merged
merged 5 commits into from
Jul 24, 2018
Merged

support WSL #46

merged 5 commits into from
Jul 24, 2018

Conversation

purocean
Copy link
Contributor

@purocean purocean commented Jul 21, 2018

resolve #47

@jdneo
Copy link
Member

jdneo commented Jul 23, 2018

@purocean Thank you for the contribution. I'll take a look at this PR these days.

}

export function toWinPath(path: string): string {
return cp.execFileSync("wsl", ["--", "wslpath", "-w", path]).toString().trim();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks the 1st param "--" doesn't work for me.

CMD>wsl wslpath -w /mnt/c/
C:\
CMD>wsl -- wslpath -w /mnt/c/
/bin/bash: --: invalid option
Usage:  /bin/bash [GNU long option] [option] ...
        /bin/bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --rcfile
        --restricted
        --verbose
        --version
Shell options:
        -ilrsD or -c command or -O shopt_option         (invocation only)
        -abefhkmnptuvxBCHP or -o option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the Windows version, maybe this param can be removed.

C:\>ver

Microsoft Windows [Version 10.0.17713.1000]

C:\>wsl --help
Usage: wsl.exe [option] ...
Options:
    -d, --distribution <DistributionName>
        Launch the specified distribition.

    -e, --exec <CommandLine>
        Execute the specified Linux command. The remainder of the arguments are
        used as the command line to execute.

    -u, --user <UserName>
        Run as the specified user.

    --help
        Display this usage information.

    --
        Stop parsing arguments and pass the remainder to the Linux process.

C:\>wsl -- wslpath -u "C:/"
/mnt/c/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attaching mine.

C:\>ver

Microsoft Windows [Version 10.0.17134.167]

C:\>wsl --help
/bin/bash: --: invalid option
Usage:  /bin/bash [GNU long option] [option] ...
        /bin/bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --rcfile
        --restricted
        --verbose
        --version
Shell options:
        -ilrsD or -c command or -O shopt_option         (invocation only)
        -abefhkmnptuvxBCHP or -o option

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think wsl.exe is a wrapper to run inner shell in your WSL. I suppose the parameters depend on what your inner shell is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purocean If you remove the -- at your side, will this command still workable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package.json Outdated
"type": "boolean",
"default": false,
"scope": "window",
"description": "Use nodejs inside the Windows Subsystem for Linux."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodejs -> Node.js

@jdneo
Copy link
Member

jdneo commented Jul 24, 2018

Looks like there are several places which contains the logic like wsl.useWsl() ? wsl.toWslPath(workFolder) : workFolder.

I think it could be better to have a pathUtils that wrap this kind of logic there. @purocean what do you think?

}

export function toWslPath(path: string): string {
return cp.execFileSync("wsl", ["wslpath", "-u", `${path.replace(/\\/g, "/")}`]).toString().trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use " to wrap the path instead of replace \, will it be workable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Work :(

function toWslPath(path) {
    return cp.execFileSync("wsl", ["wslpath", "-u", `"${path}"`]).toString().trim();
}
module.js:549
    throw err;
    ^

Error: Cannot find module '/mnt/y/env/VSCode-win32-x64/Y:/env/VSCode-win32-x64/.vscode/extensions/shengchen.vscode-leetcode-0.7.0/node_modules/leetcode-cli/bin/leetcode'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With pathUtils my point of view is not unnecessary at this time.

For this program, we just need do good job with file system and shell command for cross-platform. I think the cpUtils and workspaceUtils is sufficiently abstract.

We can try to change these next time if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could focus on cpUtils and workspaceUtils provide service for others.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purocean That is because by default the option shell of execFileSync is false. If add {shell: true} to the argument list, then I think it should work.

Another thing I'm concerning is that here we use execFileSync(). Personally, I prefer use async/await wherever possible. Take a look at this: https://nodejs.org/en/docs/guides/blocking-vs-non-blocking/
So can we use executeCommand in the cpUtils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{shell: true} work perfectly.

https://github.com/purocean/vscode-leetcode/blob/d330913ad843179e12d0248a155f8a1f570e9f6f/src/shared.ts#L7

We need a lot of works if we use async/await. Abstract leetcode command is a better option.

But we could improve step by step. Half a loaf is better than no bread.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, make sense. Tracking issue: #48

@jdneo jdneo merged commit b2deee8 into LeetCode-OpenSource:master Jul 24, 2018
@jdneo
Copy link
Member

jdneo commented Jul 24, 2018

@purocean Merged, thank you.

ringcrl pushed a commit to ringcrl/vscode-leetcode that referenced this pull request Apr 21, 2019
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 this pull request may close these issues.

Support WSL
3 participants