MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / getCurrentChunk

Function getCurrentChunk

src/rmarkdown/chunks.ts:146–174  ·  view source on GitHub ↗
(chunks: RMarkdownChunk[], line: number)

Source from the content-addressed store, hash-verified

144}
145
146export function getCurrentChunk(chunks: RMarkdownChunk[], line: number): RMarkdownChunk | undefined {
147 const textEditor = vscode.window.activeTextEditor;
148 if (!textEditor) {
149 void vscode.window.showWarningMessage('No text editor active.');
150 return;
151 }
152
153 // Case: If `chunks` is empty, return undefined
154 if (chunks.length === 0) {
155 return undefined;
156 }
157
158 // Case: Cursor is above first chunk, use first chunk
159 if (line < chunks[0].startLine) {
160 return chunks[0];
161 }
162 // Case: Cursor is below last chunk, return last chunk
163 if (line > chunks[chunks.length - 1].endLine) {
164 return chunks[chunks.length - 1];
165 }
166 // chunks.filter(i => line >= i.startLine)[0];
167 for (const chunk of chunks) {
168 // Case: Cursor is within chunk, use current chunk
169 // Case: Cursor is between, use next chunk below cursor
170 if (chunk.endLine >= line) {
171 return chunk;
172 }
173 }
174}
175
176function getPreviousChunk(chunks: RMarkdownChunk[], line: number): RMarkdownChunk | undefined {
177 const currentChunk = getCurrentChunk(chunks, line);

Callers 12

highlightCurrentChunkMethod · 0.90
getPreviousChunkFunction · 0.85
getNextChunkFunction · 0.85
runCurrentChunkFunction · 0.85
runCurrentChunkAndMoveFunction · 0.85
runPreviousChunkFunction · 0.85
runNextChunkFunction · 0.85
runAboveChunksFunction · 0.85
runBelowChunksFunction · 0.85
runCurrentAndBelowChunksFunction · 0.85
selectCurrentChunkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected