(chunks: RMarkdownChunk[], token: vscode.CancellationToken)
| 397 | } |
| 398 | |
| 399 | export function getCodeLenses(chunks: RMarkdownChunk[], token: vscode.CancellationToken): vscode.CodeLens[] { |
| 400 | |
| 401 | const enabledCodeLens = config().get<boolean>('rmarkdown.enableCodeLens'); |
| 402 | if (enabledCodeLens === false) { |
| 403 | return []; |
| 404 | } |
| 405 | |
| 406 | // Iterate through all code chunks for getting chunk information for both CodeLens and chunk background color (set by `editor.setDecorations`) |
| 407 | let codeLenses: vscode.CodeLens[] = []; |
| 408 | for (let i = 1; i <= chunks.length; i++) { |
| 409 | const chunk = chunks.find(e => e.id === i); |
| 410 | if (!chunk) { |
| 411 | continue; |
| 412 | } |
| 413 | const chunkRange = chunk.chunkRange; |
| 414 | const line = chunk.startLine; |
| 415 | |
| 416 | // Enable/disable only CodeLens, without affecting chunk background color. |
| 417 | if (chunk.language === 'r') { |
| 418 | if (token.isCancellationRequested) { |
| 419 | break; |
| 420 | } |
| 421 | codeLenses.push( |
| 422 | new vscode.CodeLens(chunkRange, { |
| 423 | title: 'Run Chunk', |
| 424 | tooltip: 'Run current chunk', |
| 425 | command: 'r.runCurrentChunk', |
| 426 | arguments: [chunks, line] |
| 427 | }), |
| 428 | new vscode.CodeLens(chunkRange, { |
| 429 | title: 'Run Above', |
| 430 | tooltip: 'Run all chunks above', |
| 431 | command: 'r.runAboveChunks', |
| 432 | arguments: [chunks, line] |
| 433 | }), |
| 434 | new vscode.CodeLens(chunkRange, { |
| 435 | title: 'Run Current & Below', |
| 436 | tooltip: 'Run current and all chunks below', |
| 437 | command: 'r.runCurrentAndBelowChunks', |
| 438 | arguments: [chunks, line] |
| 439 | }), |
| 440 | new vscode.CodeLens(chunkRange, { |
| 441 | title: 'Run Below', |
| 442 | tooltip: 'Run all chunks below', |
| 443 | command: 'r.runBelowChunks', |
| 444 | arguments: [chunks, line] |
| 445 | }), |
| 446 | new vscode.CodeLens(chunkRange, { |
| 447 | title: 'Run Previous', |
| 448 | tooltip: 'Run previous chunk', |
| 449 | command: 'r.runPreviousChunk', |
| 450 | arguments: [chunks, line] |
| 451 | }), |
| 452 | new vscode.CodeLens(chunkRange, { |
| 453 | title: 'Run Next', |
| 454 | tooltip: 'Run next chunk', |
| 455 | command: 'r.runNextChunk', |
| 456 | arguments: [chunks, line] |
no test coverage detected