[ty] Fix some configuration panics in the LSP#22040
Conversation
This introduces a safe_mode to our settings type that tells our initialization code to more aggressively believe Settings Failure Is Not An Error. This allows the full settings initialization logic to be used as much as possible for the default database while trying to keep any discarded results as narrow as possible for graceful degradation. Finally, Python has SFINAE.
| insta::assert_json_snapshot!(show_message_params, @r#" | ||
| { | ||
| "type": 1, | ||
| "message": "Failed to load project rooted at <temp_dir>/project. Please refer to the logs for more details." |
There was a problem hiding this comment.
Note this message is not "we crash and die" but rather "we are using the default fallback database that all python files outside the workspace have" (so hopefully graceful degradation, but enough of a degradation we probably want the user to look into it and fix it).
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
|
I can't for the life of me fix this bloody windows path escaping, please someone save me. |
|
I guess I can just, not snapshot the message. |
CodSpeed Performance ReportMerging #22040 will not alter performanceComparing Summary
|
|
That codspeed result has to be a false positive |
| /// Environment variable overrides. If a key is present here, it takes precedence | ||
| /// over the inner system's environment variables. | ||
| env_overrides: Arc<Mutex<FxHashMap<String, Option<String>>>>, |
There was a problem hiding this comment.
I'm inclined to add this InMemorySystem instead.
There was a problem hiding this comment.
The e2e tests don't use InMemorySystem, alas.
|
|
||
| /// Settings Failure Is Not An Error. | ||
| /// | ||
| /// This is used by the default database, which we are incentivized to make infallible, | ||
| /// while still trying to "do our best" to set things up properly where we can. | ||
| #[serde(default, skip)] | ||
| pub safe_mode: bool, |
There was a problem hiding this comment.
The idea of Options is that they directly resemble the configuration file/CLI options. It shouldn't contain any program state or inferred values. I think I would either make safe_mode an argument (or provide methods like ProjectDatabase::default(metadata_, system) or/and add it to ProjectMetadata (we already store some derived CLI state on ProjectMetadata)
There was a problem hiding this comment.
Pushed up a shot at this.
Summary
This is a revival of #21047 now that we have a reproducer again.
ProgramSettingsof default database are invalid ty#859Test Plan
e2e test from @zanieb