Skip to content

Commit

Permalink
update cached R Markdown package state after install; fixes #1801
Browse files Browse the repository at this point in the history
After successfully installing the R Markdown package on demand, most of
the session info still indicates that the package doesn't exist. This
change updates the session info in place when a recent version of the
package is successfully installed so that commands like Knit with
Parameters can be used in the very first RStudio session.
  • Loading branch information
jmcphers committed Dec 1, 2017
1 parent d90a59e commit d43cbc8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
9 changes: 9 additions & 0 deletions src/gwt/src/org/rstudio/core/client/command/AppCommand.java
Expand Up @@ -193,6 +193,15 @@ public void setVisible(boolean visible)
handlers_.fireEvent(new VisibleChangedEvent(this));
}
}

/**
* Restores a command which was formerly removed. The command must still be made
* visible and enabled in order to work.
*/
public void restore()
{
removed_ = false;
}

public boolean isCheckable()
{
Expand Down
Expand Up @@ -36,6 +36,8 @@
import org.rstudio.studio.client.common.dependencies.model.DependencyServerOperations;
import org.rstudio.studio.client.server.ServerError;
import org.rstudio.studio.client.server.ServerRequestCallback;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.views.packages.events.PackageStateChangedEvent;
import org.rstudio.studio.client.workbench.views.packages.events.PackageStateChangedHandler;
import org.rstudio.studio.client.workbench.views.vcs.common.ConsoleProgressDialog;
Expand Down Expand Up @@ -82,12 +84,16 @@ class DependencyRequest
@Inject
public DependencyManager(GlobalDisplay globalDisplay,
DependencyServerOperations server,
EventBus eventBus)
EventBus eventBus,
Session session,
Commands commands)
{
globalDisplay_ = globalDisplay;
server_ = server;
satisfied_ = new ArrayList<Dependency>();
requestQueue_ = new LinkedList<DependencyRequest>();
session_ = session;
commands_ = commands;

eventBus.addHandler(InstallShinyEvent.TYPE, this);
eventBus.addHandler(PackageStateChangedEvent.TYPE, this);
Expand Down Expand Up @@ -177,19 +183,13 @@ public void withRMarkdown(String userAction, final Command command)
public void withRMarkdown(String progressCaption, String userAction,
final Command command)
{
withDependencies(
withRMarkdown(
progressCaption,
userAction,
rmarkdownDependenciesArray(),
true, // we want to update to the embedded version if needed
new CommandWithArg<Boolean>()
succeeded ->
{
@Override
public void execute(Boolean succeeded)
{
if (succeeded)
command.execute();
}
if (succeeded)
command.execute();
}
);
}
Expand All @@ -201,8 +201,22 @@ public void withRMarkdown(String progressCaption, String userAction,
progressCaption,
userAction,
rmarkdownDependenciesArray(),
true,
command);
true, // we want to update to the embedded version if needed
succeeded ->
{
if (succeeded)
{
// if we successfully installed the latest R Markdown version,
// update the session cache of package information.
session_.getSessionInfo().setKnitParamsAvailable(true);
session_.getSessionInfo().setRMarkdownPackageAvailable(true);
session_.getSessionInfo().setKnitWorkingDirAvailable(true);

// restore removed commands
commands_.knitWithParameters().restore();
}
command.execute(succeeded);
});
}

public static List<Dependency> rmarkdownDependencies()
Expand Down Expand Up @@ -1059,4 +1073,6 @@ private void updateSatisfied(JsArray<Dependency> all,
private final GlobalDisplay globalDisplay_;
private final DependencyServerOperations server_;
private final ArrayList<Dependency> satisfied_;
private final Session session_;
private final Commands commands_;
}
Expand Up @@ -415,13 +415,25 @@ public final native boolean getRMarkdownPackageAvailable() /*-{
return this.rmarkdown_available;
}-*/;

public final native void setRMarkdownPackageAvailable(boolean available) /*-{
this.rmarkdown_available = available;
}-*/;

public final native boolean getKnitParamsAvailable() /*-{
return this.knit_params_available;
}-*/;

public final native void setKnitParamsAvailable(boolean available) /*-{
this.knit_params_available = available;
}-*/;

public final native boolean getKnitWorkingDirAvailable() /*-{
return this.knit_working_dir_available;
}-*/;

public final native void setKnitWorkingDirAvailable(boolean available) /*-{
this.knit_working_dir_available = available;
}-*/;

public final native boolean getClangAvailable() /*-{
return this.clang_available;
Expand Down
Expand Up @@ -417,7 +417,6 @@ public boolean verifyPrerequisites(String feature,
else if (fileType.requiresKnit() &&
!session_.getSessionInfo().getRMarkdownPackageAvailable())
{

showKnitrPreviewWarning(display, feature, "1.2");
return false;
}
Expand Down

0 comments on commit d43cbc8

Please sign in to comment.