Skip to content
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

feat: better setup diagnostics #436

Merged
merged 47 commits into from
May 7, 2024

Conversation

mhuisi
Copy link
Collaborator

@mhuisi mhuisi commented Apr 25, 2024

This PR has three main goals:

  1. Implement a new and easily extensible mechanism to detect issues with the user's setup and notify them about it.
  2. Implement an easily extensible mechanism to dump all kinds of context information about the user's system and Lean setup to make it easier to debug issues with their setup.
  3. Clean up all of the existing code to the extent that is necessary in order to facilitate 1. and 2..

Setup diagnostic warnings and errors

There are two separate kinds of setup diagnostics: Global- and project-level diagnostics.

  • Global-level diagnostics are checked when the first Lean file is opened. If there is an error-level setup issue, none of the Lean-specific extension features are activated. The following global-level aspects of the user's setup are checked:
    1. Whether Curl and Git are installed (Error; reference to setup guide)
    2. Whether some version of Lean can be found (Error; Elan installation offered)
    3. Whether Elan is installed and reasonably up-to-date (Warning; Elan installation / Elan update offered)
  • Project-level diagnostics are checked whenever the first Lean file of a project is opened. If there is an error-level setup issue, the language client will not launch, but all of the other Lean-specific extension features will be active, provided that the global-level diagnostics did not yield an error. The following project-level aspects of the user's setup are checked:
    1. Whether the language client is running in an Untitled file without an attached Lean 4 project (Warning; reference to setup guide)
    2. Whether a lean-toolchain file can be found in the project associated with the file (Warning; reference to setup guide & option to open parent directory with lean-toolchain offered if present)
    3. Whether some version of Lean can be found (Error)
    4. Whether the project associated with the file is a Lean 3 project (Error)
    5. Whether the project associated with the file is using a Lean version from before the first Lean 4 stable release (Warning)
    6. Whether some version of Lake can be found (Error)

If someone is willingly using a "weird" setup that triggers warning-level diagnostics, the corresponding notifications can be turned off using the lean4.showSetupWarnings configuration option.

Setup diagnostic dump

In the forall menu, a new command "Troubleshooting: Show Setup Information" has been added that can be used to gather information about the user's system and their Lean setup. It includes the following information:

  1. Operating system
  2. CPU architecture
  3. CPU model
  4. Total available RAM
  5. Whether Curl is installed
  6. Whether Git is installed
  7. Whether Elan is installed and reasonably up-to-date, as well as the Elan version
  8. Whether Lean is installed and reasonably up-to-date, as well as the Lean version
  9. Whether a Lean project with a lean-toolchain has been opened, as well as the path to the project
  10. Available Elan toolchains

Clean-up of user-facing legacy features

  • Several settings to modify the commands that are launched in specific situations have been removed (lean4.toolchainPath, lean4.lakePath, lean4.enableLake, lean4.serverEnv, lean4.serverEnvPaths) and replaced with a single setting lean4.envPathExtensions that can be used to augment the PATH variable of the VS Code extension process and all of its child processes.
  • Compatibility with Lean versions that did not support lake serve has been removed.
  • The exports of the extension have been cleaned up to reflect the two-stage activation of the extension (first, non-Lean specific features are activated when VS Code is launched, second, Lean-specific features are activated when a Lean file is opened).
  • When opening a project and installing Elan for the first time, the extension would install the given project toolchain as the default Elan toolchain and then use that toolchain for the project as well. This saves some bandwidth and is a bit quicker, but comes at the disadvantage that users will have a project-specific toolchain installed as their global default toolchain, potentially leading to unintuitive behavior down the road (e.g. when creating new projects). Now, we instead install two toolchains in this scenario: leanprover/lean4:stable as the default toolchain, and the project-specific toolchain for that project. In the future, when Eagerly resolve toolchains to canonical, fixed reference elan#106 lands, this should lead to much more intuitive behavior outside of projects.

