Skip to content

Commit

Permalink
It's alive!
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Sep 24, 2022
1 parent b00e76e commit f3c35eb
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 26 deletions.
36 changes: 36 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/tests/WebAssembly/TestWithoutWebAssembly/TestWithoutWebAssembly.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/tests/WebAssembly/TestWithoutWebAssembly/TestWithoutWebAssembly.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/tests/WebAssembly/TestWithoutWebAssembly/TestWithoutWebAssembly.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
2 changes: 1 addition & 1 deletion src/OmniSharp.Abstractions/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace OmniSharp
{
internal static class Configuration
{
public static bool ZeroBasedIndices = false;
public static bool ZeroBasedIndices = true;

public const string RoslynVersion = "4.4.0.0";
public const string RoslynPublicKeyToken = "31bf3856ad364e35";
Expand Down
26 changes: 13 additions & 13 deletions src/OmniSharp.Roslyn.CSharp/Services/InlayHints/InlayHintService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,26 @@ public async Task<InlayHintResponse> Handle(InlayHintRequest request)
var sourceText = await document.GetTextAsync();
var mappedSpan = sourceText.GetSpanFromRange(request.Location.Range);

var inlayHintsOptions = _omniSharpOptions.CurrentValue.RoslynExtensionsOptions.InlayHintsOptions;
//var inlayHintsOptions = _omniSharpOptions.CurrentValue.RoslynExtensionsOptions.InlayHintsOptions;
var options = new OmniSharpInlineHintsOptions
{
ParameterOptions = new()
{
EnabledForParameters = inlayHintsOptions.EnableForParameters,
ForIndexerParameters = inlayHintsOptions.ForIndexerParameters,
ForLiteralParameters = inlayHintsOptions.ForLiteralParameters,
ForObjectCreationParameters = inlayHintsOptions.ForObjectCreationParameters,
ForOtherParameters = inlayHintsOptions.ForOtherParameters,
SuppressForParametersThatDifferOnlyBySuffix = inlayHintsOptions.SuppressForParametersThatDifferOnlyBySuffix,
SuppressForParametersThatMatchArgumentName = inlayHintsOptions.SuppressForParametersThatMatchArgumentName,
SuppressForParametersThatMatchMethodIntent = inlayHintsOptions.SuppressForParametersThatMatchMethodIntent,
EnabledForParameters = true,
ForIndexerParameters = true,
ForLiteralParameters = true,
ForObjectCreationParameters = true,
ForOtherParameters = true,
SuppressForParametersThatDifferOnlyBySuffix = true,
SuppressForParametersThatMatchArgumentName = true,
SuppressForParametersThatMatchMethodIntent = true,
},
TypeOptions = new()
{
EnabledForTypes = inlayHintsOptions.EnableForTypes,
ForImplicitObjectCreation = inlayHintsOptions.ForImplicitObjectCreation,
ForImplicitVariableTypes = inlayHintsOptions.ForImplicitVariableTypes,
ForLambdaParameterTypes = inlayHintsOptions.ForLambdaParameterTypes,
EnabledForTypes = true,
ForImplicitObjectCreation = true,
ForImplicitVariableTypes = true,
ForLambdaParameterTypes = true,
}
};

Expand Down
14 changes: 12 additions & 2 deletions src/OmniSharp.Roslyn/OmniSharpWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public bool Initialized
public OmniSharpWorkspace(HostServicesAggregator aggregator, ILoggerFactory loggerFactory, IFileSystemWatcher fileSystemWatcher)
: this(aggregator.CreateHostServices(), loggerFactory, fileSystemWatcher)
{
if (PathRemapper is null)
{
PathRemapper = new EmptyRemapper();
}
}

public OmniSharpWorkspace(HostServices hostServices, ILoggerFactory loggerFactory, IFileSystemWatcher fileSystemWatcher)
Expand All @@ -61,8 +65,12 @@ public OmniSharpWorkspace(HostServices hostServices, ILoggerFactory loggerFactor
BufferManager = new BufferManager(this, loggerFactory, fileSystemWatcher);
_logger = loggerFactory.CreateLogger<OmniSharpWorkspace>();
fileSystemWatcher.WatchDirectories(OnDirectoryRemoved);
PathRemapper = new EmptyRemapper();
}

[Import(AllowDefault = true)]
public IPathRemapper PathRemapper { get; set; }

public override bool CanOpenDocuments => true;


Expand Down Expand Up @@ -338,14 +346,16 @@ public void OnDocumentChanged(DocumentId documentId, SourceText text)

public DocumentId GetDocumentId(string filePath)
{
var documentIds = CurrentSolution.GetDocumentIdsWithFilePath(filePath);
var remapped = PathRemapper.Remap(filePath);
_logger.LogInformation("Remapped path is " + remapped);
var documentIds = CurrentSolution.GetDocumentIdsWithFilePath(remapped);
return documentIds.FirstOrDefault();
}

public IEnumerable<Document> GetDocuments(string filePath)
{
return CurrentSolution
.GetDocumentIdsWithFilePath(filePath)
.GetDocumentIdsWithFilePath(PathRemapper.Remap(filePath))
.Select(id => CurrentSolution.GetDocument(id))
.OfType<Document>();
}
Expand Down
13 changes: 13 additions & 0 deletions src/OmniSharp.Roslyn/WorkspaceServices/IPathRemapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Composition;

namespace OmniSharp;

public interface IPathRemapper
{
string Remap(string path);
}

internal class EmptyRemapper : IPathRemapper
{
public string Remap(string path) => path;
}
20 changes: 20 additions & 0 deletions src/OmniSharp.Stdio/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ public class Host : IDisposable
private readonly CachedStringBuilder _cachedStringBuilder;
private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;

public Host(
TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment,
IServiceProvider serviceProvider, CompositionHost compositionHost, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource)
{
_cancellationTokenSource = cancellationTokenSource;
_input = input;
_writer = writer;
_environment = environment;
_serviceProvider = serviceProvider;
_logger = loggerFactory.CreateLogger<Host>();

_logger.LogInformation($"Starting OmniSharp on {"todo: refactor"/*Platform.Current*/}");

_compositionHost = compositionHost;
_cachedStringBuilder = new CachedStringBuilder();

var handlers = Initialize();
_endpointHandlers = handlers;
}

public Host(
TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment,
IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
a new enough System.Memory and we'll get method missing exceptions when we are
running with some newer MSBuild versions. -->
<PackageReference Include="System.Memory" />
<PackageReference Include="StrongNamer" Version="0.2.5" />

<PackageReference Include="DotNetJS" Version="*" GeneratePathProperty="true" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/OmniSharp.WebAssembly.Driver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static void HandleRequest(string request)
}

[JSInvokable]
public static async Task<string> InitializeAsync(byte[] compilerLogBytes)
public static async Task<string> InitializeAsync(byte[] compilerLogBytes, string workspaceBasePath)
{
return await WebAssembly.Program.InitializeAsync(compilerLogBytes, new StreamReader(_inputStream), _outputWriter, _loggerProvider);
return await WebAssembly.Program.InitializeAsync(compilerLogBytes, workspaceBasePath, new StreamReader(_inputStream), _outputWriter, _loggerProvider);
}

class OutputWriter : ISharedTextWriter
Expand Down
2 changes: 2 additions & 0 deletions src/OmniSharp.WebAssembly/CompilerLoggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ namespace OmniSharp.WebAssembly;
internal class CompilerLoggerOptions
{
public Uri LogUri { get; set; } = null!;
public string CompilerLogBasePath { get; set; } = null!;
public string WorkspaceBasePath { get; set; } = null!;
}
29 changes: 29 additions & 0 deletions src/OmniSharp.WebAssembly/CompilerLoggerPathRemapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Composition;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace OmniSharp.WebAssembly;

[Export(typeof(IPathRemapper)), Shared]
internal class CompilerLoggerPathRemapper : IPathRemapper
{
private readonly string _compilerLogBasePath;
private readonly string _workspaceBasePath;
private readonly CompilerLoggerOptions _options = new();

[ImportingConstructor]
public CompilerLoggerPathRemapper(IServiceProvider serviceProvider)
{
var configuration = serviceProvider.GetService<IConfigurationRoot>();
var section = configuration!.GetSection("CompilerLogger");
section.Bind(_options);
_compilerLogBasePath = _options.CompilerLogBasePath;
_workspaceBasePath = _options.WorkspaceBasePath;
}

public string Remap(string path)
{
return path.Replace(_workspaceBasePath, _compilerLogBasePath);
}
}
18 changes: 15 additions & 3 deletions src/OmniSharp.WebAssembly/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using OmniSharp.Stdio;
using OmniSharp.Protocol;
using OmniSharp.Roslyn.CSharp.Services;
using System.Text;
using Microsoft.Extensions.Configuration;

namespace OmniSharp.WebAssembly;

Expand All @@ -21,7 +23,7 @@ public class Program
private static CancellationTokenSource _source = new();
private static Host? _host;

public static async Task<string> InitializeAsync(byte[] compilerLogBytes, TextReader input, ISharedTextWriter outputWriter, ILoggerProvider? loggerProvider = null)
public static async Task<string> InitializeAsync(byte[] compilerLogBytes, string workspaceBasePath, TextReader input, ISharedTextWriter outputWriter, ILoggerProvider? loggerProvider = null)
{
try
{
Expand All @@ -31,7 +33,17 @@ public static async Task<string> InitializeAsync(byte[] compilerLogBytes, TextRe

var environment = new OmniSharpEnvironment(logLevel: LogLevel.Trace);
CompilerLoggerProjectSystem.CompilerLogBytes = compilerLogBytes;
var configurationResult = new ConfigurationBuilder(environment).Build((builder) => { });
var configurationResult = new ConfigurationBuilder(environment).Build((builder) =>
{
var jsonOptions =
$@"{{
""CompilerLogger"": {{
""{nameof(CompilerLoggerOptions.CompilerLogBasePath)}"": ""/home/runner/work/wasm-test/wasm-test"",
""{nameof(CompilerLoggerOptions.WorkspaceBasePath)}"": ""{workspaceBasePath}""
}}
}}";
_ = builder.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(jsonOptions)));
});
if (configurationResult.HasError())
{
logger.LogInformation("config exception: " + configurationResult.Exception);
Expand Down Expand Up @@ -61,7 +73,7 @@ public static async Task<string> InitializeAsync(byte[] compilerLogBytes, TextRe

// todo cancellation token?
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
_host = new Host(input, outputWriter, environment, serviceProvider, compositionHostBuilder, loggerFactory, _source);
_host = new Host(input, outputWriter, environment, serviceProvider, composition, loggerFactory, _source);
// something weird with tasks / cancellation / readline in the host.start.
// instead just implement simpler version where we just write start, then call HandleRequest whenever JS calls into us.
outputWriter.WriteLine(new EventPacket()
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.WebAssembly/OmniSharp.WebAssembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/WebAssembly/TestWithWebAssembly/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
var memoryStream = new MemoryStream();
var stream = e.File.OpenReadStream(maxAllowedSize: 2147483648);
await stream.CopyToAsync(memoryStream);
var response = await OmniSharp.WebAssembly.Program.InitializeAsync(memoryStream.ToArray(), new StreamReader(new MemoryStream()), new RazorLogger(this, "Output"), _loggerProvider!);
var response = await OmniSharp.WebAssembly.Program.InitializeAsync(memoryStream.ToArray(), "/home/fred/git/wasm-test", new StreamReader(new MemoryStream()), new RazorLogger(this, "Output"), _loggerProvider!);
if (response == "done")
{
IsServerRunning = true;
Expand Down
20 changes: 17 additions & 3 deletions tests/WebAssembly/TestWithoutWebAssembly/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ namespace TestWebAssemblyDriver;

internal class Program
{
static void Main(string[] args)
static async Task Main(string[] args)
{
var compilerLogBytes = File.ReadAllBytes(@"C:\Users\dabarbet\Downloads\msbuild.compilerlog");
var response = OmniSharp.WebAssembly.Program.InitializeAsync(compilerLogBytes, Console.In, new SharedTextWriter(Console.Out)).Result;
var compilerLogBytes = File.ReadAllBytes(@"/home/fred/Downloads/msbuild.compilerlog");
var response = await OmniSharp.WebAssembly.Program.InitializeAsync(compilerLogBytes, "/home/fred/git/wasm-test", Console.In, new SharedTextWriter(Console.Out));
Console.WriteLine(response);

await OmniSharp.WebAssembly.Program.InvokeRequestAsync("""
{
"Type": "request",
"Seq": 73,
"Command": "/quickinfo",
"Arguments": {
"FileName": "/home/fred/git/wasm-test/Program.cs",
"Line": 1,
"Column": 32
}
}
""");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit f3c35eb

Please sign in to comment.