Changeset View
Changeset View
Standalone View
Standalone View
src/backends/R/rserver/rserver.cpp
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | 102 | { | |||
---|---|---|---|---|---|
106 | // TODO: error handling | 106 | // TODO: error handling | ||
107 | else | 107 | else | ||
108 | { | 108 | { | ||
109 | qDebug()<<(QLatin1String("Script ")+path+QLatin1String(" not found")); // FIXME: or should we throw a messagebox | 109 | qDebug()<<(QLatin1String("Script ")+path+QLatin1String(" not found")); // FIXME: or should we throw a messagebox | ||
110 | } | 110 | } | ||
111 | } | 111 | } | ||
112 | 112 | | |||
113 | qDebug()<<"done initializing"; | 113 | qDebug()<<"done initializing"; | ||
114 | | ||||
115 | // FIXME: other way to search symbols, see listSymbols for details | | |||
116 | listSymbols(); | | |||
117 | } | 114 | } | ||
118 | 115 | | |||
119 | //Code from the RInside library | 116 | //Code from the RInside library | ||
120 | void RServer::autoload() | 117 | void RServer::autoload() | ||
121 | { | 118 | { | ||
122 | #include "rautoloads.h" | 119 | #include "rautoloads.h" | ||
123 | 120 | | |||
124 | /* Autoload default packages and names from autoloads.h | 121 | /* Autoload default packages and names from autoloads.h | ||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Line(s) | 238 | { | |||
362 | 359 | | |||
363 | //Check if the expression got results other than plain text (like files,etc) | 360 | //Check if the expression got results other than plain text (like files,etc) | ||
364 | if(!expr->hasOtherResults) | 361 | if(!expr->hasOtherResults) | ||
365 | emit expressionFinished(returnCode, returnText); | 362 | emit expressionFinished(returnCode, returnText); | ||
366 | else | 363 | else | ||
367 | showFiles(neededFiles); | 364 | showFiles(neededFiles); | ||
368 | 365 | | |||
369 | setStatus(Idle); | 366 | setStatus(Idle); | ||
370 | | ||||
371 | // FIXME: Calling this every evaluation is probably ugly | | |||
372 | listSymbols(); | | |||
373 | } | 367 | } | ||
374 | 368 | | |||
375 | void RServer::completeCommand(const QString& cmd) | 369 | void RServer::completeCommand(const QString& cmd) | ||
376 | { | 370 | { | ||
377 | // setStatus(RServer::Busy); | 371 | // setStatus(RServer::Busy); | ||
378 | 372 | | |||
379 | // TODO: is static okay? guess RServer is a singletone, but ... | 373 | // TODO: is static okay? guess RServer is a singletone, but ... | ||
380 | // TODO: error handling? | 374 | // TODO: error handling? | ||
Show All 34 Lines | |||||
415 | 409 | | |||
416 | // FIXME: This scheme is somewhat placeholder, I honestly don't like it too much | 410 | // FIXME: This scheme is somewhat placeholder, I honestly don't like it too much | ||
417 | // I am not sure whether or not asking the server with each keypress if what he typed was | 411 | // I am not sure whether or not asking the server with each keypress if what he typed was | ||
418 | // acceptable or not is a good idea. I'll leave it under investigation, let it be this way just for now | 412 | // acceptable or not is a good idea. I'll leave it under investigation, let it be this way just for now | ||
419 | // ~Landswellsong | 413 | // ~Landswellsong | ||
420 | 414 | | |||
421 | void RServer::listSymbols() | 415 | void RServer::listSymbols() | ||
422 | { | 416 | { | ||
423 | // setStatus(RServer::Busy); | 417 | setStatus(RServer::Busy); | ||
424 | 418 | | |||
425 | QStringList vars, values, funcs; | 419 | QStringList vars, values, funcs; | ||
426 | int errorOccurred; // TODO: error checks | 420 | int errorOccurred; // TODO: error checks | ||
427 | 421 | | |||
428 | /* Obtaining a list of user namespace objects */ | 422 | /* Obtaining a list of user namespace objects */ | ||
429 | SEXP usr=PROTECT(R_tryEval(lang1(install("ls")),nullptr,&errorOccurred)); | 423 | SEXP usr=PROTECT(R_tryEval(lang1(install("ls")),nullptr,&errorOccurred)); | ||
430 | for (int i=0;i<length(usr);i++) | 424 | for (int i=0;i<length(usr);i++) | ||
431 | { | 425 | { | ||
432 | SEXP object = STRING_ELT(usr,i); | 426 | SEXP object = STRING_ELT(usr,i); | ||
433 | const QString& name = QString::fromUtf8(translateCharUTF8(object)); | 427 | const QString& name = QString::fromUtf8(translateCharUTF8(object)); | ||
434 | SEXP value = findVar(installChar(object), R_GlobalEnv); | 428 | SEXP value = findVar(installChar(object), R_GlobalEnv); | ||
435 | 429 | | |||
436 | if (Rf_isFunction(value)) | 430 | if (Rf_isFunction(value)) | ||
437 | funcs << name; | 431 | funcs << name; | ||
438 | else | 432 | else if (RServerSettings::variableManagement()) | ||
439 | { | 433 | { | ||
440 | int convertStatus; | 434 | int convertStatus; | ||
441 | SEXP valueAsString = PROTECT(R_tryEval(lang2(install("toString"),value),nullptr,&convertStatus)); | 435 | SEXP valueAsString = PROTECT(R_tryEval(lang2(install("toString"),value),nullptr,&convertStatus)); | ||
442 | if (convertStatus == 0) | 436 | if (convertStatus == 0) | ||
443 | { | 437 | { | ||
444 | vars << name; | 438 | vars << name; | ||
445 | values << QString::fromUtf8(translateCharUTF8(asChar(valueAsString))); | 439 | values << QString::fromUtf8(translateCharUTF8(asChar(valueAsString))); | ||
446 | } | 440 | } | ||
447 | } | 441 | } | ||
442 | else | ||||
443 | vars << name; | ||||
448 | } | 444 | } | ||
449 | UNPROTECT(1); | 445 | UNPROTECT(1); | ||
450 | 446 | | |||
451 | /* Obtaining a list of active packages */ | 447 | /* Obtaining a list of active packages */ | ||
452 | SEXP packages=PROTECT(R_tryEval(lang1(install("search")),nullptr,&errorOccurred)); | 448 | SEXP packages=PROTECT(R_tryEval(lang1(install("search")),nullptr,&errorOccurred)); | ||
453 | //int i=1; // HACK to prevent scalability issues | 449 | //int i=1; // HACK to prevent scalability issues | ||
454 | for (int i=1;i<length(packages);i++) // Package #0 is user environment, so starting with 1 | 450 | for (int i=1;i<length(packages);i++) // Package #0 is user environment, so starting with 1 | ||
455 | { | 451 | { | ||
456 | char pos[32]; | 452 | char pos[32]; | ||
457 | sprintf(pos,"%d",i+1); | 453 | sprintf(pos,"%d",i+1); | ||
458 | SEXP f=PROTECT(R_tryEval(lang2(install("ls"),ScalarInteger(i+1)),nullptr,&errorOccurred)); | 454 | SEXP f=PROTECT(R_tryEval(lang2(install("ls"),ScalarInteger(i+1)),nullptr,&errorOccurred)); | ||
459 | for (int i=0;i<length(f);i++) | 455 | for (int i=0;i<length(f);i++) | ||
460 | funcs<<QString::fromUtf8(translateCharUTF8(STRING_ELT(f,i))); | 456 | funcs<<QString::fromUtf8(translateCharUTF8(STRING_ELT(f,i))); | ||
461 | UNPROTECT(1); | 457 | UNPROTECT(1); | ||
462 | } | 458 | } | ||
463 | UNPROTECT(1); | 459 | UNPROTECT(1); | ||
464 | 460 | | |||
465 | emit symbolList(vars, values, funcs); | 461 | emit symbolList(vars, values, funcs); | ||
466 | 462 | setStatus(Idle); | |||
467 | // setStatus(RServer::Idle); | | |||
468 | } | 463 | } | ||
469 | 464 | | |||
470 | void RServer::setStatus(Status status) | 465 | void RServer::setStatus(Status status) | ||
471 | { | 466 | { | ||
472 | if(m_status!=status) | 467 | if(m_status!=status) | ||
473 | { | 468 | { | ||
474 | m_status=status; | 469 | m_status=status; | ||
475 | if(m_isInitialized) | 470 | if(m_isInitialized) | ||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |