Skip to content

Commit e3858c8

Browse files
authored
fix(#4): build target uri for windows
* cleanup: remove unused CreateNewPipeNames function * fix(#4): fix TargetBuild URI for windows * fix: build target file path for windows * fix: diagnostic messages to not rely on english locale * chore: update dependencies * fix: update lock file * test: increase cancelation time for windows runners * fix: weird issue with paths for linux and windows * fix: use LocalPath instead of AbsolutePath from Uri * fix: windows runner test canceled
1 parent 198aece commit e3858c8

16 files changed

+134
-149
lines changed

src/bsp-server/Handlers/BuildTargetCleanCacheHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Task<CleanCacheResult> HandleRequestAsync(CleanCacheParams cleanCachePara
5151
}
5252
}
5353

54-
var workspacePath = initParams.RootUri.AbsolutePath;
54+
var workspacePath = initParams.RootUri.LocalPath;
5555
context.Logger.LogInformation("GetLoadedProjects from {}", workspacePath);
5656
foreach (var proj in projects.LoadedProjects)
5757
{

src/bsp-server/Handlers/BuildTargetCompileHandler.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public Task<CompileResult> HandleRequestAsync(CompileParams compileParams, Reque
2222
_initializeManager.EnsureInitialized();
2323

2424
var projects = new ProjectCollection();
25-
var buildResult = false;
25+
var buildResult = true;
2626
var targetFiles = compileParams.Targets.Select(x => x.ToString());
2727
var graph = new ProjectGraph(targetFiles, projects);
2828
var initParams = _initializeManager.GetInitializeParams();
2929
if (initParams.RootUri.IsFile)
3030
{
31-
var workspacePath = initParams.RootUri.AbsolutePath;
31+
var workspacePath = initParams.RootUri.LocalPath;
3232
context.Logger.LogInformation("GetLoadedProjects from {}", workspacePath);
3333
_baseProtocolClientManager.SendClearDiagnosticsMessage();
3434

@@ -40,14 +40,18 @@ public Task<CompileResult> HandleRequestAsync(CompileParams compileParams, Reque
4040
context.Logger.LogInformation("Global Properties: {}", string.Join("\n", globalProps));
4141
context.Logger.LogInformation("Start restore target: {}", proj.ProjectInstance.FullPath);
4242
var msBuildLogger = new MSBuildLogger(_baseProtocolClientManager, compileParams.OriginId, workspacePath, proj.ProjectInstance.FullPath);
43-
buildResult &= proj.ProjectInstance.Build(["Restore"], [msBuildLogger]);
43+
var result = proj.ProjectInstance.Build(["Restore"], [msBuildLogger]);
44+
context.Logger.LogInformation($"{proj.ProjectInstance.FullPath} restore result: {result}");
45+
buildResult &= result;
4446
}
4547

4648
foreach (var proj in graph.ProjectNodesTopologicallySorted)
4749
{
4850
context.Logger.LogInformation("Start building target: {}", proj.ProjectInstance.FullPath);
4951
var msBuildLogger = new MSBuildLogger(_baseProtocolClientManager, compileParams.OriginId, workspacePath, proj.ProjectInstance.FullPath);
50-
buildResult &= proj.ProjectInstance.Build(["Build"], [msBuildLogger]);
52+
var result = proj.ProjectInstance.Build(["Build"], [msBuildLogger]);
53+
context.Logger.LogInformation($"{proj.ProjectInstance.FullPath} restore result: {result}");
54+
buildResult &= result;
5155
}
5256
}
5357

src/bsp-server/Handlers/BuildTargetRunHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private async Task RunTargetAsync(string target, string? originId, RequestContex
7777
var projectFile = target;
7878
var proj = new ProjectInstance(projectFile);
7979
var initParams = _initializeManager.GetInitializeParams();
80-
var workspacePath = initParams.RootUri.AbsolutePath;
80+
var workspacePath = initParams.RootUri.LocalPath;
8181

8282
var msBuildLogger = new MSBuildLogger(_baseProtocolClientManager, originId, workspacePath, projectFile);
8383
proj.Build(["Restore", "Build"], [msBuildLogger]);

src/bsp-server/Handlers/BuildTargetTestCaseDiscoveryHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Task<TestCaseDiscoveryResult> HandleRequestAsync(TestCaseDiscoveryParams
7575
}
7676
}
7777

78-
var workspacePath = initParams.RootUri.AbsolutePath;
78+
var workspacePath = initParams.RootUri.LocalPath;
7979
_baseProtocolClientManager.SendClearDiagnosticsMessage();
8080
var testProjects = projects.LoadedProjects.Where(x => x.IsTestProject());
8181
context.Logger.LogInformation("Get loaded test projects from {}", workspacePath);

src/bsp-server/Handlers/BuildTargetTestHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Task<TestResult> HandleRequestAsync(TestParams testParams, RequestContext
7979
}
8080
}
8181

82-
var workspacePath = initParams.RootUri.AbsolutePath;
82+
var workspacePath = initParams.RootUri.LocalPath;
8383
_baseProtocolClientManager.SendClearDiagnosticsMessage();
8484
var testProjects = projects.LoadedProjects.Where(x => x.IsTestProject());
8585
context.Logger.LogInformation("Get loaded test projects from {}", workspacePath);

src/bsp-server/Handlers/WorkspaceBuildTargetsHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Task<WorkspaceBuildTargetsResult> HandleRequestAsync(RequestContext conte
2626
var initParams = _initializeManager.GetInitializeParams();
2727
if (initParams.RootUri.IsFile)
2828
{
29-
var workspacePath = initParams.RootUri.AbsolutePath;
29+
var workspacePath = initParams.RootUri.LocalPath;
3030
var buildTargets = GetBuildTargetsInWorkspace(workspacePath, context.Logger);
3131
list.AddRange(buildTargets);
3232
}
Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
using BaseProtocol;
2-
using BaseProtocol.Protocol;
3-
using Microsoft.Extensions.Logging;
4-
5-
/// <summary>
6-
/// Implements an ILogger that seamlessly switches from a fallback logger
7-
/// to BSP log messages as soon as the server initializes.
8-
/// </summary>
9-
internal sealed class BspLogMessageLogger : ILogger
10-
{
11-
private readonly string _categoryName;
12-
private readonly ILogger _fallbackLogger;
13-
14-
public BspLogMessageLogger(string categoryName, ILoggerFactory fallbackLoggerFactory)
15-
{
16-
_categoryName = categoryName;
17-
_fallbackLogger = fallbackLoggerFactory.CreateLogger(categoryName);
18-
}
19-
20-
public IDisposable BeginScope<TState>(TState state) where TState : notnull
21-
{
22-
throw new NotImplementedException();
23-
}
24-
25-
public bool IsEnabled(LogLevel logLevel)
26-
{
27-
return true;
28-
}
29-
30-
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
31-
{
32-
var server = BuildServerHost.Instance;
33-
if (server == null)
34-
{
35-
// If the language server has not been initialized yet, log using the fallback logger.
36-
_fallbackLogger.Log(logLevel, eventId, state, exception, formatter);
37-
return;
38-
}
39-
40-
var message = formatter(state, exception);
41-
42-
// HACK: work around https://github.com/dotnet/runtime/issues/67597: the formatter function we passed the exception to completely ignores the exception,
43-
// we'll add an exception message back in. If we didn't have a message, we'll just replace it with the exception text.
44-
if (exception != null)
45-
{
46-
var exceptionString = exception.ToString();
47-
if (message == "[null]") // https://github.com/dotnet/runtime/blob/013ca673f6316dbbe71c7b327d7b8fa41cf8c992/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs#L19
48-
message = exceptionString;
49-
else
50-
message += " " + exceptionString;
51-
}
52-
53-
if (message != null && logLevel != LogLevel.None)
54-
{
55-
message = $"[{_categoryName}] {message}";
56-
var _ = server.GetRequiredBspService<IBaseProtocolClientManager>().SendNotificationAsync(bsp4csharp.Protocol.Methods.BuildLogMessage, new LogMessageParams()
57-
{
58-
Message = message,
59-
MessageType = logLevel switch
60-
{
61-
LogLevel.Trace => MessageType.Log,
62-
LogLevel.Debug => MessageType.Log,
63-
LogLevel.Information => MessageType.Info,
64-
LogLevel.Warning => MessageType.Warning,
65-
LogLevel.Error => MessageType.Error,
66-
LogLevel.Critical => MessageType.Error,
67-
_ => throw new InvalidOperationException($"Unexpected logLevel argument {logLevel}"),
68-
}
69-
}, CancellationToken.None);
70-
}
71-
}
72-
}
1+
using BaseProtocol;
2+
using BaseProtocol.Protocol;
3+
using Microsoft.Extensions.Logging;
4+
5+
/// <summary>
6+
/// Implements an ILogger that seamlessly switches from a fallback logger
7+
/// to BSP log messages as soon as the server initializes.
8+
/// </summary>
9+
internal sealed class BspLogMessageLogger : ILogger
10+
{
11+
private readonly string _categoryName;
12+
private readonly ILogger _fallbackLogger;
13+
14+
public BspLogMessageLogger(string categoryName, ILoggerFactory fallbackLoggerFactory)
15+
{
16+
_categoryName = categoryName;
17+
_fallbackLogger = fallbackLoggerFactory.CreateLogger(categoryName);
18+
}
19+
20+
public IDisposable BeginScope<TState>(TState state) where TState : notnull
21+
{
22+
throw new NotImplementedException();
23+
}
24+
25+
public bool IsEnabled(LogLevel logLevel)
26+
{
27+
return true;
28+
}
29+
30+
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
31+
{
32+
var server = BuildServerHost.Instance;
33+
if (server == null)
34+
{
35+
// If the language server has not been initialized yet, log using the fallback logger.
36+
_fallbackLogger.Log(logLevel, eventId, state, exception, formatter);
37+
return;
38+
}
39+
40+
var message = formatter(state, exception);
41+
42+
// HACK: work around https://github.com/dotnet/runtime/issues/67597: the formatter function we passed the exception to completely ignores the exception,
43+
// we'll add an exception message back in. If we didn't have a message, we'll just replace it with the exception text.
44+
if (exception != null)
45+
{
46+
var exceptionString = exception.ToString();
47+
if (message == "[null]") // https://github.com/dotnet/runtime/blob/013ca673f6316dbbe71c7b327d7b8fa41cf8c992/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs#L19
48+
message = exceptionString;
49+
else
50+
message += " " + exceptionString;
51+
}
52+
53+
if (message != null && logLevel != LogLevel.None)
54+
{
55+
message = $"[{_categoryName}] {message}";
56+
var _ = server.GetRequiredBspService<IBaseProtocolClientManager>().SendNotificationAsync(bsp4csharp.Protocol.Methods.BuildLogMessage, new LogMessageParams()
57+
{
58+
Message = message,
59+
MessageType = logLevel switch
60+
{
61+
LogLevel.Trace => MessageType.Log,
62+
LogLevel.Debug => MessageType.Log,
63+
LogLevel.Information => MessageType.Info,
64+
LogLevel.Warning => MessageType.Warning,
65+
LogLevel.Error => MessageType.Error,
66+
LogLevel.Critical => MessageType.Error,
67+
_ => throw new InvalidOperationException($"Unexpected logLevel argument {logLevel}"),
68+
}
69+
}, CancellationToken.None);
70+
}
71+
}
72+
}

src/bsp-server/Program.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,4 @@ static CliRootCommand CreateCommandLineParser()
132132
return RunAsync(serverConfiguration, cancellationToken);
133133
});
134134
return rootCommand;
135-
}
136-
137-
static (string clientPipe, string serverPipe) CreateNewPipeNames()
138-
{
139-
// On windows, .NET and Nodejs use different formats for the pipe name
140-
const string WINDOWS_NODJS_PREFIX = @"\\.\pipe\";
141-
const string WINDOWS_DOTNET_PREFIX = @"\\.\";
142-
143-
// The pipe name constructed by some systems is very long (due to temp path).
144-
// Shorten the unique id for the pipe.
145-
var newGuid = Guid.NewGuid().ToString();
146-
var pipeName = newGuid.Split('-')[0];
147-
148-
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
149-
? (WINDOWS_NODJS_PREFIX + pipeName, WINDOWS_DOTNET_PREFIX + pipeName)
150-
: (GetUnixTypePipeName(pipeName), GetUnixTypePipeName(pipeName));
151-
152-
static string GetUnixTypePipeName(string pipeName)
153-
{
154-
// Unix-type pipes are actually writing to a file
155-
return Path.Combine(Path.GetTempPath(), pipeName + ".sock");
156-
}
157135
}

