Skip to content

Commit

Permalink
LSP and DAP communication refactor (#335)
Browse files Browse the repository at this point in the history
* Restarted lib

* Added message adapter

* Added handler

* Update IJsonRpcMessageAdapter.cs

* Added request handling

* Completed connection flow

* Update JsonRpcConnection.cs

* Update OneOf.sbncs

* Tweaks

* More tweaks

* Update IJsonRpcMethodHandler.cs

* Update IJsonRpcMethodHandler.cs

* No exception but hangs

* Fixes

* Fixed hanging task

* All fixed

* Shutdown

* Updating RPC connection

* Docs

* Update JsonRpcConnection.cs

* Ported to new code

* Debug adapter ported

* Factored out proxy

* Factored out method handler

* Unused usings

* Update JsonRpcConnection.cs

* Update JsonRpcConnection.cs

* Update JsonRpcConnection.cs

* Simplification
  • Loading branch information
LPeter1997 authored Oct 21, 2023
1 parent 3a244c5 commit 616115e
Show file tree
Hide file tree
Showing 30 changed files with 1,232 additions and 1,444 deletions.
17 changes: 4 additions & 13 deletions src/Draco.Compiler/Internal/Symbols/Metadata/TypeProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand All @@ -21,7 +22,7 @@ internal sealed class TypeProvider : ISignatureTypeProvider<TypeSymbol, Symbol>,
private IntrinsicSymbols IntrinsicSymbols => this.compilation.IntrinsicSymbols;

private readonly Compilation compilation;
private readonly Dictionary<CacheKey, TypeSymbol> cache = new();
private readonly ConcurrentDictionary<CacheKey, TypeSymbol> cache = new();

public TypeProvider(Compilation compilation)
{
Expand Down Expand Up @@ -94,12 +95,7 @@ public TypeSymbol GetGenericTypeParameter(Symbol genericContext, int index)
public TypeSymbol GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
{
var key = new CacheKey(reader, handle);
if (!this.cache.TryGetValue(key, out var type))
{
type = this.BuildTypeFromDefinition(reader, handle, rawTypeKind);
this.cache.Add(key, type);
}
return type;
return this.cache.GetOrAdd(key, _ => this.BuildTypeFromDefinition(reader, handle, rawTypeKind));
}

private TypeSymbol BuildTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
Expand Down Expand Up @@ -137,12 +133,7 @@ private TypeSymbol BuildTypeFromDefinition(MetadataReader reader, TypeDefinition
public TypeSymbol GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
{
var key = new CacheKey(reader, handle);
if (!this.cache.TryGetValue(key, out var type))
{
type = this.BuildTypeFromReference(reader, handle, rawTypeKind);
this.cache.Add(key, type);
}
return type;
return this.cache.GetOrAdd(key, _ => this.BuildTypeFromReference(reader, handle, rawTypeKind));
}

private TypeSymbol BuildTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
Expand Down
5 changes: 3 additions & 2 deletions src/Draco.Dap/Adapter/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Threading.Tasks;
using Draco.Dap.Attributes;
using Draco.JsonRpc;

namespace Draco.Dap.Adapter;

Expand Down Expand Up @@ -50,7 +51,7 @@ public static async Task RunAsync(this IDebugClient client, IDebugAdapter adapte
await connection.ListenAsync();
}

private static void RegisterAdapterRpcMethods(object target, DebugAdapterConnection connection)
private static void RegisterAdapterRpcMethods(object target, IJsonRpcConnection connection)
{
// Go through all methods of the adapter and register it
// NOTE: We go through the interfaces, because interface attributes are not inherited
Expand All @@ -62,7 +63,7 @@ private static void RegisterAdapterRpcMethods(object target, DebugAdapterConnect

foreach (var method in adapterMethods)
{
connection.AddRpcMethod(method, target);
connection.AddHandler(DebugAdapterMethodHandler.Create(method, target));
}
}

Expand Down
Loading

0 comments on commit 616115e

Please sign in to comment.