mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 01:21:33 +03:00
c811a5ae8b
- Fix the UI problems with our CodeMirror integration (Fixed view stability; Fixed a focus bug; Fixed errors caused by diagnostics range exceptions; Fixed linter invalidation--see https://discuss.codemirror.net/t/problem-trying-to-force-linting/5823; Implemented edit-coalescing for performance). - Introduce an algorithm for applying text edits to an AST. Compared to the GUI1 approach, the new algorithm supports deeper identity-stability for expressions (which is important for subexpression metadata and Y.Js sync), as well as reordered-subtree identification. - Enable the code editor.
23 lines
1016 B
TypeScript
23 lines
1016 B
TypeScript
import { Ast } from './tree'
|
|
|
|
/// Returns a GraphViz graph illustrating parent/child relationships in the given subtree.
|
|
export function graphParentPointers(ast: Ast) {
|
|
const sanitize = (id: string) => id.replace('ast:', '').replace(/[^A-Za-z0-9]/g, '')
|
|
const parentToChild = new Array<{ parent: string; child: string }>()
|
|
const childToParent = new Array<{ child: string; parent: string }>()
|
|
ast.visitRecursiveAst((ast) => {
|
|
for (const child of ast.children()) {
|
|
if (child instanceof Ast)
|
|
parentToChild.push({ child: sanitize(child.id), parent: sanitize(ast.id) })
|
|
}
|
|
const parent = ast.parentId
|
|
if (parent) childToParent.push({ child: sanitize(ast.id), parent: sanitize(parent) })
|
|
})
|
|
let result = 'digraph parentPointers {\n'
|
|
for (const { parent, child } of parentToChild) result += `${parent} -> ${child};\n`
|
|
for (const { child, parent } of childToParent)
|
|
result += `${child} -> ${parent} [weight=0; color=red; style=dotted];\n`
|
|
result += '}\n'
|
|
return result
|
|
}
|