More support for loading from reference files, now also registers UpsilonCreateStatic types
This commit is contained in:
parent
88d6767d56
commit
f8fe056b73
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -6,7 +6,11 @@ using Mono.Cecil;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Upsilon.BaseTypes.UserData;
|
using Upsilon.BaseTypes.UserData;
|
||||||
|
using Upsilon.Binder;
|
||||||
|
using Upsilon.Binder.VariableSymbols;
|
||||||
using Upsilon.BoundTypes;
|
using Upsilon.BoundTypes;
|
||||||
|
using Upsilon.StandardLibraries;
|
||||||
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
|
||||||
namespace UpsilonLanguageServer.ReferenceHandler
|
namespace UpsilonLanguageServer.ReferenceHandler
|
||||||
{
|
{
|
||||||
|
@ -42,7 +46,7 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
||||||
|
|
||||||
private static Dictionary<string, string> _translatedType;
|
private static Dictionary<string, string> _translatedType;
|
||||||
|
|
||||||
private static void LoadAssemblies(List<string> locations)
|
private static void LoadAssemblies(IReadOnlyCollection<string> locations)
|
||||||
{
|
{
|
||||||
var resolver = new DefaultAssemblyResolver();
|
var resolver = new DefaultAssemblyResolver();
|
||||||
foreach (var location in locations)
|
foreach (var location in locations)
|
||||||
|
@ -52,19 +56,23 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
_translatedType = new Dictionary<string, string>();
|
_translatedType = new Dictionary<string, string>();
|
||||||
var dictionary = locations.Select(x =>
|
var types = locations.Select(x =>
|
||||||
ModuleDefinition.ReadModule(x, new ReaderParameters() {AssemblyResolver = resolver}))
|
ModuleDefinition.ReadModule(x, new ReaderParameters() {AssemblyResolver = resolver}))
|
||||||
.SelectMany(file => file.Types, (file, type) => GetDefinitions(type))
|
.SelectMany(y => y.Types)
|
||||||
.SelectMany(definitions => definitions)
|
.ToArray();
|
||||||
.ToDictionary(definition => definition.Item1, definition => definition.Item2);
|
|
||||||
|
|
||||||
foreach (var definition in dictionary)
|
var requiredUserDataAttribute = typeof(UpsilonUserDataAttribute).FullName;
|
||||||
|
var userDataTypes = types
|
||||||
|
.SelectMany(x => GetDefinitions(x, requiredUserDataAttribute))
|
||||||
|
.ToDictionary(x => x.Item1, x => x.Item2);
|
||||||
|
|
||||||
|
foreach (var definition in userDataTypes)
|
||||||
{
|
{
|
||||||
_translatedType.Add(definition.Value.FullName, definition.Key);
|
_translatedType.Add(definition.Value.FullName, definition.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = new Dictionary<string, Data>();
|
var result = new Dictionary<string, Data>();
|
||||||
foreach (var definition in dictionary)
|
foreach (var definition in userDataTypes)
|
||||||
{
|
{
|
||||||
var name = definition.Key;
|
var name = definition.Key;
|
||||||
var type = definition.Value;
|
var type = definition.Value;
|
||||||
|
@ -100,7 +108,10 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
||||||
ActualType = y.Value.Type,
|
ActualType = y.Value.Type,
|
||||||
IsOptional = y.Value.IsOptional
|
IsOptional = y.Value.IsOptional
|
||||||
}).ToArray(), false);
|
}).ToArray(), false);
|
||||||
}).ToList()));
|
}).ToList())
|
||||||
|
{
|
||||||
|
Type = Type.Function
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -116,37 +127,44 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
||||||
BoundTypeHandler.LoadUserDataTypeDefinition(new UserDataBoundTypeDefinition(name, dic));
|
BoundTypeHandler.LoadUserDataTypeDefinition(new UserDataBoundTypeDefinition(name, dic));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static Type GetMonoType(this TypeReference type)
|
var requiredStaticAttribute = typeof(UpsilonCreateStaticAttribute).FullName;
|
||||||
{
|
var staticUserDataTypes = types
|
||||||
return Type.GetType(type.GetReflectionName(), true);
|
.SelectMany(x => GetDefinitions(x, requiredStaticAttribute))
|
||||||
}
|
.ToDictionary(x => x.Item1, x => x.Item2);
|
||||||
|
|
||||||
private static string GetReflectionName(this TypeReference type)
|
foreach (var staticUserDataType in staticUserDataTypes)
|
||||||
{
|
|
||||||
if (type.IsGenericInstance)
|
|
||||||
{
|
{
|
||||||
var genericInstance = (GenericInstanceType)type;
|
var variableSymbol = CreateVariableSymbol(staticUserDataType.Key, staticUserDataType.Value);
|
||||||
return
|
StaticScope.BoundScope.AssignToNearest(variableSymbol);
|
||||||
$"{genericInstance.Namespace}.{type.Name}[{string.Join(",", genericInstance.GenericArguments.Select(p => p.GetReflectionName()).ToArray())}]";
|
|
||||||
}
|
}
|
||||||
return type.FullName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<(string, TypeDefinition)> GetDefinitions(TypeDefinition typeDefinition)
|
private static VariableSymbol CreateVariableSymbol(string name, TypeDefinition def)
|
||||||
|
{
|
||||||
|
var type = BoundTypeParser.ParseType(name);
|
||||||
|
if (type == Type.UserData)
|
||||||
|
{
|
||||||
|
var boundTypeName = _translatedType[def.FullName];
|
||||||
|
var boundType = BoundTypeHandler.GetTypeDefinition(boundTypeName);
|
||||||
|
return new UserDataVariableSymbol(name, boundType, true);
|
||||||
|
}
|
||||||
|
return new VariableSymbol(name, type, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<(string, TypeDefinition)> GetDefinitions(TypeDefinition typeDefinition,
|
||||||
|
string requiredAttribute)
|
||||||
{
|
{
|
||||||
var ls = new List<(string, TypeDefinition)>();
|
var ls = new List<(string, TypeDefinition)>();
|
||||||
foreach (var nestedType in typeDefinition.NestedTypes)
|
foreach (var nestedType in typeDefinition.NestedTypes)
|
||||||
{
|
{
|
||||||
var definitions = GetDefinitions(nestedType);
|
var definitions = GetDefinitions(nestedType, requiredAttribute);
|
||||||
if (definitions.Count > 0)
|
if (definitions.Count > 0)
|
||||||
{
|
{
|
||||||
ls.AddRange(definitions);
|
ls.AddRange(definitions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var requiredAttribute = typeof(UpsilonUserDataAttribute).FullName;
|
|
||||||
if (!typeDefinition.HasCustomAttributes) return ls;
|
if (!typeDefinition.HasCustomAttributes) return ls;
|
||||||
foreach (var customAttribute in typeDefinition.CustomAttributes)
|
foreach (var customAttribute in typeDefinition.CustomAttributes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,8 @@ using JsonRpc.Standard.Contracts;
|
||||||
using JsonRpc.Standard.Server;
|
using JsonRpc.Standard.Server;
|
||||||
using LanguageServer.VsCode.Contracts;
|
using LanguageServer.VsCode.Contracts;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using UpsilonLanguageServer.ReferenceHandler;
|
||||||
|
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
|
||||||
namespace UpsilonLanguageServer.Services
|
namespace UpsilonLanguageServer.Services
|
||||||
|
@ -38,6 +40,13 @@ namespace UpsilonLanguageServer.Services
|
||||||
Session.Settings.ModuleDirectory =
|
Session.Settings.ModuleDirectory =
|
||||||
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory))
|
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory))
|
||||||
.FullName;
|
.FullName;
|
||||||
|
|
||||||
|
var referenceConfigFile = configPath + "/references.json";
|
||||||
|
if (File.Exists(referenceConfigFile))
|
||||||
|
{
|
||||||
|
LoadReferenceLibraries.ReloadReferences(WorkspaceService.RootUri,
|
||||||
|
File.ReadAllText(referenceConfigFile));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -113,6 +113,12 @@ namespace UpsilonLanguageServer.Services
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LoadReferenceLibraries.ReloadReferences(RootUri, File.ReadAllText(localPath));
|
LoadReferenceLibraries.ReloadReferences(RootUri, File.ReadAllText(localPath));
|
||||||
|
foreach (var doc in Session.Documents.Values)
|
||||||
|
{
|
||||||
|
var diag = await DiagnosticProvider.LintDocument(doc.Document, doc,
|
||||||
|
Session.Settings.MaxNumberOfProblems, Session.Settings.ModuleDirectory);
|
||||||
|
await Client.Document.PublishDiagnostics(doc.Document.Uri, diag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue