Fix some tab completion cache stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-01-21 21:46:48 +01:00
Ursprung 61999b0507
Commit b4df616bc4
2 geänderte Dateien mit 9 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -165,7 +165,7 @@ class CommandPart<T> {
}
private Collection<String> tabCompletes(T sender, String[] args, List<Object> mappedArgs, int startIndex) {
return TabCompletionCache.tabComplete(sender, args[startIndex], (AbstractTypeMapper<Object, ?>) typeMapper, command, () -> {
return TabCompletionCache.tabComplete(sender, args[startIndex], (AbstractTypeMapper<Object, ?>) typeMapper, () -> {
try {
return typeMapper.tabCompletes(sender, new PreviousArguments(Arrays.copyOf(args, startIndex), mappedArgs.toArray()), args[startIndex]);
} catch (Throwable e) {

Datei anzeigen

@ -57,22 +57,23 @@ public class TabCompletionCache {
@AllArgsConstructor
private static class TabCompletions {
private AbstractSWCommand<?> command;
private long timestamp;
private Collection<String> tabCompletions;
}
Collection<String> tabComplete(Object sender, String arg, AbstractTypeMapper<Object, ?> typeMapper, AbstractSWCommand<?> command, Supplier<Collection<String>> tabCompleteSupplier) {
Collection<String> tabComplete(Object sender, String arg, AbstractTypeMapper<Object, ?> typeMapper, Supplier<Collection<String>> tabCompleteSupplier) {
if (!cached.contains(typeMapper)) return tabCompleteSupplier.get();
String normalizedArg = typeMapper.normalize(sender, arg);
if (normalizedArg == null) normalizedArg = "";
Key key = global.contains(typeMapper) ? new Key(null, normalizedArg, typeMapper) : new Key(sender, normalizedArg, typeMapper);
Key key = new Key(global.contains(typeMapper) ? null : sender, normalizedArg, typeMapper);
TabCompletions tabCompletions = tabCompletionCache.computeIfAbsent(key, ignore -> {
return new TabCompletions(command, System.currentTimeMillis(), tabCompleteSupplier.get());
return new TabCompletions(System.currentTimeMillis(), tabCompleteSupplier.get());
});
if (tabCompletions.command != command || System.currentTimeMillis() - tabCompletions.timestamp > cacheDuration.get(typeMapper)) {
tabCompletions = new TabCompletions(command, System.currentTimeMillis(), tabCompleteSupplier.get());
tabCompletionCache.put(key, tabCompletions);
if (System.currentTimeMillis() - tabCompletions.timestamp > cacheDuration.get(typeMapper)) {
tabCompletions.tabCompletions = tabCompleteSupplier.get();
}
tabCompletions.timestamp = System.currentTimeMillis();
return tabCompletions.tabCompletions;