Skip to content

Commit 6f95b38

Browse files
committed
Truncate repl output as length crosses threshold
Calvas performance can be drastically affected as the size of the repl output window grows. This commit adds a config entry `replOutputMaxLines` which if set to a non-0 number will cause the output window to be truncated if it grows beyond this threshold. Fixes #804
1 parent 839ed37 commit 6f95b38

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changes to Calva.
55
## [Unreleased]
66

77
- Fix: [Rogue loops that print output to stdout cause Calva to hang](https://github.com/BetterThanTomorrow/calva/issues/2010)
8+
- Fix: [Output window becomes very slow when number of lines of content is very high](https://github.com/BetterThanTomorrow/calva/issues/804)
9+
- Partial Fix: [Output window becomes very slow when number of lines of content is very high](https://github.com/BetterThanTomorrow/calva/issues/942)
10+
811
## [2.0.323] - 2023-01-07
912

1013
- Fix: [Provider completions not handling errors gracefully](https://github.com/BetterThanTomorrow/calva/issues/2006)

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,11 @@
775775
"type": "number",
776776
"default": 100
777777
},
778+
"calva.replOutputMaxLines": {
779+
"markdownDescription": "The maximum number of lines to retain in the repl output window. Having the repl output window grow too large can significantly affect performance. Setting this to 0 will disable truncating",
780+
"type": "number",
781+
"default": 1000
782+
},
778783
"calva.depsEdnJackInExecutable": {
779784
"markdownDescription": "Which executable should Calva Jack-in use for starting a deps.edn project? The default is to let Calva choose. It will choose `clojure` if that is installed and working. Otherwise `deps.clj`, which is bundled with Calva, will be used. (This settings has no effect on Windows, where `deps.clj` will always be used.)",
780785
"enum": [

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const KEYBINDINGS_ENABLED_CONFIG_KEY = 'calva.keybindingsEnabled';
1515
const KEYBINDINGS_ENABLED_CONTEXT_KEY = 'calva:keybindingsEnabled';
1616

1717
const REPL_OUTPUT_THROTTLE_RATE_CONFIG_KEY = 'calva.replOutputThrottleRate';
18+
const REPL_OUTPUT_MAX_LINES_CONFIG_KEY = 'calva.replOutputMaxLines';
1819

1920
type ReplSessionType = 'clj' | 'cljs';
2021

@@ -237,6 +238,7 @@ export {
237238
KEYBINDINGS_ENABLED_CONFIG_KEY,
238239
KEYBINDINGS_ENABLED_CONTEXT_KEY,
239240
REPL_OUTPUT_THROTTLE_RATE_CONFIG_KEY,
241+
REPL_OUTPUT_MAX_LINES_CONFIG_KEY,
240242
documentSelector,
241243
ReplSessionType,
242244
getConfig,

src/results-output/results-doc.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const RESULTS_DOC_NAME = `output.${config.REPL_FILE_EXT}`;
2020
const REPL_OUTPUT_THROTTLE_RATE = vscode.workspace
2121
.getConfiguration()
2222
.get<number>(config.REPL_OUTPUT_THROTTLE_RATE_CONFIG_KEY);
23+
const REPL_OUTPUT_MAX_LINES = vscode.workspace
24+
.getConfiguration()
25+
.get<number>(config.REPL_OUTPUT_MAX_LINES_CONFIG_KEY);
26+
2327
const PROMPT_HINT = 'Use `alt+enter` to evaluate';
2428

2529
const START_GREETINGS = [
@@ -306,10 +310,22 @@ async function writeToResultsDoc({ text, onAppended }: ResultsBufferEntry): Prom
306310
const insertPosition = doc.positionAt(Infinity);
307311
const edit = new vscode.WorkspaceEdit();
308312
const editText = util.stripAnsi(text);
313+
314+
if (REPL_OUTPUT_MAX_LINES > 0 && doc.lineCount > REPL_OUTPUT_MAX_LINES) {
315+
edit.delete(
316+
docUri,
317+
new vscode.Range(
318+
new vscode.Position(0, 0),
319+
new vscode.Position(doc.lineCount - REPL_OUTPUT_MAX_LINES, 0)
320+
)
321+
);
322+
}
323+
309324
edit.insert(docUri, insertPosition, editText);
310325
if (!((await vscode.workspace.applyEdit(edit)) && (await doc.save()))) {
311326
return;
312327
}
328+
313329
onAppended?.(
314330
new vscode.Location(docUri, insertPosition),
315331
new vscode.Location(docUri, doc.positionAt(Infinity))

src/results-output/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function splitEditQueueForTextBatching(
2424
const nextBatch = takeWhile(editQueue, (value, index) => {
2525
return index < maxBatchSize && !value.onAppended;
2626
}).map((x) => x.text);
27-
const remainingEditQueue = [...editQueue].slice(nextBatch.length);
27+
const remainingEditQueue = editQueue.slice(nextBatch.length);
2828
return [nextBatch, remainingEditQueue];
2929
}
3030

0 commit comments

Comments
 (0)