Refactorings

  • Much of the old bootstrapping and Lean version check logic has been rewritten and entirely replaced with the new setup diagnostic system. Most importantly, the Lean installation bootstrapping deep in LeanClientProvider has been lifted out to the outer global-level setup diagnostics and the LeanClientProvider is now much simpler than it used to be.
  • The version cache in LeanClientProvider has been deleted. Calling lean --version (rarely) a second time when that specific Lean toolchain has already been installed by a previous call should be sufficiently cheap that no cache should be needed.
  • config.ts has been cleaned up.
  • The tests for setups without Elan have been removed as they only worked due to special test-specific behavior in the first place. I'd like to re-add better tests for this at some point in the future.
  • The pre-bootstrap test has been removed because it did not properly test whether the installation prompt is open. It would be nice to have proper tests for all setup diagnostics eventually, anyways.
  • The Typescript version has been updated 5.4.5.
  • Progress bars are now only displayed after 250ms to reduce visual clutter for quick-running commands.
  • All calls to window.show(Error|Warning|Information)... have been refactored to use a safer API that ensures the following invariants to prevent the VS Code extension from being blocked on a transient notification:
    • Notifications without input should never block the extension
    • Notifications with optional input should never block the extension
    • Notifications that block the extension must be modal

Affected issues

Fixes #323: We now have a general mechanism to improve these kinds of setup issues.
Closes #326: This setting has been removed.
Fixes #388: The refactored startup logic respects overrides.
Closes #400: This setting has been removed.
Closes #440: This setting has been removed. I checked with @eric-wieser to make sure that the setup exhibiting this issue can be implemented without this setting as well.

@mhuisi mhuisi force-pushed the mhuisi/setup-diagnostics branch 2 times, most recently from ccb8ab8 to e73a0e7 Compare April 29, 2024 14:32
@mhuisi mhuisi force-pushed the mhuisi/setup-diagnostics branch 2 times, most recently from daa86c0 to 9df1510 Compare April 30, 2024 15:34
@mhuisi mhuisi force-pushed the mhuisi/setup-diagnostics branch from e9509dc to 73b1363 Compare April 30, 2024 16:00
@mhuisi mhuisi marked this pull request as ready for review May 3, 2024 14:35
mhuisi added 17 commits May 3, 2024 17:31
Since the server startup swallows stdout and stderr output of the launched process, if `lake serve` goes wrong for whatever reason despite Lean being installed correctly, there will be no error. This ensures that we at least display an error if `lake --version` already goes wrong.
VS Code has a bug where even if you await the result of `window.withProgress`, the progress bar will still linger a bit afterwards. This means that when executing lots of quick commands with progress, irritatingly many progress bars briefly get stacked on top of one another. This ensures that quick running commands don't display a progress bar at all.
Some commands report errors on stdout, some on stderr. Now we just report all output.
Ensures that:
- Notifications without input never block the extension
- Notifications with optional input never block the extension
- If a notification blocks the extension, it must be modal so that it cannot disappear and block the extension without the user noticing
@mhuisi mhuisi merged commit 81aeae8 into leanprover:master May 7, 2024
2 checks passed
mhuisi added a commit that referenced this pull request May 23, 2024
This PR adds additional diagnostics when creating and cloning projects,
as both of these commands depend on various external dependencies and
can be used before opening a Lean file for the first time (i.e. the
global setup diagnostics of #436 do not catch issues at this point). It
also refactors the architecture in #436 to make it easier to add new
kinds of diagnostics.

The following aspects of the user's setup are checked when creating
projects:
1. Whether Curl and Git are installed (Error; reference to setup guide)
2. Whether Elan is installed and reasonably up-to-date (Error if not
installed as we use `lean +toolchain` for new project, modal warning if
out-of-date; Elan installation / Elan update offered)
3. Whether some version of Lean can be found (Error)
4. Whether the toolchain associated with the new project is a Lean 3
toolchain (Error)
5. Whether the toolchain associated with the new project is using a Lean
version from before the first Lean 4 stable release (Modal warning)
6. Whether some version of Lake can be found (Error)

The following aspects of the user's setup are checked when cloning
projects:
1. Before cloning: Whether Curl and Git are installed (Error; reference
to setup guide)
2. Whether Elan is installed and reasonably up-to-date (Modal warning;
Elan installation / Elan update offered)
3. Whether some version of Lean can be found (Error)
4. Whether the toolchain associated with the new project is a Lean 3
toolchain (Error)
5. Whether the toolchain associated with the new project is using a Lean
version from before the first Lean 4 stable release (Modal warning)
6. Whether some version of Lake can be found (Error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment