Skip to content

Commit

Permalink
disabled diagnostics and completion for non-R code
Browse files Browse the repository at this point in the history
  • Loading branch information
cassws committed Dec 17, 2019
1 parent b3172de commit 9b2c75d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 9 additions & 13 deletions R/exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,16 @@ evaluate_exercise <- function(exercise, envir) {

engine <- knitr::opts_chunk$get("exercise.engine")
if (!is.null(engine)) {
knitr::opts_chunk$set(engine = engine)
}
# catch cases where exercise.engine is set to R
# NOTE: replace logic with checks for specific supported langauges?
if (engine != 'r' && engine != 'R'){
knitr::opts_chunk$set(engine = engine)
}
}

# write the R code to a temp file (inclue setup code if necessary)
code <- c(exercise$setup, exercise$code)
exercise_r <- "exercise.R"

print('code')
print(code)
print('exercise')
print(exercise)


writeLines(code, con = exercise_r, useBytes = TRUE)

# spin it to an Rmd
Expand All @@ -248,8 +245,6 @@ evaluate_exercise <- function(exercise, envir) {
format = "Rmd")
cat("exercise.Rmd:\n") # debug line
cat(readLines(exercise_rmd), sep = "\n") # debug line
print('exercise_rmd')
print(exercise_rmd)

} else {

Expand Down Expand Up @@ -277,8 +272,6 @@ evaluate_exercise <- function(exercise, envir) {
keep_md = FALSE
)

# ignore if code chunk specifies non-R language

# capture the last value and use a regular output handler for value
# https://github.com/r-lib/evaluate/blob/e81ba2ba181827a86525767371e6dfdeb364c8b7/R/output.r#L54-L56
# @param value Function to handle the values returned from evaluation. If it
Expand Down Expand Up @@ -369,6 +362,7 @@ evaluate_exercise <- function(exercise, envir) {

# get the exercise checker (default does nothing)
err <- NULL

tryCatch({
checker <- eval(parse(text = knitr::opts_chunk$get("exercise.checker")),
envir = envir)
Expand All @@ -380,6 +374,7 @@ evaluate_exercise <- function(exercise, envir) {
return(error_result("Error occured while parsing chunk option 'exercise.checker'."))
}


checker_fn_does_not_exist <- is.null(exercise$check) || is.null(checker)
if (checker_fn_does_not_exist)
checker <- function(...) { NULL }
Expand Down Expand Up @@ -408,6 +403,7 @@ evaluate_exercise <- function(exercise, envir) {
# validate the feedback
feedback_validated(checker_feedback)


# amend output with feedback as required
feedback_html <-
if (!is.null(checker_feedback)) {
Expand Down
8 changes: 8 additions & 0 deletions inst/lib/tutorial/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,15 @@ Tutorial.prototype.$initializeExerciseEditors = function() {
// support startover
var startover_code = exercise.attr('data-startover') === "1" ? code : null;

// disable diagnostic if a langauge engine is set
if (chunk_options["exercise.engine"]) {
diagnostics = null;
}

// disable completion if a language engine is set
if (chunk_options["exercise.engine"]) {
completion = null;
}
// set tutorial options/data
editor.tutorial = {
label: label,
Expand Down

1 comment on commit 9b2c75d

@Anovisions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! Big, huge step forward.

Please sign in to comment.