Opens a *.segform.json file as an interactive form instead of raw JSON: the extension hosts a
webview (React + Formily + antd v5) and keeps the file and the form in sync in both directions.
Version 1.1.1
- Reads GitLab Personal Access Tokens from Git Credential Manager instead of bundling a token.
- Shows centred error dialogs for network and authentication failures, with recovery actions.
- Displays the preview shell immediately, including DEBUG VIEW, while the schema loads.
- Queues complete schema-loading operations within each Extension Host.
Getting started
- Install
segjsonform-1.1.1.vsix with Extensions: Install from VSIX... in VS Code.
- Ensure Git and a credential helper (such as Git Credential Manager) are available.
- Connect to the corporate network or VPN and configure a Personal Access Token, not a password:
Gitlab Settings Preparation.
- Open a
*.segform.json file. Select a schema category and template if prompted.
Recovery and credential management
Network requests time out after 15 seconds. A network error opens a centred dialog with Retry
and Open Debug View. DEBUG VIEW is the switch in the top-right of the form: it opens the
JSON source beside the preview, allowing source editing even when the schema is unavailable.
It does not enable local schema loading; the workspace .debug file controls that separately.
A 401 invalidates the in-memory token and removes the domain credential. If removal fails,
the dialog reports that failure and offers Retry Credential Removal; the extension will not
read another credential until removal succeeds. A 403 does not delete the credential:
check token permissions and project access, then use Refresh Credential.
Authentication dialogs provide Open Gitlab Settings Preparation to open the setup guide.
After changing the token outside VS Code, run SEG Form: Refresh GitLab Credential from the
Command Palette. This clears the in-memory cache and reloads open forms; it does not delete a
valid credential from the system store.
To remove the locally stored domain credential manually, run this in PowerShell:
"protocol=https`nhost=gitlab.web.sg.lan`n`n" | git credential reject
Then run SEG Form: Refresh GitLab Credential. Removing this credential may also affect Git
operations against the same domain. To revoke the token itself, revoke it in GitLab's Access
Tokens settings; removing a local credential does not revoke the server-side token.
How it works
extension host (src/extension.ts) webview (webview/app.tsx)
───────────────────────────────── ──────────────────────────
CustomTextEditorProvider ── boot payload ──► Formily form + antd UI
· resolves the schema · builds one field per schema node
· reads the document · ArrayTable columns with resize/sort/filter
· sorts the JSON keys on save ◄── edits ── · writes every change back
| Piece |
What it does |
src/extension.ts |
Registers the custom editor for **/*.segform.json (viewType: segform.preview), resolves the schema (GitLab / HTTP / local file), reads and writes the document, and keeps a text tab and the form from fighting each other. |
webview/app.tsx |
The form host: builds the Formily form from the schema, injects the table features (SortableTable, SmartColumn), tracks validation, saves on a debounce, and follows the VS Code theme. |
webview/ConcentricChart.tsx |
The sunburst chart used by the review forms (x-component: "ConcentricChart"). |
webview/theme.ts |
useVsCodeTheme() (follows vscode-dark on <body>) and contrastText() for labels drawn on coloured areas. |
webview/CardList.tsx |
The record-oriented array renderer (a card per record + a filter bar) used by the text-heavy tables. The schema contract is documented in CardList.guideline.md. |
media/ |
The bundled webview assets (app.js, app.css) - generated, never edit them by hand. |
dist/extension.js |
The bundled extension host - generated. |
Schema resolution
The form's segformSchema determines the source:
- GitLab - a value beginning with
SEGSchemas: is resolved as SEGSchemas:<Category>/<Name>
through the GitLab API (GITLAB_HOST / GITLAB_PROJECT_ID / GITLAB_BRANCH at the top of
src/extension.ts). The token is the domain-level git credential of GITLAB_HOST
(git credential fill), so it must be a Personal Access Token, not a password; see
Gitlab Settings Preparation.
A 401 removes the stored credential (git credential reject); network, 401, 403 and missing
credential failures each open a modal dialog with Retry, and the form shows the reason until a
retry succeeds.
Within one Extension Host, schema loads run in FIFO order, including credential operations,
dialogs and inline retries. Different Extension Host processes are independent; there is no
cross-process lock. Schema title requests are sequential so a failed request cannot leave
pending requests behind the error dialog.
Use SEG Form: Refresh GitLab Credential after changing the stored token externally.
Refresh clears the in-memory cache without deleting a valid stored credential. A failed 401
removal must finish successfully before another credential is read. Closing an error dialog
ends that task and permits the next queued form to load; it does not imply the error was fixed.
- HTTP(S) - fetched directly when workspace local-schema mode is enabled.
- Local file - next to the document, then relative to the workspace root; only allowed while
local-schema mode is enabled (a
.debug file at the workspace root).
In production a malformed value makes the extension prompt for a schema and write the selection back
into the document.
The theme
The webview must follow the VS Code colour theme, and it has two independent pieces:
- antd components follow it through the
ConfigProvider in webview/app.tsx
(darkAlgorithm chosen from useVsCodeTheme()).
- the chart does not -
@ant-design/plots ignores the antd theme, so ConcentricChart passes
the G2 theme as an object ({ type: 'classicDark' | 'classic', ... }) and picks each slice
label's colour from the slice's own background with contrastText(). Without that the chart kept a
light surface, a white ring stroke and white labels in every theme.
The drill-down breadcrumb
The breadcrumb (the top-left path shown after a drill-down) is drawn by G2 with a hard-coded black
fill (rgba(0,0,0,0.6) in @antv/g2/esm/interaction/drillDown.js) that no theme style reaches, so it
was unreadable on a dark background. Its colour has to be set through the theme, not through
interaction, because of how G2 resolves interaction options:
bubbleOptions (@antv/g2/esm/runtime/plot.js) merges the view's interaction with the marks'
([viewInteraction, ...markInteractions].reduce(deepMix)) - the mark wins, and the partition
mark already declares interaction: { drillDown: true }, so a drillDown option written on the
chart config is discarded.
useThemeInteraction then reads theme[<interaction name>] as that interaction's defaults, and
ClassicDark(options) / Classic(options) spread the extra theme keys onto the resolved theme.
So the option lives in theme.drillDown.breadCrumb - style colours the path text, active is the
hover colour of the clickable ancestors. Two traps, both verified the hard way:
- an interaction name must be exact (
drillDown, not drill-down): an unknown name registers
nothing, and the thrown error also kills every interaction processed after it - the chart goes inert;
@ant-design/plots v2 has no interactions (plural) list. A v1-style
interactions: [{ type: '...' }] is silently ignored.
Commands
| Command |
What it does |
segjsonform.refreshGitLabCredential |
Clears the cached credential and reloads open forms after the stored token changes. |
segjsonform.openPreviewToSide |
Opens the form in the column next to the source. |
segjsonform.openSourceAndPreviewToSide |
Opens the source editor beside the form (the "debug view"). Also on the editor title bar and the explorer context menu for *.segform.json. |
contributes.configurationDefaults maps *.segform.json to the segform.preview custom editor, so a
double-click on such a file opens the form directly (a user setting still overrides it). The extension
never moves an existing tab: the form tab is the anchor, and the source opens beside it.
Build, run, test
npm install
npm run compile # check-types + lint + esbuild bundle
node --test tests/operationQueue.test.cjs tests/credentials.test.cjs
npm run package # production bundles only
vsce package --no-dependencies --out segjsonform-1.1.1.vsix --baseContentUrl https://gitlab.web.sg.lan/ci-development/seg-form/-/blob/master/Projects --baseImagesUrl https://gitlab.web.sg.lan/ci-development/seg-form/-/raw/master/Projects
| Script |
Purpose |
compile |
check-types + lint + node esbuild.js |
package |
the same, then esbuild.js --production |
check-types |
tsc --noEmit for the extension and the webview |
test |
vscode-test; expects extension-host tests in out/test/**/*.test.js |
The Node tests verify FIFO ordering, inline retries, cached credentials, failed credential removal
and failed credential persistence using mocks. Real GCM interaction, VPN failures and restored
editor tabs should also be checked in an Extension Development Host. Packaging runs
vscode:prepublish automatically; npm run package alone does not create a VSIX.
Press F5 to launch an Extension Development Host, then open any *.segform.json.
Known issues
| # |
Issue |
Notes |
| 1 |
A GitLab token was committed in earlier revisions of src/extension.ts (GITLAB_TOKEN) |
The code now uses the user's git credential; the token in the git history must be revoked on GitLab. |
| 3 |
webview/app.tsx mixes view state, table patching and the VS Code protocol in one file |
The pure helpers (the theme, the JSON key sort, the schema-path parsing) would be easier to test if they were extracted; the extension's rootDir is src, so the webview helpers cannot be imported by the extension tests as they are. |