Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 14, 2023
1 parent 0b345f7 commit f01bcc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 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
21 changes: 8 additions & 13 deletions src/Draco.Lsp/Server/LanguageServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,22 @@ public LanguageServerConnection(IDuplexPipe transport)
protected override LspMessage CreateOkResponseMessage(object id, JsonElement okResult) => new(new ResponseMessage
{
Jsonrpc = "2.0",
Id = id switch
{
int i => i,
string s => s,
_ => -1,
},
Id = (OneOf<int, string>)id,
Result = okResult,
});
protected override LspMessage CreateErrorResponseMessage(object id, ResponseError errorResult) => new(new ResponseMessage
{
Jsonrpc = "2.0",
Id = id switch
{
int i => i,
string s => s,
_ => -1,
},
Id = (OneOf<int, string>)id,
Error = errorResult,
});
protected override LspMessage CreateCancelRequestMessage(int id) => throw new NotImplementedException();
protected override LspMessage CreateNotificationMessage(string method, JsonElement @params) => throw new NotImplementedException();
protected override LspMessage CreateNotificationMessage(string method, JsonElement @params) => new(new NotificationMessage
{
Jsonrpc = "2.0",
Method = method,
Params = @params,
});

protected override ResponseError CreateExceptionError(Exception exception)
{
Expand Down

0 comments on commit f01bcc4

Please sign in to comment.