Skip to content

Commit 661328d

Browse files
authored
Merge pull request #272 from codefori/feature/formatted_json
Formatted JSON columns
2 parents 1bbc180 + 6b372d1 commit 661328d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/views/html.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export function getHeader(options: {withCollapsed?: boolean} = {}): string {
3131
#resultset td {
3232
padding: 5px 15px;
3333
}
34+
35+
#resultset tbody tr:hover {
36+
background-color: var(--vscode-list-hoverBackground);
37+
}
3438
3539
#resultset tbody tr {
3640
border-bottom: 1px solid var(--vscode-activityBar-border);

src/views/results/html.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,27 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
184184
// Insert a cell at the end of the row
185185
var newCell = newRow.insertCell();
186186
187-
// Append a text node to the cell
188-
189-
//TODO: handle cell formatting here
190187
var newDiv = document.createElement("div");
191188
newDiv.className = "hoverable";
192-
newDiv.appendChild(document.createTextNode(cell === undefined ? 'null' : cell));
193189
190+
// Append a formatted JSON object to the cell
191+
const contentMightBeJson = typeof cell === 'string' && (cell.startsWith('{') || cell.startsWith('[')) && (cell.endsWith('}') || cell.endsWith(']'));
192+
let isJson = false;
193+
if (contentMightBeJson) {
194+
try {
195+
const cellJson = JSON.stringify(JSON.parse(cell), null, 2);
196+
newDiv.style.whiteSpace = "pre";
197+
newDiv.style["font-family"] = "monospace";
198+
newDiv.innerText = cellJson;
199+
isJson = true;
200+
} catch (e) {}
201+
}
202+
203+
if (!isJson) {
204+
// Append a text node to the cell
205+
newDiv.appendChild(document.createTextNode(cell === undefined ? 'null' : cell));
206+
}
207+
194208
newCell.appendChild(newDiv);
195209
}
196210
}

0 commit comments

Comments
 (0)