Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<!-- Enable central package management, https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<MSBuildPackageVersion>17.7.2</MSBuildPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Build" Version="18.0.2 " />
Expand Down
7 changes: 7 additions & 0 deletions dotnet-bsp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-bsp", "src\bsp-serve
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsp-server.tests", "test\bsp-server.tests.csproj", "{4EE3A425-382F-42ED-934E-6A9676533962}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsp-client", "src\bsp-client\bsp-client.csproj", "{7F8753C3-6598-4773-96EA-6EB3463A3849}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,10 +40,15 @@ Global
{4EE3A425-382F-42ED-934E-6A9676533962}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EE3A425-382F-42ED-934E-6A9676533962}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EE3A425-382F-42ED-934E-6A9676533962}.Release|Any CPU.Build.0 = Release|Any CPU
{7F8753C3-6598-4773-96EA-6EB3463A3849}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F8753C3-6598-4773-96EA-6EB3463A3849}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F8753C3-6598-4773-96EA-6EB3463A3849}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F8753C3-6598-4773-96EA-6EB3463A3849}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4C290E5D-5CAD-42D7-B776-E581695D4E4A} = {992A1911-5B82-4DF3-9880-83E07F114A2D}
{CC0B3E75-9BE0-466E-9723-CEBA3D4A79C6} = {992A1911-5B82-4DF3-9880-83E07F114A2D}
{A88E3B50-D12B-4925-9522-E57878D2AB54} = {992A1911-5B82-4DF3-9880-83E07F114A2D}
{7F8753C3-6598-4773-96EA-6EB3463A3849} = {992A1911-5B82-4DF3-9880-83E07F114A2D}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions src/bsp-client/BspConnectionDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace bsp_client;

public record BspConnectionDetails
{
/** The name of the build tool. */
public required string Name { get; init; }
/** The version of the build tool. */
public required string Version { get; init; }
/** The bsp version of the build tool. */
public required string BspVersion { get; init; }
/** A collection of languages supported by this BSP server. */
public required string[] Languages { get; init; }
/** Command arguments runnable via system processes to start a BSP server */
public required string[] Argv { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using StreamJsonRpc;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace test;
namespace bsp_client;

public sealed class BuildServerClient : IDisposable
{
private readonly JsonRpc _jsonRpc;

public BuildServerClient(Stream sendingStream, Stream receivingStream, ServerCallbacks serverCallbacks, TraceListener? traceListener = null)
public BuildServerClient(Stream sendingStream, Stream receivingStream, IServerCallbacks serverCallbacks, TraceListener? traceListener = null)
{
_jsonRpc = new JsonRpc(sendingStream, receivingStream);
_jsonRpc.AddLocalRpcTarget(serverCallbacks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
using System.Threading;
using System.Threading.Tasks;
using bsp4csharp.Protocol;
using dotnet_bsp;

namespace test;
namespace bsp_client;

public static class BuildServerClientExtensions
{
public static Task<InitializeBuildResult> BuildInitializeAsync(this BuildServerClient client, string workspaceRootPath, CancellationToken cancellationToken)
{
var initParams = new InitializeBuildParams
{
DisplayName = "TestClient",
Version = "1.0.0",
BspVersion = "2.1.1",
RootUri = UriFixer.WithFileSchema(workspaceRootPath),
Capabilities = new BuildClientCapabilities()
};
initParams.Capabilities.LanguageIds.Add("csharp");

public static Task<InitializeBuildResult> BuildInitializeAsync(this BuildServerClient client, InitializeBuildParams initParams, CancellationToken cancellationToken)
{
return client.SendRequestAsync<InitializeBuildParams, InitializeBuildResult>(Methods.BuildInitialize, initParams, cancellationToken);
}

Expand Down
90 changes: 90 additions & 0 deletions src/bsp-client/BuildServerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace bsp_client;

public class BuildServerFactory
{
private BuildServerFactory()
{
}

public static BuildServer CreateServer(BspConnectionDetails connectionDetails, ILogger logger)
{
return new BuildServer(connectionDetails, logger);
}
}

public sealed class BuildServer : IDisposable
{
private readonly Stream _serverStdin;
private readonly Stream _serverStdout;
private readonly Process _process;
private readonly ILogger _logger;

public BuildServer(BspConnectionDetails connectionDetails, ILogger logger)
{
var command = connectionDetails.Argv[0];
var args = connectionDetails.Argv[1..];
_process = new Process
{
StartInfo = new ProcessStartInfo(command, args)
{
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
// RedirectStandardError = true,
}
};

_process.Start();

_serverStdin = _process.StandardInput.BaseStream;
_serverStdout = _process.StandardOutput.BaseStream;
_process.ErrorDataReceived += ErrorDataReceived;
_logger = logger;
}

private void ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
_logger.LogError(e.Data);
}

public BuildServerClient CreateClient(
IServerCallbacks serverCallbacks,
TraceListener? traceListener = null)
{
return new BuildServerClient(_serverStdin, _serverStdout, serverCallbacks, traceListener);
}

public Task WaitForExitAsync(CancellationToken cancellationToken)
{
return _process.WaitForExitAsync(cancellationToken);
}

public int ExitCode => _process.ExitCode;

public void Dispose()
{
// var errors = _process.StandardError.ReadToEnd();
// _logger.LogError(errors);
if (!_process.HasExited)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
_process.Kill();
}
else
{
_process.Kill(ProcessExtensions.SIGINT);
}
}

_process.Dispose();
}
}
28 changes: 28 additions & 0 deletions src/bsp-client/IServerCallbacks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using bsp4csharp.Protocol;
using StreamJsonRpc;
using System.Threading.Tasks;

namespace bsp_client;

public interface IServerCallbacks
{
[JsonRpcMethod(Methods.BuildPublishDiagnostics, UseSingleObjectParameterDeserialization = true)]
public Task BuildPublishDiagnosticsRecievedAsync(PublishDiagnosticsParams publishDiagnosticsParams);

[JsonRpcMethod(Methods.BuildLogMessage, UseSingleObjectParameterDeserialization = true)]
public void BuildLogMessage(LogMessageParams logMessageParams);

[JsonRpcMethod(Methods.BuildTaskStart, UseSingleObjectParameterDeserialization = true)]
public Task BuildTaskStartAsync(TaskStartParams taskStartParams);

[JsonRpcMethod(Methods.BuildTaskProgress, UseSingleObjectParameterDeserialization = true)]
public Task BuildTaskProgressAsync(TaskProgressParams taskProgressParams);

[JsonRpcMethod(Methods.BuildTaskFinish, UseSingleObjectParameterDeserialization = true)]
public Task BuildTaskFinishAsync(TaskFinishParams taskFinishParams);

// public const string BuildShowMessage = "build/showMessage";
// public const string BuildTargetDidChange = "buildTarget/didChange";
// public const string RunPrintStdout = "run/printStdout";
// public const string RunPrintStderr = "run/printStderr";
}
17 changes: 17 additions & 0 deletions src/bsp-client/ProcessExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace bsp_client;

public static class ProcessExtensions
{
[DllImport ("libc", SetLastError=true, EntryPoint="kill")]
private static extern int sys_kill (int pid, int sig);

public static int SIGINT = 2;

public static void Kill(this Process process, int sig)
{
sys_kill(process.Id, sig);
}
}
17 changes: 17 additions & 0 deletions src/bsp-client/bsp-client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>bsp_client</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="StreamJsonRpc" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../bsp4csharp/bsp4csharp.csproj" />
</ItemGroup>

</Project>
Loading
Loading