Files
windmill/frontend/src/lib/editorLangUtils.ts
T
GuilhemandClaude Opus 4.8 e98df38ac4 feat(apps): show raw-app fork diffs as per-file tree items (#9491)
* feat(apps): show raw-app fork diffs as per-file tree items

Raw-app diffs previously rendered as one big YAML diff of the whole
serialized app. This explodes a raw app into separate, independently
collapsible diff items — one per file, one per runnable, and an
app.yaml metadata item — that flow through the existing fork-diff
list, sidebar tree, search and count via composite paths
(<appPath>/<file>). Runnables render as script/flow rows (code shown
in a Content tab), and files get extension-specific icons reused from
the raw-app editor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: remove raw-app tree-diff plan doc from the branch

The implementation plan was an authoring aid, not product documentation; drop it so it doesn't ship in the PR.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat: present raw app as an app-headed folder in the diff tree

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix: narrow RawAppFileItem in diff viewer branch (fixes svelte-check)

DiffRow.kind is a plain string so the kind check didn't narrow the union; assert the synthetic item. Also size-guard on the larger side's line count instead of the doubled total, and document normalizeRawApp's per-field value-wrapper precedence.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* style: single-line, lighter diff-tree rows for all item kinds

Add a singleLine mode to WorkspaceItemRow (summary ?? path on one line; DRY'd via a shared body snippet) and use it for every diff-tree leaf, so scripts/flows/triggers/resources/etc. match the raw-app header. Bump rows to py-1.5, force font-normal, and split colours: items in text-primary, folders in text-secondary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor: extract pure diffTree model from WorkspaceDiffDrawer

Move tree construction + keyboard-nav traversal + the folder-keying convention out of the 775-line component into a pure, generic, tested module (buildDiffTree → root/order/parentKeyOf/firstChildKeyOf). Parent and first-child come from a child→parent map built during construction, not from re-splitting a path at the call site, so a node's tree position and its nav parent can't drift — the class of bug behind the ArrowLeft regression. Deletes the forkDiffNav half-seam (its bug lived in the untested caller). 12 new unit tests cover order/parent/first-child incl. the storage-key-vs-friendly-path case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(apps): keep raw-app metadata flag + dedup runnables across path collisions

Addresses two P2 review nits (Codex/claude): (1) rawAppDiffToItems marked metadata by matching path==='app.yaml', so when a real file is named app.yaml the reserved app.yaml~2 metadata item lost its flag/full-YAML toggle — now parseRawAppDiff tags the entry with isMetadata and the items read the flag; (2) runnable composite leaves weren't deduped against real files, so a real file at runnables/<name> could produce a duplicate leaf — now reserved (slash-normalized) like parseRawAppDiff. +2 tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(apps): dedup /app.yaml metadata collision + disambiguate synthetic row keys

Two follow-up P2s from Pi/Codex re-review of the prior fix: (1) parseRawAppDiff's collision set used raw file keys, so a real file /app.yaml (leading slash, which joinAppPath strips) still collided with the synthetic app.yaml leaf — now slash-normalized via a shared stripLeadingSlash, +test. (2) synthetic raw-app items (runnables rendered as script/flow) could share kind+path identity with a real workspace script/flow at <appPath>/runnables/<name>, causing duplicate {#each} keys and broken nav — itemKey now prefixes synthetic items (rawapp:).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(apps): canonicalize raw-app file keys to dedup leading-slash collisions

Codex P2: a file keyed /App.tsx on one side and App.tsx on the other became two entries that joinAppPath collapsed to one composite path → duplicate row key. asFileMap now strips the leading slash so both sides resolve to one file. +test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* perf(apps): lazy-mount per-file diff editors as they scroll into view

Exploding a raw app into N per-file rows mounted N Monaco DiffEditors at once (3 reviews flagged it). Each block's editor now mounts only when it scrolls within ~200px of the viewport (IntersectionObserver rooted on the scroll container), showing a light placeholder until then; mountedRows latches so it never unmounts on scroll-away. Verified: ~6 of 13 mount initially, the rest on scroll.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 09:23:14 +02:00

133 lines
2.2 KiB
TypeScript

export function langToExt(lang: string): string {
switch (lang) {
case 'tsx':
return 'tsx'
case 'javascript':
return 'js'
case 'jsx':
return 'js'
case 'bunnative':
return 'ts'
case 'json':
return 'json'
case 'sql':
return 'sql'
case 'yaml':
return 'yaml'
case 'typescript':
return 'ts'
case 'python':
return 'py'
case 'go':
return 'go'
case 'bash':
return 'sh'
case 'powershell':
return 'ps1'
case 'php':
return 'php'
case 'rust':
return 'rs'
case 'deno':
return 'ts'
case 'nativets':
return 'ts'
case 'graphql':
return 'gql'
case 'css':
return 'css'
case 'ansible':
return 'yml'
case 'csharp':
return 'cs'
case 'nu':
return 'nu'
case 'java':
return 'java'
case 'svelte':
return 'svelte'
case 'vue':
return 'vue'
default:
return 'unknown'
}
}
export function extToLang(ext: string) {
switch (ext) {
case 'tsx':
return 'typescript'
case 'ts':
return 'typescript'
case 'js':
return 'javascript'
case 'jsx':
return 'javascript'
case 'json':
return 'json'
case 'sql':
return 'sql'
case 'yaml':
return 'yaml'
case 'py':
return 'python'
case 'go':
return 'go'
case 'sh':
return 'bash'
case 'ps1':
return 'powershell'
case 'php':
return 'php'
case 'rs':
return 'rust'
case 'gql':
return 'graphql'
case 'css':
return 'css'
case 'scss':
return 'scss'
case 'less':
return 'less'
case 'html':
case 'htm':
return 'html'
case 'md':
case 'markdown':
return 'markdown'
case 'xml':
return 'xml'
case 'svg':
return 'xml'
case 'txt':
return 'plaintext'
case 'yml':
return 'ansible'
case 'cs':
return 'csharp'
case 'svelte':
return 'svelte'
case 'vue':
return 'vue'
case 'nu':
return 'nu'
case 'java':
return 'java'
case 'rb':
return 'ruby'
case 'r':
return 'r'
// for related places search: ADD_NEW_LANG
default:
return 'unknown'
}
}
export function createHash() {
return (Math.random() + 1).toString(36).substring(2)
}
export function createLongHash() {
return 'h' + Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2)
}