import type { CellComponent, ColumnDefinition } from "tabulator-tables";
import type { SymbolType } from ".."
/// SVG from https://github.com/olifolkerd/tabulator/blob/master/src/js/modules/Format/defaults/formatters/tickCross.js
/// but with the default font color.
/// hopefully in the future we can set the color as parameter: https://github.com/olifolkerd/tabulator/pull/4791
const TICK_ELEMENT = ``;
function getTabulatorHexaFormatter(padding: number): (cell: CellComponent) => string {
return (cell: CellComponent) => {
const val = cell.getValue();
if (val === undefined || val === null) {
return "";
}
return val !== undefined ? "0x" + val.toString(16).toLowerCase().padStart(padding, "0") : "";
};
}
const SYMBOL_TABLE_COLUMNS: ColumnDefinition[] = [
{ title: "ID", field: "id", headerTooltip: true, sorter: "number", widthGrow: 0.6 },
{
title: "Name",
field: "name",
headerTooltip: true,
sorter: "string",
widthGrow: 2.5,
minWidth: 200,
tooltip : (_event: MouseEvent, cell: CellComponent) => {
const rowData = cell.getRow().getData();
return rowData.name;
}
},
{
title: "Debug",
field: "isDebug",
headerTooltip: true,
hozAlign: "center",
widthGrow: 0.8,
formatter: "tickCross",
formatterParams: {
tickElement: TICK_ELEMENT,
crossElement: false,
}
},
{
title: "Synthetic",
field: "isSynthetic",
headerTooltip: true,
hozAlign: "center",
widthGrow: 0.8,
formatter: "tickCross",
formatterParams: {
tickElement: TICK_ELEMENT,
crossElement: false,
}
},
{
title: "External",
field: "isExternal",
headerTooltip: true,
hozAlign: "center",
widthGrow: 0.8,
formatter: "tickCross",
formatterParams: {
tickElement: TICK_ELEMENT,
crossElement: false,
}
},
{ title: "Type", field: "type", sorter: "string" },
{
title: "File Address",
field: "fileAddress",
headerTooltip: true,
sorter: "number",
widthGrow : 1.25,
formatter: getTabulatorHexaFormatter(16),
},
{
title: "Load Address",
field: "loadAddress",
headerTooltip: true,
sorter: "number",
widthGrow : 1.25,
formatter: getTabulatorHexaFormatter(16),
},
{ title: "Size", field: "size", headerTooltip: true, sorter: "number", formatter: getTabulatorHexaFormatter(8) },
];
const vscode = acquireVsCodeApi();
const previousState: any = vscode.getState();
declare const Tabulator: any; // HACK: real definition comes from tabulator.min.js
const SYMBOLS_TABLE = new Tabulator("#symbols-table", {
height: "100vh",
columns: SYMBOL_TABLE_COLUMNS,
layout: "fitColumns",
selectableRows: false,
data: previousState?.symbols || [],
});
function updateSymbolsTable(symbols: SymbolType[]) {
SYMBOLS_TABLE.setData(symbols);
}
window.addEventListener("message", (event: MessageEvent) => {
const message = event.data;
switch (message.command) {
case "updateSymbols":
vscode.setState({ symbols: message.symbols });
updateSymbolsTable(message.symbols);
break;
}
});