Skip to content

Commit

Permalink
Append = to suggested sweave chunk options
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Mar 30, 2012
1 parent fea50d0 commit 19dcef9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Expand Up @@ -66,4 +66,12 @@ public final native void setCacheable(boolean cacheable) /*-{
public final native boolean isCacheable() /*-{
return !this.nocache;
}-*/;

public final native void setSuggestOnAccept(boolean suggestOnAccept) /*-{
this.suggestOnAccept = suggestOnAccept;
}-*/;

public final native boolean getSuggestOnAccept() /*-{
return !!this.suggestOnAccept;
}-*/;
}
Expand Up @@ -101,7 +101,8 @@ public void onResponseReceived(Completions response)
CompletionResult result = new CompletionResult(
response.getToken(),
newComp,
response.getGuessedFunctionName());
response.getGuessedFunctionName(),
response.getSuggestOnAccept());

cachedResult_ = response.isCacheable() ? result : null;

Expand Down Expand Up @@ -149,6 +150,11 @@ public void onResponseReceived(RnwChunkOptions options)
// guaranteed to narrow the candidate list (in particular
// true/false).
response.setCacheable(false);
if (result.completions.length() > 0 &&
result.completions.get(0).endsWith("="))
{
response.setSuggestOnAccept(true);
}
requestCallback.onResponseReceived(response);
}

Expand Down Expand Up @@ -176,22 +182,26 @@ private CompletionResult narrow(String diff)
if (qname.name.startsWith(token))
newCompletions.add(qname) ;

return new CompletionResult(token, newCompletions, null) ;
return new CompletionResult(token, newCompletions, null,
cachedResult_.suggestOnAccept) ;
}

public static class CompletionResult
{
public CompletionResult(String token, ArrayList<QualifiedName> completions,
String guessedFunctionName)
String guessedFunctionName,
boolean suggestOnAccept)
{
this.token = token ;
this.completions = completions ;
this.guessedFunctionName = guessedFunctionName ;
this.suggestOnAccept = suggestOnAccept ;
}

public final String token ;
public final ArrayList<QualifiedName> completions ;
public final String guessedFunctionName ;
public final boolean suggestOnAccept ;
}

public static class QualifiedName implements Comparable<QualifiedName>
Expand Down
Expand Up @@ -550,6 +550,7 @@ public void onResponseReceived(CompletionResult completions)
selection_.getStart().movePosition(-token.length(), true));

token_ = token ;
suggestOnAccept_ = completions.suggestOnAccept;

if (results.length == 1
&& canAutoAccept_
Expand Down Expand Up @@ -609,6 +610,18 @@ private void onSelection(QualifiedName qname)
}

applyValue(value);

if (suggestOnAccept_)
{
Scheduler.get().scheduleDeferred(new ScheduledCommand()
{
@Override
public void execute()
{
beginSuggest(true, true);
}
});
}
}

private void applyValue(final String value)
Expand Down Expand Up @@ -637,6 +650,7 @@ private void applyValue(final String value)
private InputEditorSelection selection_ ;
private final boolean canAutoAccept_;
private HelpStrategy helpStrategy_ ;
private boolean suggestOnAccept_;
}

private GlobalDisplay globalDisplay_;
Expand Down
Expand Up @@ -102,7 +102,7 @@ public final RnwOptionCompletionResult getCompletions(String line, int pos)
for (String option : this.getOptions())
{
if (option.startsWith(token))
completions.push(option);
completions.push(option + "=");
}
}
else
Expand Down Expand Up @@ -156,7 +156,7 @@ else if (name != null)
{
for (String optionName : this.getOptions())
if (optionName.startsWith(name))
completions.push(optionName);
completions.push(optionName + "=");
}
}
}
Expand Down

0 comments on commit 19dcef9

Please sign in to comment.