opensafely-core / codespaces-initiative

Improving the use of OpenSAFELY in Codespaces
MIT License
0 stars 0 forks source link

Decide on Visual Studio Code auto save configuration #36

Closed StevenMaude closed 2 months ago

StevenMaude commented 3 months ago

In some instances, a frequent autosave may not be desirable; for example, where you have a site that rebuilds on every save.

For the research-template, this may or may not be OK.

Auto save is controlled via a JSON setting.

StevenMaude commented 3 months ago

~It seems like you can set the setting as follows in devcontainer.json, but that "remote" setting gets overridden by the workspace settings:~

        "customizations": {
                "vscode": {
                        "settings": {
                                "files.autoSave": "off"
                        }
                }
         }

Actually, I think this works. The actual setting state is very confusing, because there are multiple levels of setting (user, workspace, remote…) and, I'm not entirely sure but I think, "Auto save" might be ticked in the menu bar, yet possibly disabled even?!

For reference, the other location you can add such settings is .vscode/settings.json.

Disabling autosave entirely may not be what we want though:

StevenMaude commented 3 months ago

Now that we know that auto save is configurable in Codespaces, what I think needs to be decided to close this are:

  1. Do we want auto save enabled?
    • Probably yes, as avoiding losing user work — or losing relatively little, only the changes since the last auto save — should be a priority.
    • I'm not entirely sure on the failure mode when there's a sudden disconnection or Codespaces outage, but GitHub's own documentation recommends enabling auto save when using Codespaces with a local Visual Studio Code editor:

      When you connect to a codespace through Visual Studio Code running on your desktop, you must enable auto-save.

    • The downside of this is that any running "live" servers that rerun code based on changes to source files may run frequently.
  2. How should auto save be configured? The options are:
    • time delay
    • focus change away from the unsaved file
    • focus change away from the Visual Studio Code window (does this feature work, and how does this work in Codespaces? when you navigate to a new tab/away from the browser window?)
  3. Do we want "auto format on auto save" to work? This would require different tools for Python and R.

Finally, it will be useful to confirm that any settings changes added behave as intended in a codespace. The hierarchy of Visual Studio Code settings can be a little complex, especially with the extra "Remote" level added by Codespaces/dev containers.


For projects that only actually run code when opensafely run, then the answers might be:

  1. Yes, auto save should be enabled.
  2. Auto saving whether immediately or on delay may be OK.
  3. We might want to make "auto format on auto save" work. However, we also need to review the existing formatting tooling, because it's deprecated (#31). That in turn requires a decision on whether we even want formatting tooling bundled in.
lucyb commented 2 months ago

I'm closing this, because after testing it appears that autosave has been enabled and this isn't causing any problems with the user experience/performance.