-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move DefTags into a SimpleICache (#7)
Move DefTag detection/caching to RimworldXmlCache which extends from SimpleICache
- Loading branch information
Showing
15 changed files
with
200 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Param( | ||
$Version = "2023.1.0" | ||
$Version = "2023.1.1" | ||
) | ||
|
||
Set-StrictMode -Version Latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.202", | ||
"rollForward": "latestMajor", | ||
"allowPrerelease": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-7.3-all.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
src/dotnet/ReSharperPlugin.RimworldDev/RimworldXMLDefUtil.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/dotnet/ReSharperPlugin.RimworldDev/SymbolScope/RimworldSymbolScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JetBrains; | ||
using JetBrains.Annotations; | ||
using JetBrains.Application.Threading; | ||
using JetBrains.Collections; | ||
using JetBrains.Lifetimes; | ||
using JetBrains.ReSharper.Psi; | ||
using JetBrains.ReSharper.Psi.Caches; | ||
using JetBrains.ReSharper.Psi.Files; | ||
using JetBrains.ReSharper.Psi.Xml.Tree; | ||
|
||
namespace ReSharperPlugin.RimworldDev.SymbolScope; | ||
|
||
[PsiComponent] | ||
public class RimworldSymbolScope : SimpleICache<List<RimworldXmlDefSymbol>> | ||
{ | ||
public Dictionary<string, IXmlTag> DefTags = new(); | ||
|
||
public RimworldSymbolScope | ||
(Lifetime lifetime, [NotNull] IShellLocks locks, [NotNull] IPersistentIndexManager persistentIndexManager, long? version = null) | ||
: base(lifetime, locks, persistentIndexManager, RimworldXmlDefSymbol.Marshaller, version) | ||
{ | ||
} | ||
|
||
protected override bool IsApplicable(IPsiSourceFile sourceFile) | ||
{ | ||
return base.IsApplicable(sourceFile) && sourceFile.LanguageType.Name == "XML"; | ||
} | ||
|
||
[CanBeNull] | ||
public IXmlTag GetTagByDef(string defType, string defName) | ||
{ | ||
return GetTagByDef($"{defType}/{defName}"); | ||
} | ||
|
||
[CanBeNull] | ||
public IXmlTag GetTagByDef(string defId) | ||
{ | ||
if (!DefTags.ContainsKey(defId)) | ||
return null; | ||
|
||
return DefTags[defId]; | ||
} | ||
|
||
public override object Build(IPsiSourceFile sourceFile, bool isStartup) | ||
{ | ||
if (!IsApplicable(sourceFile)) | ||
return null; | ||
|
||
if (sourceFile.GetPrimaryPsiFile() is not IXmlFile xmlFile) return null; | ||
|
||
var tags = xmlFile.GetNestedTags<IXmlTag>("Defs/*").Where(tag => | ||
{ | ||
var defNameTag = tag.GetNestedTags<IXmlTag>("defName").FirstOrDefault(); | ||
return defNameTag is not null; | ||
}); | ||
|
||
List<RimworldXmlDefSymbol> defs = new(); | ||
|
||
foreach (var tag in tags) | ||
{ | ||
var defName = tag.GetNestedTags<IXmlTag>("defName").FirstOrDefault()?.InnerText; | ||
if (defName is null) continue; | ||
|
||
defs.Add(new RimworldXmlDefSymbol(tag, defName, tag.GetTagName())); | ||
} | ||
|
||
return defs; | ||
} | ||
|
||
public override void Merge(IPsiSourceFile sourceFile, object builtPart) | ||
{ | ||
RemoveFromLocalCache(sourceFile); | ||
AddToLocalCache(sourceFile, builtPart as List<RimworldXmlDefSymbol>); | ||
base.Merge(sourceFile, builtPart); | ||
} | ||
|
||
public override void MergeLoaded(object data) | ||
{ | ||
PopulateLocalCache(); | ||
base.MergeLoaded(data); | ||
} | ||
|
||
public override void Drop(IPsiSourceFile sourceFile) | ||
{ | ||
RemoveFromLocalCache(sourceFile); | ||
base.Drop(sourceFile); | ||
} | ||
|
||
private void AddToLocalCache(IPsiSourceFile sourceFile, [CanBeNull] List<RimworldXmlDefSymbol> cacheItem) | ||
{ | ||
if (sourceFile.GetPrimaryPsiFile() is not IXmlFile xmlFile) return; | ||
|
||
cacheItem?.ForEach(item => | ||
{ | ||
if (!DefTags.ContainsKey($"{item.DefType}/{item.DefName}")) | ||
DefTags.Add($"{item.DefType}/{item.DefName}", xmlFile.GetNestedTags<IXmlTag>("Defs/*").FirstOrDefault(tag => tag.GetTreeStartOffset().Offset == item.DocumentOffset)); | ||
}); | ||
} | ||
|
||
private void RemoveFromLocalCache(IPsiSourceFile sourceFile) | ||
{ | ||
var items = Map!.GetValueSafe(sourceFile); | ||
|
||
items?.ForEach(item => | ||
{ | ||
if (!DefTags.ContainsKey($"{item.DefType}/{item.DefName}")) | ||
DefTags.Remove($"{item.DefType}/{item.DefName}"); | ||
}); | ||
} | ||
|
||
private void PopulateLocalCache() | ||
{ | ||
foreach (var (sourceFile, cacheItem) in Map) | ||
AddToLocalCache(sourceFile, cacheItem); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/dotnet/ReSharperPlugin.RimworldDev/SymbolScope/RimworldXmlDefSymbol.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.ReSharper.Psi.Xml.Tree; | ||
using JetBrains.Serialization; | ||
using JetBrains.Util.PersistentMap; | ||
|
||
namespace ReSharperPlugin.RimworldDev.SymbolScope; | ||
|
||
public class RimworldXmlDefSymbol | ||
{ | ||
public static readonly IUnsafeMarshaller<List<RimworldXmlDefSymbol>> Marshaller = | ||
UnsafeMarshallers.GetCollectionMarshaller(new UniversalMarshaller<RimworldXmlDefSymbol>(Read, Write), (size) => new List<RimworldXmlDefSymbol>()); | ||
|
||
public string DefName { get; } | ||
public string DefType { get; } | ||
|
||
public int DocumentOffset { get; } | ||
|
||
// public IXmlTag Tag { get; } | ||
|
||
public RimworldXmlDefSymbol(IXmlTag tag, string defName, string defType) | ||
{ | ||
DefName = defName; | ||
DefType = defType; | ||
DocumentOffset = tag.GetTreeStartOffset().Offset; | ||
} | ||
|
||
public RimworldXmlDefSymbol(int documentOffset, string defName, string defType) | ||
{ | ||
DefName = defName; | ||
DefType = defType; | ||
DocumentOffset = documentOffset; | ||
} | ||
|
||
private static RimworldXmlDefSymbol Read(UnsafeReader reader) | ||
{ | ||
var defType = reader.ReadString(); | ||
var defName = reader.ReadString(); | ||
var documentOffset = reader.ReadInt(); | ||
|
||
return new RimworldXmlDefSymbol(documentOffset, defName, defType); | ||
} | ||
|
||
private static void Write(UnsafeWriter writer, RimworldXmlDefSymbol value) | ||
{ | ||
writer.Write(value.DefType); | ||
writer.Write(value.DefName); | ||
writer.Write(value.DocumentOffset); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters