swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
706 stars 47 forks source link

Warn users about lack of symlink privileges on Windows #888

Closed matthewbastien closed 2 weeks ago

matthewbastien commented 2 weeks ago

Issue: #805

Our available solutions are:

  1. Check for Developer Mode being enabled in the registry using an existing npm package like regedit
  2. Check for the Create Symbolic Links privilege. However, there are no good npm packages for this which means we would have to create a native module and compile it for all Windows architectures that we support.
  3. Check that fs.symlink() works using a temporary file as the target.

I've opted for the 3rd approach since it is the simplest and it seems like all we really care about is that we can create symlinks on Windows. If fs.symlink() fails then the Swift extension will pop up a warning notification pointing the user at Microsoft's Developer Mode documentation. They can also choose to silence the warning in their user settings if they do not wish to enable Developer Mode or grant the Create Symbolic Link permission.

compnerd commented 2 weeks ago

Could the fs.symlink fail for other reasons other than lack of privileges? Developer Mode being disabled is not a great heuristic either - I have a group policy applied to grant myself the privilege and do not have developer mode enabled.

matthewbastien commented 2 weeks ago

Could the fs.symlink fail for other reasons other than lack of privileges?

It would also fail if the user didn't have permissions to write to the directory, but presumably it would fail at the creation of the temporary directory instead. The only other thing I can think of (and I'm just speculating here - I have not tested) is if the workspace were on a remote file system or something that didn't support symlinks at all. Perhaps we could write to a hidden file/folder in the workspace as a better check instead?

I did test this out with a Windows VM and it works as expected at least with my setup. I was able to set the privilege, restart Windows, and the symlink creation succeeded.

Developer Mode being disabled is not a great heuristic either

Agreed. That's why I'm not too keen on that approach. The only thing it has going for it is ease of implementation since there are already npm modules out there for reading from the registry. Checking the privilege directly, unfortunately, requires us to build native modules which is just a pain for one small warning.

adam-fowler commented 2 weeks ago

@swift-server-bot test this please