brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 9d34681 Raw
116 lines · typescript
1import type { CellComponent, ColumnDefinition } from "tabulator-tables";2import type { SymbolType } from ".."3 4/// SVG from https://github.com/olifolkerd/tabulator/blob/master/src/js/modules/Format/defaults/formatters/tickCross.js5/// but with the default font color.6/// hopefully in the future we can set the color as parameter: https://github.com/olifolkerd/tabulator/pull/47917const TICK_ELEMENT = `<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="var(--vscode-editor-foreground)" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34  c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351  l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07  l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>`;8 9function getTabulatorHexaFormatter(padding: number): (cell: CellComponent) => string {10  return (cell: CellComponent) => {11    const val = cell.getValue();12    if (val === undefined || val === null) {13      return "";14    }15 16    return val !== undefined ? "0x" + val.toString(16).toLowerCase().padStart(padding, "0") : "";17  };18}19 20const SYMBOL_TABLE_COLUMNS: ColumnDefinition[] = [21  { title: "ID", field: "id", headerTooltip: true, sorter: "number", widthGrow: 0.6 },22  {23    title: "Name",24    field: "name",25    headerTooltip: true,26    sorter: "string",27    widthGrow: 2.5,28    minWidth: 200,29    tooltip : (_event: MouseEvent, cell: CellComponent) => {30      const rowData = cell.getRow().getData();31      return rowData.name;32    }33  },34  {35    title: "Debug",36    field: "isDebug",37    headerTooltip: true,38    hozAlign: "center",39    widthGrow: 0.8,40    formatter: "tickCross",41    formatterParams: {42      tickElement: TICK_ELEMENT,43      crossElement: false,44    }45  },46  {47    title: "Synthetic",48    field: "isSynthetic",49    headerTooltip: true,50    hozAlign: "center",51    widthGrow: 0.8,52    formatter: "tickCross",53    formatterParams: {54      tickElement: TICK_ELEMENT,55      crossElement: false,56    }57  },58  {59    title: "External",60    field: "isExternal",61    headerTooltip: true,62    hozAlign: "center",63    widthGrow: 0.8,64    formatter: "tickCross",65    formatterParams: {66      tickElement: TICK_ELEMENT,67      crossElement: false,68    }69  },70  { title: "Type", field: "type", sorter: "string" },71  {72    title: "File Address",73    field: "fileAddress",74    headerTooltip: true,75    sorter: "number",76    widthGrow : 1.25,77    formatter: getTabulatorHexaFormatter(16),78  },79  {80    title: "Load Address",81    field: "loadAddress",82    headerTooltip: true,83    sorter: "number",84    widthGrow : 1.25,85    formatter: getTabulatorHexaFormatter(16),86  },87  { title: "Size", field: "size", headerTooltip: true, sorter: "number", formatter: getTabulatorHexaFormatter(8) },88];89 90const vscode = acquireVsCodeApi();91const previousState: any = vscode.getState();92 93declare const Tabulator: any; // HACK: real definition comes from tabulator.min.js94const SYMBOLS_TABLE = new Tabulator("#symbols-table", {95  height: "100vh",96  columns: SYMBOL_TABLE_COLUMNS,97  layout: "fitColumns",98  selectableRows: false,99  data: previousState?.symbols || [],100});101 102function updateSymbolsTable(symbols: SymbolType[]) {103  SYMBOLS_TABLE.setData(symbols);104}105 106window.addEventListener("message", (event: MessageEvent<any>) => {107  const message = event.data;108  switch (message.command) {109    case "updateSymbols":110      vscode.setState({ symbols: message.symbols });111      updateSymbolsTable(message.symbols);112      break;113  }114});115 116