microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 449 forks source link

Windows network drive as sourceDirectory #2607

Open csuvbakka opened 2 years ago

csuvbakka commented 2 years ago

I run VSCode on a Windows machine and I run Ubuntu on WSL. My source code is on the Ubuntu machine which I can access as a network drive from Windows, using the following path: \\wsl$\Ubuntu-22.04\...

If I open my source code folder in VSCode the ${workspaceFolder} variable will be correctly set to \\wsl$\Ubuntu-22.04\my_project The source directory is set in settings.json as "cmake.sourceDirectory": "${workspaceFolder}"

With this setup I get the following error message when configuring the project: "sourceDirectory" is not a directory {"sourceDirectory":"/wsl$/Ubuntu-22.04/my_project"}

The problem seems to be caused by double slashes being replaced with single ones.

bobbrow commented 2 years ago

Are you using the Remote - WSL extension for VS Code to open your WSL workspace? If you do that, the ${workspaceFolder} should show as the native path, like /home/bob/my_project and I haven't encountered any problems with that. CMake Tools does not do anything else special for network paths.

csuvbakka commented 2 years ago

I do not use the Remote WSL extension. My goal is to keep the source code in WSL and use the MSVC compiler to build it so I simply open VSCode from the command line like code \\wsl$\Ubuntu-22.04\my_project

In the meantime I've managed to make it work by deleting the duplicate slash removal from https://github.com/microsoft/vscode-cmake-tools/blob/1ca9c49158cec8f94d4ce6f9b380dfe0322815d0/src/util.ts#L83

What do you think, would it make sense to modify the function above to keep leading double slashes?

bobbrow commented 2 years ago

I think it would be safe to keep leading double slashes only if the platform is Windows. Keeping them on other platforms could break the contract of normalization. Would you be interested in contributing a fix for this?

musteresel commented 2 years ago

I'm running into the same issue; VS Code running on Win 10, trying to access file which are in a WSL2 VM, "CMake/Build" output window shows:

[rollbar] "sourceDirectory" is not a directory {"sourceDirectory":"/wsl$/NixOS/home/nixos/private/cmake-tools-in-wsl-but-not-remote"}
[rollbar] "sourceDirectory" is not a directory {"sourceDirectory":"/wsl$/NixOS/home/nixos/private/cmake-tools-in-wsl-but-not-remote"}
[main] Configuring folder: cmake-tools-in-wsl-but-not-remote 
[rollbar] "sourceDirectory" is not a directory {"sourceDirectory":"/wsl$/NixOS/home/nixos/private/cmake-tools-in-wsl-but-not-remote"}

Is there documentation on how to develop / debug a VS Code extension, or any "onboarding" documentation? I'm willing to contribute a fix, but haven't yet worked much with VS Code and have literally no idea about its extension system.

musteresel commented 2 years ago

In the meantime I've managed to make it work by deleting the duplicate slash removal

@csuvbakka so a path like //wsl$/vmname/some/path works for you? Hm ... testing from powershell terminal within VS code with CMake suggest it would:

cmake -S //wsl$/NixOS/home/nixos/private/cmake-tools-in-wsl-but-not-remote -B build

Punching that path into Win Explorer however doesn't, it needs the first \\ and also the backslash between wsl$ and the vm name.