From f6ac40b10db81f05adaf524fcc481607492e300d Mon Sep 17 00:00:00 2001 From: elliot Date: Fri, 14 Aug 2026 10:28:57 -0400 Subject: [PATCH 1/2] add #| yaml injection language --- apps/vscode/syntaxes/build-lang.js | 7 + apps/vscode/syntaxes/quarto.tmLanguage | 1449 ++++++++++++++++++++++++ 2 files changed, 1456 insertions(+) diff --git a/apps/vscode/syntaxes/build-lang.js b/apps/vscode/syntaxes/build-lang.js index b258b4105..2c9ac1104 100644 --- a/apps/vscode/syntaxes/build-lang.js +++ b/apps/vscode/syntaxes/build-lang.js @@ -491,6 +491,13 @@ const fencedCodeBlockDefinition = ( while: (^|\\G)(?!\\s*([\`~]{3,})\\s*$) contentName: ${contentName} patterns: + - begin: ^(\\s*)(#\\|) + while: ^(\\s*)(#\\|) + captures: + '2': {name: 'comment.line.number-sign.quarto'} + contentName: meta.embedded.block.yaml + patterns: + - {include: 'source.yaml'} ${indent(4, scopes)} `; }; diff --git a/apps/vscode/syntaxes/quarto.tmLanguage b/apps/vscode/syntaxes/quarto.tmLanguage index a5a9a842a..4e668c16e 100644 --- a/apps/vscode/syntaxes/quarto.tmLanguage +++ b/apps/vscode/syntaxes/quarto.tmLanguage @@ -172,6 +172,29 @@ meta.embedded.block.css patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.css @@ -225,6 +248,29 @@ meta.embedded.block.html patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.html.basic @@ -278,6 +324,29 @@ meta.embedded.block.ini patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.ini @@ -331,6 +400,29 @@ meta.embedded.block.java patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.java @@ -384,6 +476,29 @@ meta.embedded.block.lua patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.lua @@ -437,6 +552,29 @@ meta.embedded.block.makefile patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.makefile @@ -490,6 +628,29 @@ meta.embedded.block.perl patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.perl @@ -543,6 +704,29 @@ meta.embedded.block.prql patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.prql @@ -596,6 +780,29 @@ meta.embedded.block.r patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.r @@ -649,6 +856,29 @@ meta.embedded.block.julia patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.julia @@ -702,6 +932,29 @@ meta.embedded.block.matlab patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.matlab @@ -755,6 +1008,29 @@ meta.embedded.block.stata patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.stata @@ -808,6 +1084,29 @@ meta.embedded.block.dot patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.dot @@ -861,6 +1160,29 @@ meta.embedded.block.mermaid patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.mmd @@ -914,6 +1236,29 @@ meta.embedded.block.plantuml patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.wsd @@ -967,6 +1312,29 @@ meta.embedded.block.ruby patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.ruby @@ -1020,6 +1388,29 @@ meta.embedded.block.php patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.html.basic @@ -1077,6 +1468,29 @@ meta.embedded.block.sql patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.sql @@ -1130,6 +1544,29 @@ meta.embedded.block.vs_net patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.asp.vb.net @@ -1183,6 +1620,29 @@ meta.embedded.block.xml patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.xml @@ -1236,6 +1696,29 @@ meta.embedded.block.xsl patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.xml.xsl @@ -1289,6 +1772,29 @@ meta.embedded.block.yaml patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.yaml @@ -1342,6 +1848,29 @@ meta.embedded.block.dosbatch patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.batchfile @@ -1395,6 +1924,29 @@ meta.embedded.block.clojure patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.clojure @@ -1448,6 +2000,29 @@ meta.embedded.block.coffee patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.coffee @@ -1501,6 +2076,29 @@ meta.embedded.block.c patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.c @@ -1554,6 +2152,29 @@ meta.embedded.block.cpp source.cpp patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.cpp @@ -1607,6 +2228,29 @@ meta.embedded.block.diff patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.diff @@ -1660,6 +2304,29 @@ meta.embedded.block.dockerfile patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.dockerfile @@ -1713,6 +2380,29 @@ meta.embedded.block.git_commit patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.git-commit @@ -1766,6 +2456,29 @@ meta.embedded.block.git_rebase patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.git-rebase @@ -1819,6 +2532,29 @@ meta.embedded.block.go patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.go @@ -1872,6 +2608,29 @@ meta.embedded.block.groovy patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.groovy @@ -1925,6 +2684,29 @@ meta.embedded.block.pug patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.pug @@ -1978,6 +2760,29 @@ meta.embedded.block.javascript patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.js @@ -2031,6 +2836,29 @@ meta.embedded.block.js_regexp patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.js.regexp @@ -2084,6 +2912,29 @@ meta.embedded.block.json patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.json @@ -2137,6 +2988,29 @@ meta.embedded.block.jsonc patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.json.comments @@ -2190,6 +3064,29 @@ meta.embedded.block.less patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.css.less @@ -2243,6 +3140,29 @@ meta.embedded.block.objc patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.objc @@ -2296,6 +3216,29 @@ meta.embedded.block.swift patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.swift @@ -2349,6 +3292,29 @@ meta.embedded.block.scss patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.css.scss @@ -2402,6 +3368,29 @@ meta.embedded.block.perl6 patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.perl.6 @@ -2455,6 +3444,29 @@ meta.embedded.block.powershell patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.powershell @@ -2508,6 +3520,29 @@ meta.embedded.block.stan patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.stan @@ -2561,6 +3596,29 @@ meta.embedded.block.python patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.python @@ -2614,6 +3672,29 @@ meta.embedded.block.regexp_python patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.regexp.python @@ -2667,6 +3748,29 @@ meta.embedded.block.rust patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.rust @@ -2720,6 +3824,29 @@ meta.embedded.block.scala patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.scala @@ -2773,6 +3900,29 @@ meta.embedded.block.shellscript patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.shell @@ -2826,6 +3976,29 @@ meta.embedded.block.typescript patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.ts @@ -2879,6 +4052,29 @@ meta.embedded.block.typescriptreact patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.tsx @@ -2932,6 +4128,29 @@ meta.embedded.block.typst patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.typst @@ -2985,6 +4204,29 @@ meta.embedded.block.csharp patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.cs @@ -3038,6 +4280,29 @@ meta.embedded.block.fsharp patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.fsharp @@ -3091,6 +4356,29 @@ meta.embedded.block.dart patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.dart @@ -3144,6 +4432,29 @@ meta.embedded.block.handlebars patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.html.handlebars @@ -3197,6 +4508,29 @@ meta.embedded.block.markdown patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.html.markdown @@ -3250,6 +4584,29 @@ meta.embedded.block.log patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.log @@ -3303,6 +4660,29 @@ meta.embedded.block.erlang patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.erlang @@ -3356,6 +4736,29 @@ meta.embedded.block.elixir patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include source.elixir @@ -3409,6 +4812,29 @@ meta.embedded.block.latex patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.tex.latex @@ -3462,6 +4888,29 @@ meta.embedded.block.bibtex patterns + + begin + ^(\s*)(#\|) + while + ^(\s*)(#\|) + captures + + 2 + + name + comment.line.number-sign.quarto + + + contentName + meta.embedded.block.yaml + patterns + + + include + source.yaml + + + include text.bibtex From 79f8b4c275935b482a2405e9d321638ee4a7ea67 Mon Sep 17 00:00:00 2001 From: elliot Date: Fri, 14 Aug 2026 10:55:27 -0400 Subject: [PATCH 2/2] Add background, underline, and opacity to #| lines --- apps/vscode/src/providers/background.ts | 82 ++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/apps/vscode/src/providers/background.ts b/apps/vscode/src/providers/background.ts index 7b25a45b9..b3e6e87bf 100644 --- a/apps/vscode/src/providers/background.ts +++ b/apps/vscode/src/providers/background.ts @@ -153,13 +153,28 @@ async function setEditorHighlightDecorations( // ranges to highlight const blockRanges: vscode.Range[] = []; const inlineRanges: vscode.Range[] = []; + const optionLineRanges: vscode.Range[] = []; + const optionSeparatorRanges: vscode.Range[] = []; if (highlightingConfig.enabled()) { // find code blocks const tokens = engine.parse(editor.document); for (const block of tokens.filter(isExecutableLanguageBlock)) { - blockRanges.push(vscRange(block.range)); + const blockRange = vscRange(block.range); + blockRanges.push(blockRange); + + // cell options (#| comments) get a darker background, and the last + // option line gets a separator (rendered as a bottom border) + const lines = hashPipeLines(editor.document, blockRange); + for (const line of lines) { + optionLineRanges.push(editor.document.lineAt(line).range); + } + if (lines.length > 0) { + optionSeparatorRanges.push( + editor.document.lineAt(lines[lines.length - 1]).range + ); + } } // find inline executable code @@ -186,10 +201,75 @@ async function setEditorHighlightDecorations( highlightingConfig.inlineBackgroundDecoration(), inlineRanges ); + editor.setDecorations(cellOptionsBackgroundDecoration, optionLineRanges); + editor.setDecorations(cellOptionsSeparatorDecoration, optionSeparatorRanges); } function clearEditorHighlightDecorations(editor: vscode.TextEditor) { editor.setDecorations(highlightingConfig.backgroundDecoration(), []); + editor.setDecorations(cellOptionsBackgroundDecoration, []); + editor.setDecorations(cellOptionsSeparatorDecoration, []); +} + +// these composite on top of the cell background decoration, so a +// translucent black overlay reads as "slightly darker" in both themes +// (the text is also slightly dimmed to de-emphasize options vs. code) +const cellOptionsBackgroundDecoration = vscode.window.createTextEditorDecorationType({ + isWholeLine: true, + opacity: "0.75", + light: { + backgroundColor: "#00000012", + }, + dark: { + backgroundColor: "#00000033", + }, +}); + +// the separator is rendered via an "after" attachment (absolutely +// positioned to span the bottom of the row) rather than a border on the +// line itself: vscode applies line decorations to every visual row of a +// soft-wrapped line, which would repeat the border on each wrapped row, +// while an attachment is placed once, after the line's content +const cellOptionsSeparatorDecoration = vscode.window.createTextEditorDecorationType({ + isWholeLine: true, + after: { + contentText: "", + textDecoration: + "none; position: absolute; left: 0; bottom: 0; width: 100vw; border-bottom: 1px solid;", + }, + light: { + after: { + borderColor: "#00000025", + }, + }, + dark: { + after: { + borderColor: "#FFFFFF25", + }, + }, +}); + +// document lines of the leading run of cell option (#|) comments in a cell +// (same pattern as the tmLanguage rule in ../../syntaxes/build-lang.js: +// optional leading whitespace, then "#|" or "# |") +// +// note: this only handles #-comment languages (r, python, julia, etc.). +// to generalize to all languages (//| for js, --| for sql, /*| ... */ +// for c, etc.), derive the prefix from the block's language using +// kLangCommentChars/optionCommentPattern in packages/core/src/jupyter/options.ts +function hashPipeLines( + document: vscode.TextDocument, + blockRange: vscode.Range +): number[] { + const lines: number[] = []; + const lastLine = Math.min(blockRange.end.line, document.lineCount - 1); + for (let i = blockRange.start.line + 1; i <= lastLine; i++) { + if (!/^\s*# ?\|/.test(document.lineAt(i).text)) { + break; + } + lines.push(i); + } + return lines; } enum CellBackgroundColor {