Skip to content

Commit

Permalink
Run spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude committed Jun 20, 2024
1 parent c6f44aa commit 45b0d22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> required, Map<String, String> optional) {}

public record LightbulbData(String version, Map<String, ParamData> paramData) {}

private static final ConcurrentHashMap<Sdk, LightbulbData> sdkLightbulbData = new ConcurrentHashMap<>();
Expand All @@ -35,8 +35,7 @@ public static ConcurrentHashMap<Sdk, LightbulbData> getSdkLightbulbData() {

LightbulbData readMetaparamsFile(String version, VirtualFile vf) {
try {
var parsedParamData =
MAPPER.readValue(vf.getInputStream(), new TypeReference<Map<String, ParamData>>() {});
var parsedParamData = MAPPER.readValue(vf.getInputStream(), new TypeReference<Map<String, ParamData>>() {});
return new LightbulbData(version, parsedParamData);
} catch (IOException e) {
return null;
Expand All @@ -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;
}
Expand All @@ -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));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -64,8 +63,7 @@ public static Map<String, PyExpression> 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()));
}
}

0 comments on commit 45b0d22

Please sign in to comment.