Fix document analysis provider selection freezes

This commit is contained in:
Peer Hogeterp committed 2026-09-14 14:20:01 +02:00
1 parent 6e735523c6
commit 894c509f4d
7 files changed
+80 -34

No files matched your search

@@ -33,6 +33,7 @@ public sealed class SettingsManager
private readonly ILogger<SettingsManager> logger;
private readonly RustService rustService;
private readonly SemaphoreSlim settingsWriteSemaphore = new(1, 1);
/// <summary>
/// The settings manager.
@@ -294,41 +295,56 @@ public sealed class SettingsManager
/// </summary>
public async Task StoreSettings()
{
if(!this.IsSetUp)
await this.settingsWriteSemaphore.WaitAsync();
try
{
this.logger.LogWarning("Cannot store settings, because the configuration is not set up yet.");
return;
}
if(!this.IsSetUp)
{
this.logger.LogWarning("Cannot store settings, because the configuration is not set up yet.");
return;
}
if(this.SettingsWriteBlocked)
if(this.SettingsWriteBlocked)
{
this.logger.LogWarning($"Cannot store settings, because settings writes are blocked. Reason: '{this.SettingsWriteBlockReason}'.");
return;
}
var settingsJson = JsonSerializer.Serialize(this.ConfigurationData, JSON_OPTIONS);
var settingsPath = Path.Combine(ConfigDirectory!, SETTINGS_FILENAME);
await this.StoreSettingsSnapshot(settingsJson, settingsPath);
await this.StoreCurrentVersionBackup(this.ConfigurationData.Version, settingsJson);
}
finally
{
this.logger.LogWarning($"Cannot store settings, because settings writes are blocked. Reason: '{this.SettingsWriteBlockReason}'.");
return;
this.settingsWriteSemaphore.Release();
}
var settingsPath = Path.Combine(ConfigDirectory!, SETTINGS_FILENAME);
await this.StoreSettingsSnapshot(this.ConfigurationData, settingsPath);
await this.StoreCurrentVersionBackup(this.ConfigurationData);
}
private static string GetBackupSettingsFilename(Version version) => $"settings.{version.ToString().ToLowerInvariant()}.json";
private static string GetBackupSettingsPath(Version version) => Path.Combine(ConfigDirectory!, GetBackupSettingsFilename(version));
private async Task StoreCurrentVersionBackup(Data settingsData)
private Task StoreCurrentVersionBackup(Data settingsData) =>
this.StoreCurrentVersionBackup(settingsData.Version, JsonSerializer.Serialize(settingsData, JSON_OPTIONS));
private async Task StoreCurrentVersionBackup(Version settingsVersion, string settingsJson)
{
if(settingsData.Version != CURRENT_SETTINGS_VERSION)
if(settingsVersion != CURRENT_SETTINGS_VERSION)
{
this.logger.LogWarning($"Skipping settings backup because the settings version '{settingsData.Version}' is not the current version '{CURRENT_SETTINGS_VERSION}'.");
this.logger.LogWarning($"Skipping settings backup because the settings version '{settingsVersion}' is not the current version '{CURRENT_SETTINGS_VERSION}'.");
return;
}
var backupSettingsPath = GetBackupSettingsPath(CURRENT_SETTINGS_VERSION);
await this.StoreSettingsSnapshot(settingsData, backupSettingsPath);
await this.StoreSettingsSnapshot(settingsJson, backupSettingsPath);
this.logger.LogInformation($"Stored the settings backup file '{backupSettingsPath}'.");
}
private async Task StoreSettingsSnapshot(Data settingsData, string settingsPath)
private Task StoreSettingsSnapshot(Data settingsData, string settingsPath) =>
this.StoreSettingsSnapshot(JsonSerializer.Serialize(settingsData, JSON_OPTIONS), settingsPath);
private async Task StoreSettingsSnapshot(string settingsJson, string settingsPath)
{
if(!Directory.Exists(ConfigDirectory))
{
@@ -336,8 +352,6 @@ public sealed class SettingsManager
Directory.CreateDirectory(ConfigDirectory!);
}
var settingsJson = JsonSerializer.Serialize(settingsData, JSON_OPTIONS);
//
// We write the new settings next to the previous ones and replace them afterwards, so that
// no crash can leave a half-written settings file behind. The temporary file has to live in
@@ -349,7 +363,7 @@ public sealed class SettingsManager
try
{
await File.WriteAllTextAsync(tempFile, settingsJson);
File.Move(tempFile, settingsPath, true);
await Task.Run(() => File.Move(tempFile, settingsPath, true));
}
catch
{