Skip to content

Commit

Permalink
Fix SDK not being set propery / prompt showing up after it is set
Browse files Browse the repository at this point in the history
  • Loading branch information
ab5tract committed Sep 16, 2024
1 parent 4a0fd65 commit cc3cfdd
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public void update(@NotNull AnActionEvent e) {
if (e.getProject() == null) {
e.getPresentation().setEnabledAndVisible(false);
}
BuildNumber build = ApplicationInfo.getInstance().getBuild();
if ("CP".equals(build.getProductCode()) ||
"CT".equals(build.getProductCode()))
e.getPresentation().setEnabledAndVisible(false);
}

static class SecondarySdkSelector extends DialogWrapper {
Expand Down Expand Up @@ -81,8 +77,9 @@ protected SecondarySdkSelector(@Nullable Project project, String currentSdk) {
protected void doOKAction() {
RakuBackupSDKService service = myProject.getService(RakuBackupSDKService.class);
Sdk sdk = mySdkCheckbox.getSelectedJdk();
if (sdk != null)
if (sdk != null) {
service.setProjectSdkPath(myProject.getProjectFilePath(), sdk.getHomePath());
}
super.doOKAction();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ public static String stubTemplate(Path testDirectoryPath, String fileName) {

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
return ActionUpdateThread.BGT;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/raku/comma/parsing/RakuWordsScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void processWords(@NotNull CharSequence fileText, @NotNull Processor<? su
if (myIdentifierTokenSet.contains(type)) {
String text = myLexer.getTokenText();
if (type == RakuTokenTypes.VARIABLE) {
if (text.length() > 1) {
if (! text.isEmpty()) {
String sigilLess = text.substring(Character.isLetter(text.charAt(1)) ? 1 : 2);
if (indexByDash(processor, occurrence, sigilLess)) return;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ protected static boolean stripWords(final Processor<? super WordOccurrence> proc
final WordOccurrence.Kind kind,
@NotNull WordOccurrence occurrence
) {
// This code seems strange but it is more effective as Character.isJavaIdentifier_xxx_ is quite costly operation due to unicode
// This code seems strange, but it is more effective as Character.isJavaIdentifier_xxx_ is quite costly operation due to unicode
int index = from;

ScanWordsLoop:
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/raku/comma/project/RakuProjectBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.raku.comma.RakuIcons;
import org.raku.comma.metadata.RakuMetaDataComponent;
import org.raku.comma.module.RakuModuleType;
import org.raku.comma.pm.IgnoreObsoletePackageManagerSettings;
import org.raku.comma.pm.RakuPackageManagerManager;
import org.raku.comma.sdk.RakuSdkType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.raku.comma.services.RakuBackupSDKService;

import javax.swing.*;
import java.nio.file.Path;
Expand Down Expand Up @@ -113,8 +113,7 @@ public List<Module> commit(@NotNull Project project,
RakuMetaDataComponent component = firstModule.getService(RakuMetaDataComponent.class);
component.triggerMetaBuild(metaFile);
}
// Ignore
IgnoreObsoletePackageManagerSettings managerSettings = project.getService(IgnoreObsoletePackageManagerSettings.class);

// Detect and set PM from path
RakuPackageManagerManager manager = project.getService(RakuPackageManagerManager.class);
if (manager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.intellij.openapi.module.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.Comparing;
Expand All @@ -26,12 +28,14 @@ public class RakuModuleConfigurable extends NamedConfigurable<Module> implements
public RakuModuleConfigurable(RakuModulesConfigurator modulesConfigurator,
@NotNull Module module,
Runnable updateTree,
ModuleGrouper moduleGrouper) {
ModuleGrouper moduleGrouper)
{
super(true, updateTree);
myModule = module;
myModuleGrouper = moduleGrouper;
myConfigurator = modulesConfigurator;
myModuleName = myConfigurator.getModuleModel().getActualName(myModule);
// TODO: Address RakuModuleStructureConfigurable being totally broken
//myContext = RakuModuleStructureConfigurable.getInstance(myModule.getProject()).getContext();
//myProjectStructureElement = new ModuleProjectStructureElement(myContext, myModule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public boolean isModified() {
public Module getModule(final String moduleName) {
if (moduleName == null) return null;
return myContext != null && myContext.myModulesConfigurator != null
? myContext.myModulesConfigurator.getModule(moduleName)
: myModuleManager.findModuleByName(moduleName);
? myContext.myModulesConfigurator.getModule(moduleName)
: myModuleManager.findModuleByName(moduleName);
}

public RakuStructureConfigurableContext getContext() {
Expand All @@ -157,7 +157,8 @@ public RakuStructureConfigurableContext getContext() {

public static RakuModuleStructureConfigurable getInstance(Project project) {
// TODO: Fix this
return project.getService(RakuModuleStructureConfigurable.class);
// return project.getService(RakuModuleStructureConfigurable.class);
return null;
}

private class AddModuleAction extends AnAction implements DumbAware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import java.util.ArrayList;
import java.util.List;

public class RakuProjectStructureConfigurable extends BaseConfigurable implements Disposable,
SearchableConfigurable,
Place.Navigator, Configurable.NoMargin,
Configurable.NoScroll
public class RakuProjectStructureConfigurable extends BaseConfigurable
implements Disposable,
SearchableConfigurable,
Place.Navigator,
Configurable.NoMargin,
Configurable.NoScroll
{
private static final String CATEGORY = "category";
public static final DataKey<RakuProjectStructureConfigurable> KEY = DataKey.create("RakuProjectStructureConfiguration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import java.util.function.Predicate;

public abstract class RakuStructureConfigurable extends MasterDetailsComponent
implements SearchableConfigurable, Disposable, Place.Navigator {
implements SearchableConfigurable,
Disposable,
Place.Navigator
{
protected final Project myProject;
protected boolean myWasTreeInitialized;
protected boolean myUiDisposed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.raku.comma.project.structure;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ProjectRootManager;
Expand Down Expand Up @@ -53,7 +54,7 @@ public Sdk getSdk(final Sdk sdk, final String sdkName) {
@Override
public Module getModule(final Module module, final String moduleName) {
if (module == null) {
return RakuModuleStructureConfigurable.getInstance(myProject).getModule(moduleName);
return ModuleManager.getInstance(myProject).findModuleByName(moduleName);
}
return module;
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/raku/comma/sdk/RakuSdkType.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public static String findRakuInSdkHome(String home) {
public static String getSdkHomeByProject(@NotNull Project project) {
Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk();
return sdk != null && sdk.getSdkType() instanceof RakuSdkType
? sdk.getHomePath()
: secondarySDKHome(project);
? sdk.getHomePath()
: secondarySDKHome(project);
}

public static String secondarySDKHome(@NotNull Project project) {
Expand Down Expand Up @@ -250,7 +250,8 @@ public RakuFile getCoreSettingFile(Project project) {
return cache.setting;
}
if (settingJson != null) {
return cache.setting = makeSettingSymbols(project, settingJson);
cache.setting = makeSettingSymbols(project, settingJson);
return cache.setting;
}

File coreSymbols = RakuUtils.getResourceAsFile("symbols/raku-core-symbols.p6");
Expand All @@ -259,10 +260,10 @@ public RakuFile getCoreSettingFile(Project project) {

if (perl6path == null || coreSymbols == null || coreDocs == null) {
String errorMessage = perl6path == null
? "getCoreSettingFile is called without Raku SDK set, using fallback"
: coreSymbols == null
? "getCoreSettingFile is called with corrupted resources bundle, using fallback"
: "getCoreSettingFile is called with corrupted resources bundle";
? "getCoreSettingFile is called without Raku SDK set, using fallback"
: coreSymbols == null
? "getCoreSettingFile is called with corrupted resources bundle, using fallback"
: "getCoreSettingFile is called with corrupted resources bundle";
reactToSDKIssue(project, errorMessage);
return getFallback(project);
}
Expand All @@ -280,8 +281,8 @@ public RakuFile getCoreSettingFile(Project project) {
coreSymbols.delete();
coreDocs.delete();
}
catch (Exception ignored) {
}
catch (Exception ignored) {}

if (settingLines.isEmpty()) {
reactToSDKIssue(project, "getCoreSettingFile got no symbols from Raku, using fallback");
getFallback(project);
Expand Down
34 changes: 16 additions & 18 deletions src/main/java/org/raku/comma/utils/RakuUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ public static File getResourceAsFile(String resourcePath) {
File tempFile;
try {
tempFile = FileUtil.createTempFile("comma", ".tmp");
}
catch (IOException e) {
} catch (IOException e) {
LOG.error(e);
return null;
}

try (
InputStream in = RakuUtils.class.getClassLoader().getResourceAsStream(resourcePath);
FileOutputStream out = new FileOutputStream(tempFile)
InputStream in = RakuUtils.class.getClassLoader().getResourceAsStream(resourcePath);
FileOutputStream out = new FileOutputStream(tempFile)
) {
if (in != null)
if (in != null) {
in.transferTo(out);
}
} catch (IOException e) {
LOG.error(e);
}
Expand All @@ -55,13 +55,12 @@ public static File getResourceAsFile(String resourcePath) {
public static List<String> getResourceAsLines(String filepath) {
List<String> lines = new ArrayList<>();
try (
InputStream resourceFileStream = RakuUtils.class.getClassLoader().getResourceAsStream(filepath);
BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(resourceFileStream), StandardCharsets.UTF_8))
InputStream resourceFileStream = RakuUtils.class.getClassLoader().getResourceAsStream(filepath);
BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(resourceFileStream), StandardCharsets.UTF_8))
) {
while (inputStreamReader.ready())
lines.add(inputStreamReader.readLine());
}
catch (IOException|NullPointerException e) {
} catch (IOException | NullPointerException e) {
LOG.error(e);
}
return lines;
Expand All @@ -75,7 +74,7 @@ public static String formatDelimiters(int originalText, String delimiter, int ea
String text = new StringBuilder(String.valueOf(originalText)).reverse().toString();
StringBuilder builder = new StringBuilder(text.length() + text.length() / each + 1);
int index = 0;
while (index < text.length()) {
while (index < text.length()) {
builder.append(text, index, Math.min(index + 3, text.length()));
index += each;

Expand All @@ -90,17 +89,16 @@ public static String getNameExtension(@Nullable String filename) {
}

public static String escapeHTML(String str) {
return str.chars().mapToObj(c -> c > 127 || "\"'<>&".indexOf(c) != -1 ?
"&" + htmlReplace(c) + ";" : String.valueOf((char) c)).collect(Collectors.joining());
return str.chars().mapToObj(
c -> (c > 127 || "\"'<>&".indexOf(c) != -1)
? "&" + htmlReplace(c) + ";"
: String.valueOf((char) c)).collect(Collectors.joining());
}

private static String htmlReplace(int c) {
if (c == 62)
return "gt";
if (c == 60)
return "lt";
if (c == 38)
return "amp";
if (c == 62) return "gt";
if (c == 60) return "lt";
if (c == 38) return "amp";
return String.valueOf(c);
}
}

0 comments on commit cc3cfdd

Please sign in to comment.