enso/app/gui2/shared/ensoFile.ts
Paweł Grabarz 48a5599eb6
improve argument placeholder resolution for partial applications and … (#8794)
Fixes #8788

- Fixed missing argument lists on constructors, and improved handling for various cases of partially applied functions.
- Extended tests to check for correct `self` argument placeholders.
- Additionally reworked some questionable test code to maintain separation between server and client code.

<img width="1241" alt="image" src="https://github.com/enso-org/enso/assets/919491/5377f57f-18f0-4a50-a8ab-9331862ca547">
2024-01-18 13:13:31 +00:00

39 lines
1.1 KiB
TypeScript

const META_TAG = '\n\n\n#### METADATA ####'
export interface EnsoFileParts {
code: string
idMapJson: string | null
metadataJson: string | null
}
export function splitFileContents(content: string): EnsoFileParts {
const splitPoint = content.lastIndexOf(META_TAG)
if (splitPoint < 0) {
return {
code: content,
idMapJson: null,
metadataJson: null,
}
}
const code = content.slice(0, splitPoint)
const metadataString = content.slice(splitPoint + META_TAG.length)
const metaLines = metadataString.trim().split('\n')
const idMapJson = metaLines[0] ?? null
const metadataJson = metaLines[1] ?? null
return { code, idMapJson, metadataJson }
}
export function combineFileParts(parts: EnsoFileParts): string {
const hasMeta = parts.idMapJson != null || parts.metadataJson != null
if (hasMeta) {
return `${parts.code}${META_TAG}\n${parts.idMapJson ?? ''}\n${parts.metadataJson ?? ''}`
} else {
// If code segment contains meta tag, add another one to make sure it is not misinterpreted.
if (parts.code.includes(META_TAG)) {
return `${parts.code}${META_TAG}`
} else {
return parts.code
}
}
}