Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference #348

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/com/reason/hints/InsightManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.vfs.*;
import com.reason.comp.Compiler;
import com.reason.comp.*;
import com.reason.ide.settings.*;
import jpsplugin.com.reason.*;
import org.jetbrains.annotations.*;

Expand Down Expand Up @@ -105,6 +106,13 @@ public void queryTypes(@NotNull VirtualFile sourceFile, @NotNull Path cmtPath, @

if (ocamlVersion != null && !rincewindVersion.equals(excludedVersion)) {
return "rincewind_" + getOsPrefix() + ocamlVersion + "-" + rincewindVersion + ".exe";
} else if (ocamlVersion == null){
ORSettings settings = myProject.getService(ORSettings.class);
ocamlVersion = settings.getOcamlFallback();
if (ocamlVersion != null){
rincewindVersion = getRincewindVersion(ocamlVersion);
return "rincewind_" + getOsPrefix() + ocamlVersion + "-" + rincewindVersion + ".exe";
}
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/com/reason/hints/RincewindProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void types(@NotNull VirtualFile sourceFile, @NotNull String rincewindBina
LOG.debug("Looking for types for file", sourceFile);

Optional<VirtualFile> contentRoot = BsPlatform.findContentRoot(myProject, sourceFile);
if (!contentRoot.isPresent()) {
if (contentRoot.isEmpty()) {
return;
}

Expand Down
19 changes: 19 additions & 0 deletions src/com/reason/ide/settings/ORSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class ORSettings implements PersistentStateComponent<ORSettings.ReasonSet
private static final boolean IS_FORMAT_ON_SAVE_DEFAULT = true;
private static final String FORMAT_WIDTH_COLUMNS_DEFAULT = "80";
private static final boolean IS_BS_ENABLED_DEFAULT = true;
private static final String[] RINCEWIND_SUPPORTED_VERSIONS = new String[]{
"", "4.06.1", "4.07.1", "4.08.1", "4.09.1", "4.10.0"
};

private final @NotNull Project m_project;

// General
private boolean m_isFormatOnSaveEnabled = IS_FORMAT_ON_SAVE_DEFAULT;
private @Nullable String m_formatColumnWidth;
private boolean myUseSuperErrors = false;
private String myOcamlFallback = "";

// BuckleScript
private boolean m_isBsEnabled = IS_BS_ENABLED_DEFAULT;
Expand All @@ -38,6 +42,7 @@ public ReasonSettingsState getState() {
state.isBsEnabled = m_isBsEnabled;
state.bsPlatformLocation = m_bsPlatformLocation;
state.esyExecutable = m_esyExecutable;
state.myOcamlFallback = myOcamlFallback;
return state;
}

Expand All @@ -49,6 +54,7 @@ public void loadState(@NotNull ReasonSettingsState state) {
m_isBsEnabled = state.isBsEnabled;
m_bsPlatformLocation = state.bsPlatformLocation;
m_esyExecutable = state.esyExecutable;
myOcamlFallback = state.myOcamlFallback;
}

public @NotNull Project getProject() {
Expand Down Expand Up @@ -86,6 +92,18 @@ public void setUseSuperErrors(boolean useSuperErrors) {
myUseSuperErrors = useSuperErrors;
}

public String getOcamlFallback() {
return myOcamlFallback.equals("") ? null : myOcamlFallback;
}

public void setOcamlFallback(String ocamlFallback) {
myOcamlFallback = ocamlFallback;
}

public String[] getOcamlFallbacks() {
return RINCEWIND_SUPPORTED_VERSIONS;
}

public boolean isBsEnabled() {
return m_isBsEnabled;
}
Expand Down Expand Up @@ -115,6 +133,7 @@ public static class ReasonSettingsState {
// General
public boolean isFormatOnSaveEnabled = IS_FORMAT_ON_SAVE_DEFAULT;
public @Nullable String formatColumnWidth;
public String myOcamlFallback;
public boolean isUseSuperErrors = false;
// BuckleScript
public boolean isBsEnabled = IS_BS_ENABLED_DEFAULT;
Expand Down
37 changes: 31 additions & 6 deletions src/com/reason/ide/settings/ORSettingsConfigurable.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="f_rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="823" height="400"/>
<xy x="20" y="20" width="823" height="410"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -25,7 +25,7 @@
</properties>
<border type="etched"/>
<children>
<grid id="5a7f7" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="5a7f7" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<tabbedpane title="General"/>
Expand All @@ -36,7 +36,7 @@
<grid id="d2465" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<name value="refmt"/>
Expand Down Expand Up @@ -95,7 +95,7 @@
<grid id="cdaf5" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title="Compiler"/>
Expand All @@ -115,9 +115,34 @@
</hspacer>
</children>
</grid>
<vspacer id="c5e73">
<grid id="45941" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title="OCaml"/>
<children>
<component id="7b4a" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="42670"/>
<text value="If you aren't using a build tool, you may set the version of OCaml here to enable Type inference"/>
</properties>
</component>
<component id="42670" class="javax.swing.JComboBox" binding="f_setOCamlFallBack">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<vspacer id="a061">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
Expand Down
14 changes: 13 additions & 1 deletion src/com/reason/ide/settings/ORSettingsConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ORSettingsConfigurable implements SearchableConfigurable, Configura
private JTextField f_generalFormatWidthColumns;
private JCheckBox f_generalIsFormatOnSave;
private JCheckBox myUseSuperErrorsCheckBox;
private JComboBox<String> f_setOCamlFallBack;

// BuckleScript
private JCheckBox f_bsIsEnabled;
Expand Down Expand Up @@ -73,6 +74,7 @@ public void apply() {
m_settings.setFormatOnSaveEnabled(f_generalIsFormatOnSave.isSelected());
m_settings.setFormatColumnWidth(sanitizeInput(f_generalFormatWidthColumns));
m_settings.setUseSuperErrors(myUseSuperErrorsCheckBox.isSelected());
m_settings.setOcamlFallback((String) f_setOCamlFallBack.getSelectedItem());
// BuckleScript
m_settings.setBsEnabled(f_bsIsEnabled.isSelected());
m_settings.setBsPlatformLocation(sanitizeInput(f_bsPlatformLocation));
Expand All @@ -92,12 +94,17 @@ public boolean isModified() {
!f_bsPlatformLocation.getText().equals(m_settings.getBsPlatformLocation());
boolean isEsyExecutableModified =
!f_esyExecutable.getText().equals(m_settings.getEsyExecutable());

String selectedItem = (String) f_setOCamlFallBack.getSelectedItem();
boolean isOCamlFallbackModified =
selectedItem != null && !selectedItem.equals(m_settings.getOcamlFallback());
return isFormatOnSaveModified
|| isFormatWidthColumnsModified
|| isUseSuperErrorModified
|| isBsEnabledModified
|| isBsPlatformLocationModified
|| isEsyExecutableModified;
|| isEsyExecutableModified
|| isOCamlFallbackModified;
}

@Override
Expand All @@ -106,6 +113,7 @@ public void reset() {
f_generalIsFormatOnSave.setSelected(m_settings.isFormatOnSaveEnabled());
f_generalFormatWidthColumns.setText(m_settings.getFormatColumnWidth());
myUseSuperErrorsCheckBox.setSelected(m_settings.isUseSuperErrors());
f_setOCamlFallBack.setSelectedItem(m_settings.getOcamlFallback());
// BuckleScript
f_bsIsEnabled.setSelected(m_settings.isBsEnabled());
f_bsPlatformLocation.setText(m_settings.getBsPlatformLocation());
Expand All @@ -114,6 +122,10 @@ public void reset() {
}

private void createGeneralTab() {
for (String ocamlVersion:m_settings.getOcamlFallbacks()) {
f_setOCamlFallBack.addItem(ocamlVersion);
}
f_setOCamlFallBack.setSelectedIndex(0);
}

private void createBsTab() {
Expand Down