use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.
the class PaneManager method swapConsolePane.
private void swapConsolePane(PaneConfig paneConfig, int consoleTargetIndex) {
int consoleCurrentIndex = paneConfig.getConsoleIndex();
if (consoleCurrentIndex != consoleTargetIndex) {
JsArrayString panes = JsArrayUtil.copy(paneConfig.getPanes());
panes.set(consoleCurrentIndex, panes.get(consoleTargetIndex));
panes.set(consoleTargetIndex, "Console");
uiPrefs_.paneConfig().setGlobalValue(PaneConfig.create(panes, paneConfig.getTabSet1(), paneConfig.getTabSet2(), paneConfig.getConsoleLeftOnTop(), paneConfig.getConsoleRightOnTop()));
uiPrefs_.writeUIPrefs();
}
}
use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.
the class CompletionRequester method addFunctionArgumentCompletions.
private void addFunctionArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
AceEditor editor = (AceEditor) docDisplay_;
if (editor != null) {
Position cursorPosition = editor.getSession().getSelection().getCursor();
CodeModel codeModel = editor.getSession().getMode().getRCodeModel();
// Try to see if we can find a function name
TokenCursor cursor = codeModel.getTokenCursor();
// NOTE: This can fail if the document is empty
if (!cursor.moveToPosition(cursorPosition))
return;
String tokenLower = token.toLowerCase();
if (cursor.currentValue() == "(" || cursor.findOpeningBracket("(", false)) {
if (cursor.moveToPreviousToken()) {
// Check to see if this really is the name of a function
JsArray<ScopeFunction> functionsInScope = codeModel.getAllFunctionScopes();
String tokenName = cursor.currentValue();
for (int i = 0; i < functionsInScope.length(); i++) {
ScopeFunction rFunction = functionsInScope.get(i);
String fnName = rFunction.getFunctionName();
if (tokenName == fnName) {
JsArrayString args = rFunction.getFunctionArgs();
for (int j = 0; j < args.length(); j++) {
String arg = args.get(j);
if (arg.toLowerCase().startsWith(tokenLower))
completions.add(new QualifiedName(args.get(j) + " = ", fnName, false, RCompletionType.CONTEXT));
}
}
}
}
}
}
}
use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.
the class CompletionRequester method getCompletions.
public void getCompletions(final String token, final List<String> assocData, final List<Integer> dataType, final List<Integer> numCommas, final String functionCallString, final String chainDataName, final JsArrayString chainAdditionalArgs, final JsArrayString chainExcludeArgs, final boolean chainExcludeArgsFromObject, final String filePath, final String documentId, final boolean implicit, final ServerRequestCallback<CompletionResult> callback) {
boolean isHelp = dataType.size() > 0 && dataType.get(0) == AutocompletionContext.TYPE_HELP;
if (usingCache(token, isHelp, callback))
return;
doGetCompletions(token, assocData, dataType, numCommas, functionCallString, chainDataName, chainAdditionalArgs, chainExcludeArgs, chainExcludeArgsFromObject, filePath, documentId, new ServerRequestCallback<Completions>() {
@Override
public void onError(ServerError error) {
callback.onError(error);
}
@Override
public void onResponseReceived(Completions response) {
cachedLinePrefix_ = token;
String token = response.getToken();
JsArrayString comp = response.getCompletions();
JsArrayString pkgs = response.getPackages();
JsArrayBoolean quote = response.getQuote();
JsArrayInteger type = response.getType();
ArrayList<QualifiedName> newComp = new ArrayList<QualifiedName>();
// Get function completions from the server
for (int i = 0; i < comp.length(); i++) if (comp.get(i).endsWith(" = "))
newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i), response.getHelpHandler()));
// Try getting our own function argument completions
if (!response.getExcludeOtherCompletions()) {
addFunctionArgumentCompletions(token, newComp);
addScopedArgumentCompletions(token, newComp);
}
// Get variable completions from the current scope
if (!response.getExcludeOtherCompletions()) {
addScopedCompletions(token, newComp, "variable");
addScopedCompletions(token, newComp, "function");
}
// Get other server completions
for (int i = 0; i < comp.length(); i++) if (!comp.get(i).endsWith(" = "))
newComp.add(new QualifiedName(comp.get(i), pkgs.get(i), quote.get(i), type.get(i), response.getHelpHandler()));
// to properly ascertain this.
if (isTopLevelCompletionRequest())
addSnippetCompletions(token, newComp);
// Remove duplicates
newComp = resolveDuplicates(newComp);
CompletionResult result = new CompletionResult(response.getToken(), newComp, response.getGuessedFunctionName(), response.getSuggestOnAccept(), response.getOverrideInsertParens());
if (response.isCacheable()) {
cachedCompletions_.put("", result);
}
callback.onResponseReceived(result);
}
});
}
use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.
the class CompletionRequester method addScopedArgumentCompletions.
private void addScopedArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
AceEditor editor = (AceEditor) docDisplay_;
// NOTE: this will be null in the console, so protect against that
if (editor != null) {
Position cursorPosition = editor.getSession().getSelection().getCursor();
CodeModel codeModel = editor.getSession().getMode().getRCodeModel();
JsArray<RFunction> scopedFunctions = codeModel.getFunctionsInScope(cursorPosition);
if (scopedFunctions.length() == 0)
return;
String tokenLower = token.toLowerCase();
for (int i = 0; i < scopedFunctions.length(); i++) {
RFunction scopedFunction = scopedFunctions.get(i);
String functionName = scopedFunction.getFunctionName();
JsArrayString argNames = scopedFunction.getFunctionArgs();
for (int j = 0; j < argNames.length(); j++) {
String argName = argNames.get(j);
if (argName.toLowerCase().startsWith(tokenLower)) {
if (functionName == null || functionName == "") {
completions.add(new QualifiedName(argName, "<anonymous function>", false, RCompletionType.CONTEXT));
} else {
completions.add(new QualifiedName(argName, functionName, false, RCompletionType.CONTEXT));
}
}
}
}
}
}
use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.
the class Shell method sessionInit.
private void sessionInit(Session session) {
SessionInfo sessionInfo = session.getSessionInfo();
ClientInitState clientState = sessionInfo.getClientState();
new StringStateValue(GROUP_CONSOLE, STATE_INPUT, ClientState.TEMPORARY, clientState) {
@Override
protected void onInit(String value) {
initialInput_ = value;
}
@Override
protected String getValue() {
return view_.getInputEditorDisplay().getText();
}
};
JsArrayString history = sessionInfo.getConsoleHistory();
if (history != null)
setHistory(history);
RpcObjectList<ConsoleAction> actions = sessionInfo.getConsoleActions();
if (actions != null) {
view_.playbackActions(actions);
}
if (sessionInfo.getResumed()) {
// no special UI for this (resuming session with all console
// history and other UI state preserved deemed adequate feedback)
}
}
Aggregations