diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd5be8..5af4fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2023.1-Alpha-3 * Fixed some instances of certain classes not being queried for their properties + * If you've got a project without the Assembly-CSharp.dll referenced (If you're on Linux for example), it should now be + able to find the DLL file on disk and reference that directly as a fall-back ## 2023.1-Alpha-2 * Minimum Rider version is now 2023.1 diff --git a/TODO.md b/TODO.md index 2695a6d..79d213e 100644 --- a/TODO.md +++ b/TODO.md @@ -6,7 +6,6 @@ * If we know a bit of XML should be an enum like Gender, we should be able to check that it's a valid enum value ` * Maybe bring out own Rimworld defs if there's no scope? * Handle Defs with custom classes instead of Rimworld classes -` * Packaging. It shouldn't be too difficult, but I haven't done it yet * We need to be able to support "LoadAlias", such as "StorageSettings.priority" * Autocomplete of special types @@ -28,13 +27,10 @@ * Make auto completing to other XMLTags look nicer and work faster * When linking to other def (`DefNameHere`) also include defs where the tag is a custom class that extends from the def we're looking for - -` * Refactoring - * We're fetching symbol scopes a bit all over the place. Let's collect it into a SymbolScope helper class ` * Documentation * Re-read and document References.RimworldXmlReference * If you have an XML file open while Rider is still initializing, that file doesn't get autocompletion. Document that * Tests - * It's not a serious plugin project without Tests IMO. Let's at least aim to get one or two unit tests to start with \ No newline at end of file + * It's not a serious project without Tests IMO. Let's at least aim to get one or two unit tests to start with \ No newline at end of file diff --git a/src/dotnet/ReSharperPlugin.RimworldDev/ScopeHelper.cs b/src/dotnet/ReSharperPlugin.RimworldDev/ScopeHelper.cs index 0321680..8bea3eb 100644 --- a/src/dotnet/ReSharperPlugin.RimworldDev/ScopeHelper.cs +++ b/src/dotnet/ReSharperPlugin.RimworldDev/ScopeHelper.cs @@ -1,8 +1,13 @@ using System.Collections.Generic; using System.Linq; +using JetBrains.Application.Threading.Tasks; +using JetBrains.Metadata.Reader.API; using JetBrains.ProjectModel; +using JetBrains.ProjectModel.model2.Assemblies.Interfaces; using JetBrains.ReSharper.Psi.Caches; using JetBrains.ReSharper.Psi.Modules; +using JetBrains.Util; +using JetBrains.Util.Threading.Tasks; namespace ReSharperPlugin.RimworldDev; @@ -12,11 +17,12 @@ public class ScopeHelper private static ISymbolScope rimworldScope; private static IPsiModule rimworldModule; private static List usedScopes; + private static bool adding = false; public static bool UpdateScopes(ISolution solution) { if (solution == null) return false; - + allScopes = solution.PsiModules().GetModules().Select(module => module.GetPsiServices().Symbols.GetSymbolScope(module, true, true)).ToList(); @@ -24,17 +30,50 @@ public static bool UpdateScopes(ISolution solution) { rimworldScope = allScopes.FirstOrDefault(scope => scope.GetTypeElementByCLRName("Verse.ThingDef") != null); - if (rimworldScope == null) return false; + if (rimworldScope == null) + { + AddRef(solution); + + return false; + } rimworldModule = solution.PsiModules().GetModules() - .First(module => module.GetPsiServices().Symbols.GetSymbolScope(module, true, true).GetTypeElementByCLRName("Verse.ThingDef") != null); - - // rimworldScope = rimWorldModule.GetPsiServices().Symbols.GetSymbolScope(rimWorldModule, true, true); + .First(module => + module.GetPsiServices().Symbols.GetSymbolScope(module, true, true) + .GetTypeElementByCLRName("Verse.ThingDef") != null); } return true; } + private static async void AddRef(ISolution solution) + { + if (adding) return; + adding = true; + + var locations = new List + { + "C:\\Program Files (x86)\\Steam\\steamapps\\common\\RimWorld\\RimWorldWin64_Data\\Managed\\Assembly-CSharp.dll", + "C:\\Program Files\\Steam\\steamapps\\common\\RimWorld\\RimWorldWin64_Data\\Managed\\Assembly-CSharp.dll", + "~/.steam/steam/SteamApps/common/RimWorld/RimWorldWin64_Data/Managed/Assembly-CSharp.dll" + }; + + + var location = locations.FirstOrDefault(location => FileSystemPath.TryParse(location).ExistsFile); + + if (location == null) return; + + var path = FileSystemPath.TryParse(location); + + var moduleReferenceResolveContext = + (IModuleReferenceResolveContext)UniversalModuleReferenceContext.Instance; + + await solution.Locks.Tasks.YieldTo(solution.GetLifetime(), Scheduling.MainDispatcher, TaskPriority.Low); + + solution.GetComponent().AddRef(path.ToAssemblyLocation(), "ScopeHelper::AddRef", + moduleReferenceResolveContext); + } + public static ISymbolScope RimworldScope => rimworldScope; public static IPsiModule RimworldModule => rimworldModule;