src/bsp-server/dotnet-bsp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReference Include="Microsoft.TestPlatform" Version="17.11.1" />
2626
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.11.1" />
2727
<PackageReference Include="Microsoft.TestPlatform.TranslationLayer" Version="17.11.1" />
28-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.24324.3" />
28+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.24528.1" />
2929
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
3030
</ItemGroup>
3131

src/bsp-server/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@
104104
},
105105
"System.CommandLine": {
106106
"type": "Direct",
107-
"requested": "[2.0.0-beta4.24324.3, )",
108-
"resolved": "2.0.0-beta4.24324.3",
109-
"contentHash": "UddDcdPmeAbRpkYHOMBHYS74UINTL5yXhzHTbruhVN7eR79J8RPGgq1nNXlz5TH4iMK/Fn6OlSFf4Z2UxCJpXw=="
107+
"requested": "[2.0.0-beta4.24528.1, )",
108+
"resolved": "2.0.0-beta4.24528.1",
109+
"contentHash": "Xt8tsSU8yd0ZpbT9gl5DAwkMYWLo8PV1fq2R/belrUbHVVOIKqhLfbWksbdknUDpmzMHZenBtD6AGAp9uJTa2w=="
110110
},
111111
"System.ComponentModel.Composition": {
112112
"type": "Direct",

0 commit comments

Comments
 (0)