From 48d85e19060fb43ea841b72325331ee3ba747d3a Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 26 Oct 2025 23:50:55 -0400 Subject: [PATCH] Add configuration system for RoslynBridge extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add appsettings.json with configurable settings: - WebApiUrl: URL of the WebAPI middleware (default: http://localhost:5001) - DefaultPort: Starting port for VS instances (default: 59123) - MaxPortRange: Number of ports to try (default: 10) - HeartbeatIntervalSeconds: Heartbeat interval (default: 60) - Create ConfigurationService singleton to load settings - Loads from appsettings.json in extension directory - Falls back to sensible defaults if file missing - Provides easy property access - Update RoslynBridge.csproj to include: - ConfigurationService.cs in compilation - appsettings.json as content (copied to output and included in VSIX) - System.Data reference for future use This allows users to customize extension behavior without recompiling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- RoslynBridge/RoslynBridge.csproj | 7 ++ RoslynBridge/Services/ConfigurationService.cs | 85 +++++++++++++++++++ RoslynBridge/appsettings.json | 8 ++ 3 files changed, 100 insertions(+) create mode 100644 RoslynBridge/Services/ConfigurationService.cs create mode 100644 RoslynBridge/appsettings.json diff --git a/RoslynBridge/RoslynBridge.csproj b/RoslynBridge/RoslynBridge.csproj index aa0cbd6..abe1fde 100644 --- a/RoslynBridge/RoslynBridge.csproj +++ b/RoslynBridge/RoslynBridge.csproj @@ -74,12 +74,14 @@ + + @@ -87,6 +89,10 @@ Designer + + Always + true + Always true @@ -95,6 +101,7 @@ + diff --git a/RoslynBridge/Services/ConfigurationService.cs b/RoslynBridge/Services/ConfigurationService.cs new file mode 100644 index 0000000..fa654fd --- /dev/null +++ b/RoslynBridge/Services/ConfigurationService.cs @@ -0,0 +1,85 @@ +using System; +using System.IO; +using System.Reflection; +using System.Text.Json; + +namespace RoslynBridge.Services +{ + /// + /// Service for reading configuration from appsettings.json + /// + public class ConfigurationService + { + private static ConfigurationService? _instance; + private readonly RoslynBridgeConfig _config; + + private ConfigurationService() + { + _config = LoadConfiguration(); + } + + public static ConfigurationService Instance => _instance ??= new ConfigurationService(); + + public string WebApiUrl => _config.RoslynBridge.WebApiUrl; + public int DefaultPort => _config.RoslynBridge.DefaultPort; + public int MaxPortRange => _config.RoslynBridge.MaxPortRange; + public int HeartbeatIntervalSeconds => _config.RoslynBridge.HeartbeatIntervalSeconds; + + private RoslynBridgeConfig LoadConfiguration() + { + try + { + // Get the directory where the extension is installed + var assemblyPath = Assembly.GetExecutingAssembly().Location; + var assemblyDir = Path.GetDirectoryName(assemblyPath); + var configPath = Path.Combine(assemblyDir ?? "", "appsettings.json"); + + if (File.Exists(configPath)) + { + var json = File.ReadAllText(configPath); + var config = JsonSerializer.Deserialize(json, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }); + + if (config != null) + { + System.Diagnostics.Debug.WriteLine($"Loaded configuration from {configPath}"); + return config; + } + } + + System.Diagnostics.Debug.WriteLine($"Configuration file not found at {configPath}, using defaults"); + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine($"Error loading configuration: {ex.Message}, using defaults"); + } + + // Return default configuration + return new RoslynBridgeConfig + { + RoslynBridge = new RoslynBridgeSettings + { + WebApiUrl = "http://localhost:5001", + DefaultPort = 59123, + MaxPortRange = 10, + HeartbeatIntervalSeconds = 60 + } + }; + } + } + + public class RoslynBridgeConfig + { + public RoslynBridgeSettings RoslynBridge { get; set; } = new(); + } + + public class RoslynBridgeSettings + { + public string WebApiUrl { get; set; } = "http://localhost:5001"; + public int DefaultPort { get; set; } = 59123; + public int MaxPortRange { get; set; } = 10; + public int HeartbeatIntervalSeconds { get; set; } = 60; + } +} diff --git a/RoslynBridge/appsettings.json b/RoslynBridge/appsettings.json new file mode 100644 index 0000000..95d85e3 --- /dev/null +++ b/RoslynBridge/appsettings.json @@ -0,0 +1,8 @@ +{ + "RoslynBridge": { + "WebApiUrl": "http://localhost:5001", + "DefaultPort": 59123, + "MaxPortRange": 10, + "HeartbeatIntervalSeconds": 60 + } +}