Search in sources :

Example 6 with NotebookQueueUnit

use of org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit in project rstudio by rstudio.

the class TextEditingTargetNotebook method onRmdChunkOutput.

@Override
public void onRmdChunkOutput(RmdChunkOutputEvent event) {
    // ignore if not targeted at this document
    if (event.getOutput().getDocId() != docUpdateSentinel_.getId())
        return;
    // the server, so clean it up here.
    if (event.getOutput().isEmpty() && !queue_.isExecuting()) {
        events_.fireEvent(new ChunkChangeEvent(docUpdateSentinel_.getId(), event.getOutput().getChunkId(), event.getOutput().getRequestId(), 0, ChunkChangeEvent.CHANGE_REMOVE));
        return;
    }
    String chunkId = event.getOutput().getChunkId();
    // ignore requests performed to initialize satellite chunks
    if (satelliteChunkRequestIds_.contains(event.getOutput().getRequestId()))
        return;
    // if this is the currently executing chunk and it has an error...
    NotebookQueueUnit unit = queue_.executingUnit();
    if (unit != null && unit.getChunkId() == event.getOutput().getChunkId() && event.getOutput().getType() == RmdChunkOutput.TYPE_SINGLE_UNIT && event.getOutput().getUnit().getType() == RmdChunkOutputUnit.TYPE_ERROR) {
        // draw the error 
        Scope scope = getChunkScope(unit.getChunkId());
        if (scope != null) {
            int offset = scope.getBodyStart().getRow();
            List<Integer> lines = unit.getExecutingLines();
            for (Integer line : lines) docDisplay_.setChunkLineExecState(line + offset, line + offset, ChunkRowExecState.LINE_ERROR);
        }
        // error = FALSE
        if (!outputs_.containsKey(chunkId) || !outputs_.get(chunkId).getOptions().error()) {
            clearChunkExecQueue();
        }
    }
    // show output in matching chunk
    if (outputs_.containsKey(chunkId)) {
        // by default, ensure chunks are visible if we aren't replaying them
        // from the cache
        boolean ensureVisible = !event.getOutput().isReplay();
        int mode = queue_.getChunkExecMode(chunkId);
        // no need to make chunks visible in batch mode
        if (ensureVisible && mode == NotebookQueueUnit.EXEC_MODE_BATCH)
            ensureVisible = false;
        outputs_.get(chunkId).getOutputWidget().showChunkOutput(event.getOutput(), mode, NotebookQueueUnit.EXEC_SCOPE_PARTIAL, !queue_.isChunkExecuting(chunkId), ensureVisible);
    }
}
Also used : ChunkChangeEvent(org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) NotebookQueueUnit(org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit)

Example 7 with NotebookQueueUnit

use of org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit in project rstudio by rstudio.

the class NotebookQueueState method dequeueChunk.

public void dequeueChunk(int preambleRow) {
    // find the chunk's ID
    String chunkId = notebook_.getRowChunkId(preambleRow);
    if (StringUtil.isNullOrEmpty(chunkId))
        return;
    notebook_.cleanChunkExecState(chunkId);
    // clear from the execution queue and update display
    for (int i = 0; i < queue_.getUnits().length(); i++) {
        if (queue_.getUnits().get(i).getChunkId() == chunkId) {
            NotebookQueueUnit unit = queue_.getUnits().get(i);
            queue_.removeUnit(unit);
            server_.updateNotebookExecQueue(unit, NotebookDocQueue.QUEUE_OP_DELETE, "", new VoidServerRequestCallback());
            break;
        }
    }
}
Also used : NotebookQueueUnit(org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Example 8 with NotebookQueueUnit

use of org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit in project rstudio by rstudio.

the class NotebookQueueState method queueChunkRange.

private void queueChunkRange(ChunkExecUnit chunk) {
    NotebookQueueUnit unit = unitFromScope(chunk);
    renderLineState(chunk.getScope().getBodyStart().getRow(), unit.getPendingLines(), ChunkRowExecState.LINE_QUEUED);
    notebook_.setChunkState(chunk.getScope(), ChunkContextToolbar.STATE_QUEUED);
    queue_.addUnit(unit);
    server_.updateNotebookExecQueue(unit, NotebookDocQueue.QUEUE_OP_ADD, "", new VoidServerRequestCallback());
}
Also used : NotebookQueueUnit(org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Example 9 with NotebookQueueUnit

use of org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit in project rstudio by rstudio.

the class NotebookQueueState method onNotebookRangeExecuted.

// Event handlers ----------------------------------------------------------
@Override
public void onNotebookRangeExecuted(NotebookRangeExecutedEvent event) {
    if (queue_ == null || event.getDocId() != queue_.getDocId())
        return;
    Scope scope = notebook_.getChunkScope(event.getChunkId());
    if (scope == null)
        return;
    if (isChunkExecuting(event.getChunkId())) {
        if (event.getExprMode() == NotebookRangeExecutedEvent.EXPR_NEW)
            executingUnit_.setExecutingRange(event.getExecRange());
        else
            executingUnit_.extendExecutingRange(event.getExecRange());
        executingUnit_.addCompletedRange(event.getExecRange());
    }
    // add to console history
    events_.fireEvent(new ConsoleHistoryAddedEvent(event.getCode()));
    // find the queue unit and convert to lines
    for (int i = 0; i < queue_.getUnits().length(); i++) {
        NotebookQueueUnit unit = queue_.getUnits().get(i);
        if (unit.getChunkId() == event.getChunkId()) {
            List<Integer> lines = unit.linesFromRange(event.getExecRange());
            renderLineState(scope.getBodyStart().getRow(), lines, ChunkRowExecState.LINE_EXECUTED);
            break;
        }
    }
}
Also used : ConsoleHistoryAddedEvent(org.rstudio.studio.client.workbench.views.console.events.ConsoleHistoryAddedEvent) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) NotebookQueueUnit(org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit)

Aggregations

NotebookQueueUnit (org.rstudio.studio.client.rmarkdown.model.NotebookQueueUnit)9 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)4 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)3 NotebookExecRange (org.rstudio.studio.client.rmarkdown.model.NotebookExecRange)2 ArrayList (java.util.ArrayList)1 ConsoleHistoryAddedEvent (org.rstudio.studio.client.workbench.views.console.events.ConsoleHistoryAddedEvent)1 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)1 ChunkSatelliteCacheEditorStyleEvent (org.rstudio.studio.client.workbench.views.source.editors.text.events.ChunkSatelliteCacheEditorStyleEvent)1 ChunkChangeEvent (org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent)1