Skip to content

Commit bfcd3c1

Browse files
committed
feat: configuration option for max rows before truncation
1 parent b6d0b70 commit bfcd3c1

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
- New configuration option for maximum number of result rows before truncating the result table.
6+
Defaults to `25`.
7+
8+
```json
9+
{
10+
"SQLNotebook.maxResultRows": 25
11+
}
12+
```
13+
314
## v0.5.0
415

516
- Bundle `sqls` language server into `vscode-sql-notebook`.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
"type": "number",
103103
"default": 30000,
104104
"description": "Query timeout in milliseconds for cell query execution."
105+
},
106+
"SQLNotebook.maxResultRows": {
107+
"type": "number",
108+
"default": 25,
109+
"description": "Maximum number of result rows to display before truncating result table."
105110
}
106111
}
107112
},

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,24 @@ function resultToMarkdownTable(result: TabularResult): string {
189189
return '*Empty Results Table*';
190190
}
191191

192-
if (result.length > 20) {
193-
result = result.slice(0, 20);
192+
const maxRows = getMaxRows();
193+
if (result.length > maxRows) {
194+
result = result.slice(0, maxRows);
194195
result.push(
195196
Object.fromEntries(Object.entries(result).map((pair) => [pair[0], '...']))
196197
);
197198
}
198199
return `${markdownHeader(result[0])}\n${result.map(markdownRow).join('\n')}`;
199200
}
200201

202+
function getMaxRows(): number {
203+
const fallbackMaxRows = 25;
204+
const maxRows: number | undefined = vscode.workspace
205+
.getConfiguration('SQLNotebook')
206+
.get('maxResultRows');
207+
return maxRows ?? fallbackMaxRows;
208+
}
209+
201210
function escapeNewline(a: string | number | null): string | number | null {
202211
if (typeof a === 'string') {
203212
return a.replace(/\n/g, '\\n').replace(/\r/g, '\\r');

0 commit comments

Comments
 (0)