diff --git a/CHANGELOG.md b/CHANGELOG.md index e33fcb8..fc23631 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog ## 2025.1.13 - * Updates support for XML Only mods to work with both 1.6 and 1.7 + * Update support for XML Only mods to allow launching directly through Rider + * Update support for XML Only mods to work with both 1.6 and 1.7 ## 2025.1.12 * Update the Rimworld Run Configuration to support both 1.6 and 1.7 at the same time diff --git a/example-mods/XmlOnlyMod/XmlOnlyMod.sln b/example-mods/XmlOnlyMod/XmlOnlyMod.sln deleted file mode 100644 index 54d6e66..0000000 --- a/example-mods/XmlOnlyMod/XmlOnlyMod.sln +++ /dev/null @@ -1,2 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 diff --git a/gradle.properties b/gradle.properties index f906fb5..a6727e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ DotnetPluginId=ReSharperPlugin.RimworldDev DotnetSolution=ReSharperPlugin.RimworldDev.sln RiderPluginId=com.jetbrains.rider.plugins.rimworlddev -PluginVersion=2025.1.12 +PluginVersion=2025.1.13 BuildConfiguration=Release diff --git a/src/dotnet/ReSharperPlugin.RimworldDev/RimworldXmlProject/Solution/RimworldSolutionMarkProvider.cs b/src/dotnet/ReSharperPlugin.RimworldDev/RimworldXmlProject/Solution/RimworldSolutionMarkProvider.cs new file mode 100644 index 0000000..6fb6a96 --- /dev/null +++ b/src/dotnet/ReSharperPlugin.RimworldDev/RimworldXmlProject/Solution/RimworldSolutionMarkProvider.cs @@ -0,0 +1,57 @@ +using System; +using System.Linq; +using JetBrains.Application; +using JetBrains.ProjectModel.ProjectsHost; +using JetBrains.RdBackend.Common.Features.ProjectModel; +using JetBrains.Rider.Model; +using JetBrains.Util; +using ReSharperPlugin.RimworldDev.Settings; + +namespace ReSharperPlugin.RimworldDev.RimworldXmlProject.Solution; + +[ShellComponent] +public sealed class RimworldSolutionMarkProvider : ISolutionMarkProvider +{ + public RimworldSolutionMarkProvider(SettingsAccessor settingsAccessor) + { + settingsAccessor.GetSettings(); + } + + public ISolutionMark TryCreate(RdSolutionDescription solutionDescription) + { + // This check is here to make sure we're only trying to adopt projects that opened up in Folder View, IE: they + // don't have a .sln file. If they do have a .sln file, we'll use the RimworldProjectMarkProvider instead. + if (solutionDescription is not RdVirtualSolution virtualSolution) return null; + + var directory = VirtualFileSystemPath.TryParse(virtualSolution.SolutionDirectory.Value, InteractionContext.SolutionContext); + if (directory.IsEmpty) return null; + + var projectDirectory = directory; + var aboutFile = projectDirectory.TryCombine("About/About.xml"); + var parentAttempts = 0; + while (!aboutFile.ExistsFile) + { + parentAttempts++; + projectDirectory = projectDirectory.Parent; + if (projectDirectory.Exists == FileSystemPath.Existence.Missing || parentAttempts >= 5) break; + + aboutFile = projectDirectory.TryCombine("About/About.xml"); + } + + if (!aboutFile.ExistsFile) return null; + + // When we come in as a folder project we may have other "projects" that we do or don't want to load. De default + // Rider will pass us a list where it's basically a file for ever folder, since it assumes each folder is its own + // project. We don't just want to throw them away (maybe someone has a .csproj or an obscure F# project without + // using a .sln file because reasons) (If you are using F# for your mods, respect), we want to load the ones that + // are legitimate projects. So we'll filter files down by ending in .*proj and let them get added to our custom + // virtual solution. + var projectFiles = virtualSolution.ProjectFilePaths + .Where(path => path.Value.EndsWith("proj", StringComparison.OrdinalIgnoreCase)) + .Select(path => VirtualFileSystemPath.TryParse(path.Value, InteractionContext.SolutionContext)) + .Where(path => !path.IsEmpty) + .ToList(); + + return new RimworldVirtualSolutionMark(directory.Name, aboutFile, projectFiles); + } +} diff --git a/src/dotnet/ReSharperPlugin.RimworldDev/RimworldXmlProject/Solution/RimworldVirtualSolutionMark.cs b/src/dotnet/ReSharperPlugin.RimworldDev/RimworldXmlProject/Solution/RimworldVirtualSolutionMark.cs new file mode 100644 index 0000000..ec4b01e --- /dev/null +++ b/src/dotnet/ReSharperPlugin.RimworldDev/RimworldXmlProject/Solution/RimworldVirtualSolutionMark.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using JetBrains.ProjectModel.Impl; +using JetBrains.ProjectModel.ProjectsHost; +using JetBrains.ProjectModel.ProjectsHost.Diagnostic; +using JetBrains.ProjectModel.ProjectsHost.Impl; +using JetBrains.ProjectModel.SolutionStructure.SolutionConfigurations; +using JetBrains.ProjectModel.SolutionStructure.SolutionDefinitions; +using JetBrains.Util; + +namespace ReSharperPlugin.RimworldDev.RimworldXmlProject.Solution; + +public class RimworldVirtualSolutionMark : ISolutionMark +{ + private readonly IReadOnlyCollection myProjectFiles; + + public RimworldVirtualSolutionMark([NotNull] string name, [NotNull] VirtualFileSystemPath location, + [NotNull] IReadOnlyCollection projectFiles) + { + Name = name; + Location = location; + myProjectFiles = projectFiles; + ConfigurationAndPlatformStore = SolutionConfigurationAndPlatformStore.Empty; + } + + public string Name { get; } + + public VirtualFileSystemPath Location { get; } + + public SolutionFormatVersion GetPlatformVersion() => SolutionFormatVersion.Unknown; + + public IReadOnlyCollection GetProjectLocations() => myProjectFiles; + + public IReadOnlyCollection GetSolutionRelatedLocations() => + EmptyList.Instance; + + public ISolutionConfigurationAndPlatform ActiveConfigurationAndPlatform => + MissingSolutionConfigurationAndPlatform.Instance; + + public ISolutionConfigurationAndPlatformStore ConfigurationAndPlatformStore { get; } + + public SolutionStructureChange Update(SolutionMarkUpdateRequest request) + { + var projectMarks = request.StructureContainer.ProjectMarks; + var addedProjects = new List(); + var updatedProjects = new List(); + + // See our comment in `RimworldSolutionMarkProvider`, we may be picking up other actual projects that we want + // to add. + var existingVirtualMarks = projectMarks.OfType().ToList(); + foreach (var projectFile in myProjectFiles) + { + var existingMark = existingVirtualMarks.FirstOrDefault(mark => mark.Location == projectFile); + if (existingMark == null) + { + addedProjects.Add(new VirtualProjectMark(this, projectFile)); + continue; + } + + updatedProjects.Add(existingMark); + existingVirtualMarks.Remove(existingMark); + } + + var rimworldMarks = projectMarks.OfType().ToList(); + if (rimworldMarks.Count == 0) + { + var rootProject = new RimworldProjectMark(this, Location, this); + addedProjects.Add(rootProject); + addedProjects.AddRange(rootProject.Dependencies); + } + else + updatedProjects.AddRange(rimworldMarks); + + return new SolutionStructureChange(this, addedProjects, existingVirtualMarks, updatedProjects, + EmptyList.InstanceList, EmptyList.InstanceList); + } + + public IProjectMark AddProject(ProjectDefinitionDescriptor descriptor, IProjectMark parent) => + throw new NotImplementedException(); + + public IProjectMark RenameProject(IProjectMark project, string name, string path) => + throw new NotImplementedException(); + + public void RemoveProject(IProjectMark project) => throw new NotImplementedException(); + + public void MoveProject(IProjectMark project, IProjectMark parent) => throw new NotImplementedException(); +}