SchoofsKelvin / vscode-sshfs

Extension for Visual Studio Code: File system provider using SSH
GNU General Public License v3.0
543 stars 36 forks source link

Add support for config flags to settings UI (+ technical explanation flag system) #270

Open SchoofsKelvin opened 3 years ago

SchoofsKelvin commented 3 years ago

If you're here just to see how to enable flags, check the How to add flags as a user section in the explanation below

Feature request

Add two new sections to the webview:

Some notes regarding this:

Technical explanation about the flag system

The flag system got added in 83d6cd0 and expanded upon in 218188a and 9de1d03. It allows the user to quickly toggle certain features/fixes in the extension, both globally or per-config. We can also make the extension automatically enable/disable flags (yet allow it to be overridden by the user), as shown here for DF-GE that fixes #239:

Extension auto-enabling DF-GE https://github.com/SchoofsKelvin/vscode-sshfs/blob/87d2cf845a62d23d55bbb253b4697e2acbdf05a0/src/config.ts#L389-L405

And a simple example of the extension checking a boolean flag:

Extension checking DF-GE https://github.com/SchoofsKelvin/vscode-sshfs/blob/87d2cf845a62d23d55bbb253b4697e2acbdf05a0/src/connect.ts#L266-L273

Here's more information regarding flags:

How to add flags as a user For managing flags globally, the user can edit the `sshfs.flags` setting in VS Code's User Settings. For example: ```json "sshfs.flags": [ "DEBUG_SSH2" ], ``` For a per-config basis, the user requires to edit the JSON-representation of the config. This is usually under `sshfs.configs` in the User Settings, but could be in other places if you configured it that way, e.g. the workspace settings: ```json "sshfs.configs": [ { "name": "config-name", "host": "localhost", "flags": ["DEBUG_SSH2"] } ], ```
Parsing of flags Flags are case-insensitive, and are basically represented as strings, where the resulting flag value depends on the format: ```ts "+KEY" => true "-KEY" => false "KEY" => null "KEY=something" => "something" ``` Boolean flags (e.g. `DEBUG_SSH2` in 06bce85) will on top of that convert non-boolean values (e.g. `null` and `"something"`) to booleans on very simple rules: - If the value is `null`, we return `true` (thus the presence of a (non-false) flag counts as `true`) - If it's a string that lowercase equals `true`, `t`, `yes` or `y`, we return `true` - If it's a string that lowercase equals `false`, `f`, `no` or `n`, we return `false` - In other cases, we assume the user did something wrong, so we throw an error This allows the user to simply add e.g. `DEBUG_SSH2` _(or `+DEBUG_SSH2` or `DEBUG_SSH=true` etc)_ to enable debugging of the ssh2 library, while also supporting `-CHECK_HOME` _(or `CHECK_HOME=no` etc)_ to disable that enabled-by-default flag.
List of currently available flags https://github.com/SchoofsKelvin/vscode-sshfs/blob/87d2cf845a62d23d55bbb253b4697e2acbdf05a0/src/config.ts#L370-L384 _check up-to-date list at https://github.com/SchoofsKelvin/vscode-sshfs/blob/master/src/config.ts_