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.Linq;
|
||||
using Upsilon.BaseTypes.UserData;
|
||||
using Upsilon.Binder;
|
||||
using Upsilon.Binder.VariableSymbols;
|
||||
using Upsilon.BoundTypes;
|
||||
using Upsilon.StandardLibraries;
|
||||
using Type = Upsilon.BaseTypes.Type;
|
||||
|
||||
namespace UpsilonLanguageServer.ReferenceHandler
|
||||
{
|
||||
|
@ -42,7 +46,7 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
|||
|
||||
private static Dictionary<string, string> _translatedType;
|
||||
|
||||
private static void LoadAssemblies(List<string> locations)
|
||||
private static void LoadAssemblies(IReadOnlyCollection<string> locations)
|
||||
{
|
||||
var resolver = new DefaultAssemblyResolver();
|
||||
foreach (var location in locations)
|
||||
|
@ -52,19 +56,23 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
|||
}
|
||||
|
||||
_translatedType = new Dictionary<string, string>();
|
||||
var dictionary = locations.Select(x =>
|
||||
var types = locations.Select(x =>
|
||||
ModuleDefinition.ReadModule(x, new ReaderParameters() {AssemblyResolver = resolver}))
|
||||
.SelectMany(file => file.Types, (file, type) => GetDefinitions(type))
|
||||
.SelectMany(definitions => definitions)
|
||||
.ToDictionary(definition => definition.Item1, definition => definition.Item2);
|
||||
.SelectMany(y => y.Types)
|
||||
.ToArray();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
var result = new Dictionary<string, Data>();
|
||||
foreach (var definition in dictionary)
|
||||
foreach (var definition in userDataTypes)
|
||||
{
|
||||
var name = definition.Key;
|
||||
var type = definition.Value;
|
||||
|
@ -100,7 +108,10 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
|||
ActualType = y.Value.Type,
|
||||
IsOptional = y.Value.IsOptional
|
||||
}).ToArray(), false);
|
||||
}).ToList()));
|
||||
}).ToList())
|
||||
{
|
||||
Type = Type.Function
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -116,37 +127,44 @@ namespace UpsilonLanguageServer.ReferenceHandler
|
|||
BoundTypeHandler.LoadUserDataTypeDefinition(new UserDataBoundTypeDefinition(name, dic));
|
||||
}
|
||||
}
|
||||
|
||||
var requiredStaticAttribute = typeof(UpsilonCreateStaticAttribute).FullName;
|
||||
var staticUserDataTypes = types
|
||||
.SelectMany(x => GetDefinitions(x, requiredStaticAttribute))
|
||||
.ToDictionary(x => x.Item1, x => x.Item2);
|
||||
|
||||
foreach (var staticUserDataType in staticUserDataTypes)
|
||||
{
|
||||
var variableSymbol = CreateVariableSymbol(staticUserDataType.Key, staticUserDataType.Value);
|
||||
StaticScope.BoundScope.AssignToNearest(variableSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
private static Type GetMonoType(this TypeReference type)
|
||||
private static VariableSymbol CreateVariableSymbol(string name, TypeDefinition def)
|
||||
{
|
||||
return Type.GetType(type.GetReflectionName(), true);
|
||||
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 string GetReflectionName(this TypeReference type)
|
||||
{
|
||||
if (type.IsGenericInstance)
|
||||
{
|
||||
var genericInstance = (GenericInstanceType)type;
|
||||
return
|
||||
$"{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 List<(string, TypeDefinition)> GetDefinitions(TypeDefinition typeDefinition,
|
||||
string requiredAttribute)
|
||||
{
|
||||
var ls = new List<(string, TypeDefinition)>();
|
||||
foreach (var nestedType in typeDefinition.NestedTypes)
|
||||
{
|
||||
var definitions = GetDefinitions(nestedType);
|
||||
var definitions = GetDefinitions(nestedType, requiredAttribute);
|
||||
if (definitions.Count > 0)
|
||||
{
|
||||
ls.AddRange(definitions);
|
||||
}
|
||||
}
|
||||
|
||||
var requiredAttribute = typeof(UpsilonUserDataAttribute).FullName;
|
||||
if (!typeDefinition.HasCustomAttributes) return ls;
|
||||
foreach (var customAttribute in typeDefinition.CustomAttributes)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,8 @@ using JsonRpc.Standard.Contracts;
|
|||
using JsonRpc.Standard.Server;
|
||||
using LanguageServer.VsCode.Contracts;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UpsilonLanguageServer.ReferenceHandler;
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace UpsilonLanguageServer.Services
|
||||
|
@ -38,6 +40,13 @@ namespace UpsilonLanguageServer.Services
|
|||
Session.Settings.ModuleDirectory =
|
||||
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory))
|
||||
.FullName;
|
||||
|
||||
var referenceConfigFile = configPath + "/references.json";
|
||||
if (File.Exists(referenceConfigFile))
|
||||
{
|
||||
LoadReferenceLibraries.ReloadReferences(WorkspaceService.RootUri,
|
||||
File.ReadAllText(referenceConfigFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -113,6 +113,12 @@ namespace UpsilonLanguageServer.Services
|
|||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
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