Add configuration system for RoslynBridge extension
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -74,12 +74,14 @@
|
||||
|
||||
<!-- Services -->
|
||||
<Compile Include="Services\BaseRoslynService.cs" />
|
||||
<Compile Include="Services\ConfigurationService.cs" />
|
||||
<Compile Include="Services\DiagnosticsService.cs" />
|
||||
<Compile Include="Services\DocumentQueryService.cs" />
|
||||
<Compile Include="Services\IRoslynQueryService.cs" />
|
||||
<Compile Include="Services\IWorkspaceProvider.cs" />
|
||||
<Compile Include="Services\ProjectOperationsService.cs" />
|
||||
<Compile Include="Services\RefactoringService.cs" />
|
||||
<Compile Include="Services\RegistrationService.cs" />
|
||||
<Compile Include="Services\RoslynQueryService.cs" />
|
||||
<Compile Include="Services\SymbolQueryService.cs" />
|
||||
<Compile Include="Services\WorkspaceProvider.cs" />
|
||||
@@ -87,6 +89,10 @@
|
||||
<None Include="source.extension.vsixmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<IncludeInVSIX>true</IncludeInVSIX>
|
||||
</Content>
|
||||
<Content Include="README.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<IncludeInVSIX>true</IncludeInVSIX>
|
||||
@@ -95,6 +101,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
85
RoslynBridge/Services/ConfigurationService.cs
Normal file
85
RoslynBridge/Services/ConfigurationService.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RoslynBridge.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Service for reading configuration from appsettings.json
|
||||
/// </summary>
|
||||
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<RoslynBridgeConfig>(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;
|
||||
}
|
||||
}
|
||||
8
RoslynBridge/appsettings.json
Normal file
8
RoslynBridge/appsettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"RoslynBridge": {
|
||||
"WebApiUrl": "http://localhost:5001",
|
||||
"DefaultPort": 59123,
|
||||
"MaxPortRange": 10,
|
||||
"HeartbeatIntervalSeconds": 60
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user