diff --git a/src/main/java/io/github/tandemdude/hklbsupport/CommandParameterCompletionContributor.java b/src/main/java/io/github/tandemdude/hklbsupport/CommandParameterCompletionContributor.java index a391241..d989880 100644 --- a/src/main/java/io/github/tandemdude/hklbsupport/CommandParameterCompletionContributor.java +++ b/src/main/java/io/github/tandemdude/hklbsupport/CommandParameterCompletionContributor.java @@ -44,7 +44,8 @@ protected void addCompletions( return; } - var moduleLightbulbData = LightbulbPackageManagerListener.getSdkLightbulbData().get(sdk); + var moduleLightbulbData = + LightbulbPackageManagerListener.getSdkLightbulbData().get(sdk); if (moduleLightbulbData == null) { // We don't have the data for the specified module - maybe it isn't part of this project? // Alternatively, lightbulb may not be installed - a filesystem listener will load the diff --git a/src/main/java/io/github/tandemdude/hklbsupport/LightbulbPackageManagerListener.java b/src/main/java/io/github/tandemdude/hklbsupport/LightbulbPackageManagerListener.java index cbeaff7..4d09365 100644 --- a/src/main/java/io/github/tandemdude/hklbsupport/LightbulbPackageManagerListener.java +++ b/src/main/java/io/github/tandemdude/hklbsupport/LightbulbPackageManagerListener.java @@ -13,18 +13,18 @@ import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.sdk.PythonSdkUtil; import io.github.tandemdude.hklbsupport.utils.Notifier; -import org.jetbrains.annotations.NotNull; - import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jetbrains.annotations.NotNull; public class LightbulbPackageManagerListener implements PyPackageManager.Listener { private static final ObjectMapper MAPPER = new ObjectMapper(); public record ParamData(Map required, Map optional) {} + public record LightbulbData(String version, Map paramData) {} private static final ConcurrentHashMap sdkLightbulbData = new ConcurrentHashMap<>(); @@ -35,8 +35,7 @@ public static ConcurrentHashMap getSdkLightbulbData() { LightbulbData readMetaparamsFile(String version, VirtualFile vf) { try { - var parsedParamData = - MAPPER.readValue(vf.getInputStream(), new TypeReference>() {}); + var parsedParamData = MAPPER.readValue(vf.getInputStream(), new TypeReference>() {}); return new LightbulbData(version, parsedParamData); } catch (IOException e) { return null; @@ -60,7 +59,8 @@ public void packagesRefreshed(@NotNull Sdk sdk) { } var existingData = sdkLightbulbData.get(sdk); - if (existingData != null && existingData.version().equals(lightbulb.get().getVersion())) { + if (existingData != null + && existingData.version().equals(lightbulb.get().getVersion())) { // The cache is still up-to-date - do not refresh return; } @@ -80,23 +80,25 @@ public void packagesRefreshed(@NotNull Sdk sdk) { }); } - FileTypeIndex.processFiles(FileTypeManager.getInstance().getFileTypeByExtension("json"), file -> { - if ( - file.getPath().endsWith("metaparams.json") - && file.getPath().contains("lightbulb") - && file.getPath().contains(lightbulbLocation) - ) { - var data = readMetaparamsFile(lightbulb.get().getVersion(), file); - if (data == null) { - return false; - } + FileTypeIndex.processFiles( + FileTypeManager.getInstance().getFileTypeByExtension("json"), + file -> { + if (file.getPath().endsWith("metaparams.json") + && file.getPath().contains("lightbulb") + && file.getPath().contains(lightbulbLocation)) { + var data = readMetaparamsFile(lightbulb.get().getVersion(), file); + if (data == null) { + return false; + } - sdkLightbulbData.put(sdk, data); - Notifier.notifyInformation(null, "Lightbulb configuration loaded successfully (%s)", sdk.getName()); - return false; - } - return true; - }, GlobalSearchScope.union(searchScopes)); + sdkLightbulbData.put(sdk, data); + Notifier.notifyInformation( + null, "Lightbulb configuration loaded successfully (%s)", sdk.getName()); + return false; + } + return true; + }, + GlobalSearchScope.union(searchScopes)); }); } } diff --git a/src/main/java/io/github/tandemdude/hklbsupport/utils/Utils.java b/src/main/java/io/github/tandemdude/hklbsupport/utils/Utils.java index 1f6eb8f..9944ad4 100644 --- a/src/main/java/io/github/tandemdude/hklbsupport/utils/Utils.java +++ b/src/main/java/io/github/tandemdude/hklbsupport/utils/Utils.java @@ -6,12 +6,11 @@ import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PyKeywordArgument; import com.jetbrains.python.psi.types.TypeEvalContext; +import com.jetbrains.python.sdk.PythonSdkUtil; +import io.github.tandemdude.hklbsupport.LightbulbPackageManagerListener; import java.util.Arrays; import java.util.Map; import java.util.stream.Collectors; - -import com.jetbrains.python.sdk.PythonSdkUtil; -import io.github.tandemdude.hklbsupport.LightbulbPackageManagerListener; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,8 +63,7 @@ public static Map getKeywordSuperclassExpressions(PyClass .map(expr -> (PyKeywordArgument) expr) // I had a null pointer exception from this previously so probably good to just make sure .filter(expr -> expr.getKeyword() != null && expr.getValueExpression() != null) - .map(expr -> Pair.create( - expr.getKeyword(), expr.getValueExpression())) + .map(expr -> Pair.create(expr.getKeyword(), expr.getValueExpression())) .collect(Collectors.toMap(p -> p.getFirst(), p -> p.getSecond())); } }