Skip to content

Commit

Permalink
Properly used codegen to generate code for new setting related to loa…
Browse files Browse the repository at this point in the history
…ding variables from variables file.
  • Loading branch information
fabioz committed Apr 12, 2024
1 parent afda578 commit 51dbf37
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class RobotState {
public String robotPythonEnv = "";
public String robotVariables = "";
public String robotLoadVariablesFromArgumentsFile = "";
public String robotLoadVariablesFromVariablesFile = "";
public String robotPythonpath = "";
public String robotLibrariesLibdocNeedsArgs = "";
public String robotLibrariesLibdocPreGenerate = "";
Expand Down Expand Up @@ -60,6 +61,7 @@ class RobotState {
public String robotTimeoutCodeFormatting = "";
public String robotTimeoutCollectDocsTimeout = "";
public String robotTimeoutListTestsTimeout = "";
public String robotTestViewEnabled = "";
}

// IMPORTANT: Autogenerated. Don't change manually. Run codegen.py to regenerate.
Expand All @@ -74,6 +76,7 @@ public class RobotPreferences implements PersistentStateComponent<RobotState> {
public static final String ROBOT_PYTHON_ENV = "robot.python.env";
public static final String ROBOT_VARIABLES = "robot.variables";
public static final String ROBOT_LOAD_VARIABLES_FROM_ARGUMENTS_FILE = "robot.loadVariablesFromArgumentsFile";
public static final String ROBOT_LOAD_VARIABLES_FROM_VARIABLES_FILE = "robot.loadVariablesFromVariablesFile";
public static final String ROBOT_PYTHONPATH = "robot.pythonpath";
public static final String ROBOT_LIBRARIES_LIBDOC_NEEDS_ARGS = "robot.libraries.libdoc.needsArgs";
public static final String ROBOT_LIBRARIES_LIBDOC_PRE_GENERATE = "robot.libraries.libdoc.preGenerate";
Expand Down Expand Up @@ -109,6 +112,7 @@ public class RobotPreferences implements PersistentStateComponent<RobotState> {
public static final String ROBOT_TIMEOUT_CODE_FORMATTING = "robot.timeout.codeFormatting";
public static final String ROBOT_TIMEOUT_COLLECT_DOCS_TIMEOUT = "robot.timeout.collectDocsTimeout";
public static final String ROBOT_TIMEOUT_LIST_TESTS_TIMEOUT = "robot.timeout.listTestsTimeout";
public static final String ROBOT_TEST_VIEW_ENABLED = "robot.testView.enabled";

private static final Logger LOG = Logger.getInstance(RobotPreferences.class);

Expand All @@ -125,6 +129,7 @@ public RobotState getState() {
robotState.robotPythonEnv = getRobotPythonEnv();
robotState.robotVariables = getRobotVariables();
robotState.robotLoadVariablesFromArgumentsFile = getRobotLoadVariablesFromArgumentsFile();
robotState.robotLoadVariablesFromVariablesFile = getRobotLoadVariablesFromVariablesFile();
robotState.robotPythonpath = getRobotPythonpath();
robotState.robotLibrariesLibdocNeedsArgs = getRobotLibrariesLibdocNeedsArgs();
robotState.robotLibrariesLibdocPreGenerate = getRobotLibrariesLibdocPreGenerate();
Expand Down Expand Up @@ -160,6 +165,7 @@ public RobotState getState() {
robotState.robotTimeoutCodeFormatting = getRobotTimeoutCodeFormatting();
robotState.robotTimeoutCollectDocsTimeout = getRobotTimeoutCollectDocsTimeout();
robotState.robotTimeoutListTestsTimeout = getRobotTimeoutListTestsTimeout();
robotState.robotTestViewEnabled = getRobotTestViewEnabled();
return robotState;
}

Expand All @@ -174,6 +180,7 @@ public void loadState(@NotNull RobotState robotState) {
setRobotPythonEnv(robotState.robotPythonEnv);
setRobotVariables(robotState.robotVariables);
setRobotLoadVariablesFromArgumentsFile(robotState.robotLoadVariablesFromArgumentsFile);
setRobotLoadVariablesFromVariablesFile(robotState.robotLoadVariablesFromVariablesFile);
setRobotPythonpath(robotState.robotPythonpath);
setRobotLibrariesLibdocNeedsArgs(robotState.robotLibrariesLibdocNeedsArgs);
setRobotLibrariesLibdocPreGenerate(robotState.robotLibrariesLibdocPreGenerate);
Expand Down Expand Up @@ -209,6 +216,7 @@ public void loadState(@NotNull RobotState robotState) {
setRobotTimeoutCodeFormatting(robotState.robotTimeoutCodeFormatting);
setRobotTimeoutCollectDocsTimeout(robotState.robotTimeoutCollectDocsTimeout);
setRobotTimeoutListTestsTimeout(robotState.robotTimeoutListTestsTimeout);
setRobotTestViewEnabled(robotState.robotTestViewEnabled);
}

// IMPORTANT: Autogenerated. Don't change manually. Run codegen.py to regenerate.
Expand Down Expand Up @@ -278,6 +286,15 @@ public JsonObject asJsonObject() {
}
}

if(!robotLoadVariablesFromVariablesFile.isEmpty()){

try {
jsonObject.add(ROBOT_LOAD_VARIABLES_FROM_VARIABLES_FILE, new JsonPrimitive(robotLoadVariablesFromVariablesFile));
} catch(Exception e) {
LOG.error(e);
}
}

if(!robotPythonpath.isEmpty()){
Gson g = new Gson();
try {
Expand Down Expand Up @@ -593,6 +610,15 @@ public JsonObject asJsonObject() {
}
}

if(!robotTestViewEnabled.isEmpty()){

try {
jsonObject.add(ROBOT_TEST_VIEW_ENABLED, new JsonPrimitive(Boolean.parseBoolean(robotTestViewEnabled)));
} catch(Exception e) {
LOG.error(e);
}
}

return jsonObject;
}

Expand Down Expand Up @@ -926,6 +952,53 @@ public void setRobotLoadVariablesFromArgumentsFile(String s) {
}
}

private String robotLoadVariablesFromVariablesFile = "";

public @NotNull String getRobotLoadVariablesFromVariablesFile() {
return robotLoadVariablesFromVariablesFile;
}

public @Nullable JsonPrimitive getRobotLoadVariablesFromVariablesFileAsJson() {
if(robotLoadVariablesFromVariablesFile.isEmpty()){
return null;
}

return new JsonPrimitive(robotLoadVariablesFromVariablesFile);
}

public @NotNull String validateRobotLoadVariablesFromVariablesFile(String robotLoadVariablesFromVariablesFile) {
if(robotLoadVariablesFromVariablesFile.isEmpty()) {
return "";
}
try {

new JsonPrimitive(robotLoadVariablesFromVariablesFile);

return "";

} catch(Exception e) {
return e.toString();
}
}

public void setRobotLoadVariablesFromVariablesFile(String s) {
if (s == null) {
s = "";
}
if (s.equals(robotLoadVariablesFromVariablesFile)) {
return;
}
String old = robotLoadVariablesFromVariablesFile;
robotLoadVariablesFromVariablesFile = s;
for (LanguageServerDefinition.IPreferencesListener listener : listeners) {
try {
listener.onChanged(ROBOT_LOAD_VARIABLES_FROM_VARIABLES_FILE, old, s);
} catch (CancelledException e) {
// just ignore at this point
}
}
}

private String robotPythonpath = "";

public @NotNull String getRobotPythonpath() {
Expand Down Expand Up @@ -2604,6 +2677,53 @@ public void setRobotTimeoutListTestsTimeout(String s) {
}
}

private String robotTestViewEnabled = "";

public @NotNull String getRobotTestViewEnabled() {
return robotTestViewEnabled;
}

public @Nullable JsonPrimitive getRobotTestViewEnabledAsJson() {
if(robotTestViewEnabled.isEmpty()){
return null;
}

return new JsonPrimitive(Boolean.parseBoolean(robotTestViewEnabled));
}

public @NotNull String validateRobotTestViewEnabled(String robotTestViewEnabled) {
if(robotTestViewEnabled.isEmpty()) {
return "";
}
try {

new JsonPrimitive(Boolean.parseBoolean(robotTestViewEnabled));

return "";

} catch(Exception e) {
return e.toString();
}
}

public void setRobotTestViewEnabled(String s) {
if (s == null) {
s = "";
}
if (s.equals(robotTestViewEnabled)) {
return;
}
String old = robotTestViewEnabled;
robotTestViewEnabled = s;
for (LanguageServerDefinition.IPreferencesListener listener : listeners) {
try {
listener.onChanged(ROBOT_TEST_VIEW_ENABLED, old, s);
} catch (CancelledException e) {
// just ignore at this point
}
}
}


private Collection<LanguageServerDefinition.IPreferencesListener> listeners = new CopyOnWriteArraySet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class RobotPreferencesComponent {
private final JBTextField robotPythonEnv = new JBTextField();
private final JBTextField robotVariables = new JBTextField();
private final JBTextField robotLoadVariablesFromArgumentsFile = new JBTextField();
private final JBTextField robotLoadVariablesFromVariablesFile = new JBTextField();
private final JBTextField robotPythonpath = new JBTextField();
private final JBTextField robotLibrariesLibdocNeedsArgs = new JBTextField();
private final JBTextField robotLibrariesLibdocPreGenerate = new JBTextField();
Expand Down Expand Up @@ -62,6 +63,7 @@ class RobotPreferencesComponent {
private final JBTextField robotTimeoutCodeFormatting = new JBTextField();
private final JBTextField robotTimeoutCollectDocsTimeout = new JBTextField();
private final JBTextField robotTimeoutListTestsTimeout = new JBTextField();
private final JBTextField robotTestViewEnabled = new JBTextField();

public RobotPreferencesComponent() {
panel = FormBuilder.createFormBuilder()
Expand All @@ -79,6 +81,8 @@ public RobotPreferencesComponent() {
.addComponent(createJTextArea("Custom variables passed to RobotFramework\n(used when resolving variables and automatically passed to the launch config as --variable entries).\n(i.e.: {\"EXECDIR\": \"c:/my/proj/src\"})\nNote: expected format: JSON Object\n"))
.addLabeledComponent(new JBLabel("Load Variables From Arguments File"), robotLoadVariablesFromArgumentsFile, 1, false)
.addComponent(createJTextArea("Load variables for code-completion and code-analysis based on an arguments file. Multiple files\naccepted by separating with a comma.\n"))
.addLabeledComponent(new JBLabel("Load Variables From Variables File"), robotLoadVariablesFromVariablesFile, 1, false)
.addComponent(createJTextArea("Load variables for code-completion and code-analysis based on an variables file. Multiple files\naccepted by separating with a comma.\n"))
.addLabeledComponent(new JBLabel("Pythonpath"), robotPythonpath, 1, false)
.addComponent(createJTextArea("Entries to be added to the PYTHONPATH\n(used when resolving resources and imports and automatically passed to the launch config as\n--pythonpath entries).\n(i.e.: [\"c:/my/pro/src\"])\nNote: expected format: JSON Array\n"))
.addLabeledComponent(new JBLabel("Libraries Libdoc Needs Args"), robotLibrariesLibdocNeedsArgs, 1, false)
Expand Down Expand Up @@ -149,6 +153,8 @@ public RobotPreferencesComponent() {
.addComponent(createJTextArea("This is the timeout used for collecting documentation to show in the ROBOT DOCUMENTATION view. Set\nto 0 to disable it.\n"))
.addLabeledComponent(new JBLabel("Timeout List Tests Timeout"), robotTimeoutListTestsTimeout, 1, false)
.addComponent(createJTextArea("This is the timeout used for listing the tests from a robot file. Set to 0 to disable it.\n"))
.addLabeledComponent(new JBLabel("Test View Enabled"), robotTestViewEnabled, 1, false)
.addComponent(createJTextArea("Whether to show robot tests in the test view. You may want to disable this if you are using another\ntest runner\n(eg. https://github.com/DetachHead/pytest-robotframework)\nNote: expected 'true' or 'false'\n"))

.addComponentFillVertically(new JPanel(), 0)
.getPanel();
Expand Down Expand Up @@ -236,6 +242,15 @@ public void setRobotLoadVariablesFromArgumentsFile (@NotNull String newText) {
robotLoadVariablesFromArgumentsFile.setText(newText);
}

@NotNull
public String getRobotLoadVariablesFromVariablesFile() {
return robotLoadVariablesFromVariablesFile.getText();
}

public void setRobotLoadVariablesFromVariablesFile (@NotNull String newText) {
robotLoadVariablesFromVariablesFile.setText(newText);
}

@NotNull
public String getRobotPythonpath() {
return robotPythonpath.getText();
Expand Down Expand Up @@ -551,6 +566,15 @@ public void setRobotTimeoutListTestsTimeout (@NotNull String newText) {
robotTimeoutListTestsTimeout.setText(newText);
}

@NotNull
public String getRobotTestViewEnabled() {
return robotTestViewEnabled.getText();
}

public void setRobotTestViewEnabled (@NotNull String newText) {
robotTestViewEnabled.setText(newText);
}


}

Expand Down Expand Up @@ -612,6 +636,10 @@ public boolean isModified() {
return true;
}

if(!settings.getRobotLoadVariablesFromVariablesFile().equals(component.getRobotLoadVariablesFromVariablesFile())){
return true;
}

if(!settings.getRobotPythonpath().equals(component.getRobotPythonpath())){
return true;
}
Expand Down Expand Up @@ -752,6 +780,10 @@ public boolean isModified() {
return true;
}

if(!settings.getRobotTestViewEnabled().equals(component.getRobotTestViewEnabled())){
return true;
}

return false;
}

Expand All @@ -771,6 +803,7 @@ public void reset() {
component.setRobotPythonEnv(settings.getRobotPythonEnv());
component.setRobotVariables(settings.getRobotVariables());
component.setRobotLoadVariablesFromArgumentsFile(settings.getRobotLoadVariablesFromArgumentsFile());
component.setRobotLoadVariablesFromVariablesFile(settings.getRobotLoadVariablesFromVariablesFile());
component.setRobotPythonpath(settings.getRobotPythonpath());
component.setRobotLibrariesLibdocNeedsArgs(settings.getRobotLibrariesLibdocNeedsArgs());
component.setRobotLibrariesLibdocPreGenerate(settings.getRobotLibrariesLibdocPreGenerate());
Expand Down Expand Up @@ -806,6 +839,7 @@ public void reset() {
component.setRobotTimeoutCodeFormatting(settings.getRobotTimeoutCodeFormatting());
component.setRobotTimeoutCollectDocsTimeout(settings.getRobotTimeoutCollectDocsTimeout());
component.setRobotTimeoutListTestsTimeout(settings.getRobotTimeoutListTestsTimeout());
component.setRobotTestViewEnabled(settings.getRobotTestViewEnabled());
}

@Override
Expand Down Expand Up @@ -846,6 +880,10 @@ public void apply() throws ConfigurationException {
if(!s.isEmpty()) {
throw new ConfigurationException("Error in Load Variables From Arguments File:\n" + s);
}
s = settings.validateRobotLoadVariablesFromVariablesFile(component.getRobotLoadVariablesFromVariablesFile());
if(!s.isEmpty()) {
throw new ConfigurationException("Error in Load Variables From Variables File:\n" + s);
}
s = settings.validateRobotPythonpath(component.getRobotPythonpath());
if(!s.isEmpty()) {
throw new ConfigurationException("Error in Pythonpath:\n" + s);
Expand Down Expand Up @@ -986,6 +1024,10 @@ public void apply() throws ConfigurationException {
if(!s.isEmpty()) {
throw new ConfigurationException("Error in Timeout List Tests Timeout:\n" + s);
}
s = settings.validateRobotTestViewEnabled(component.getRobotTestViewEnabled());
if(!s.isEmpty()) {
throw new ConfigurationException("Error in Test View Enabled:\n" + s);
}

settings.setRobotLanguageServerPython(component.getRobotLanguageServerPython());
settings.setRobotLanguageServerArgs(component.getRobotLanguageServerArgs());
Expand All @@ -994,6 +1036,7 @@ public void apply() throws ConfigurationException {
settings.setRobotPythonEnv(component.getRobotPythonEnv());
settings.setRobotVariables(component.getRobotVariables());
settings.setRobotLoadVariablesFromArgumentsFile(component.getRobotLoadVariablesFromArgumentsFile());
settings.setRobotLoadVariablesFromVariablesFile(component.getRobotLoadVariablesFromVariablesFile());
settings.setRobotPythonpath(component.getRobotPythonpath());
settings.setRobotLibrariesLibdocNeedsArgs(component.getRobotLibrariesLibdocNeedsArgs());
settings.setRobotLibrariesLibdocPreGenerate(component.getRobotLibrariesLibdocPreGenerate());
Expand Down Expand Up @@ -1029,5 +1072,6 @@ public void apply() throws ConfigurationException {
settings.setRobotTimeoutCodeFormatting(component.getRobotTimeoutCodeFormatting());
settings.setRobotTimeoutCollectDocsTimeout(component.getRobotTimeoutCollectDocsTimeout());
settings.setRobotTimeoutListTestsTimeout(component.getRobotTimeoutListTestsTimeout());
settings.setRobotTestViewEnabled(component.getRobotTestViewEnabled());
}
}
Loading

0 comments on commit 51dbf37

Please sign in to comment.