Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 60 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ platform API version.
seven graphs of a real design. The estimate is good to about a factor of
two.

- **The layout rates of a product** (`DiagramProfile.elkServer.rates`,
`ElkServerOptions.rates`). The rates of the platform were measured with its
own layout options, and a product that lays out with other options can be
far from them. mlir-viewer has a configurator of its own: one function of
6,172 nodes, 5,960 of them in one block, is 24 s on elkjs by the middle
rates and 12 min by the rates mlir measured, and elkjs was still on it
after 35 minutes. A product that measured its layout names its rates
beside its jar. `auto` then chooses the engine by them, a layout elkjs is
not to take is refused by them, and the log gives their estimate beside
the time a layout took. One set prices every layout of the product, so a
product that lays out with the presets of the platform names none, and is
priced as before. Rates that are not four numbers for each engine, one of
them above zero, are said in the log and left out.

- **A `ram` flow symbol.** The flow symbols (`FlowSymbols`, the dataflow
pictograms a product draws a node as) have a 29th kind, `ram`, in the
memory family: a memory itself, with no operand and one result. `memory`
Expand Down Expand Up @@ -148,18 +162,52 @@ platform API version.
nodes. Every layout logs its estimate beside the time it took
(`[dialogram layout] elkjs: 40 nodes, 110 edges in 229 ms (estimated
228 ms)`).
- **A layout the ELK server did not answer is refused when elkjs would not
finish it in the same time.** The server's timeout
(`<settingsNamespace>.layout.serverTimeoutMs`, 120 s) or failure used to
hand any graph to elkjs, which runs on the extension host's thread: a
graph the server could not finish in two minutes held every diagram, and
the host, for many times that. Such a layout now fails with a
`LayoutRefusedError`, and the diagram says on its status line that it was
not laid out, with the estimate. A graph elkjs is estimated to finish
within the timeout still falls back to it, or within a minute when the
timeout is shorter (`elkjsTakeoverMs`), and so does every graph when there
is no server to ask (no Java, no jar): elkjs is all there is then. A Free
Ports layout is refused at its probe, so the server is asked once.
- **elkjs takes no layout it would hold the host for: such a graph is the
ELK server's alone.** elkjs runs on the extension host's thread. A graph
the server could not finish in two minutes, or one opened without Java,
went to elkjs and held every diagram, and the host, for many times that:
one function of 6,172 nodes in mlir-viewer was still on elkjs after 35
minutes. Whoever was to lay a graph out, elkjs now takes it only when it is
estimated to finish within a minute (`ELKJS_BUDGET_MS`), whatever the
server's timeout. That holds for a server that timed out or failed, for one
that is not running (no Java, no jar), and with `layout.engine` set to
`elkjs`, where the switch now stands before elkjs too and starts no server.
Past the estimate the layout fails with a `LayoutRefusedError`, and the
diagram says on its status line that it was not laid out, why the server
did not lay it out, and what elkjs would have taken. A diagram that was
never laid out stays so, with that line. A Free Ports layout is refused at
its probe, so the server is asked once. A server that cannot start says
what it failed on (`ElkServerProcess.failure`): a `java` that is not there
could not be run, with the error of the system, and one that ends at once
(a Java before 17, an option it does not know) exited, with the line that
names the error, where both were reported as a server slow to start. A
graph of another algorithm than layered has no estimate, and is not
refused by this rule.

- **A server a layout timed out on is ended.** A layout that ran past its
time cannot be taken back from the ELK server, which stayed on it with
nobody waiting: a core and a gigabyte of heap, for minutes on a graph of
thousands of nodes, while the next layouts queued behind it. A server that
had a minute or more for the layout (`ELK_SERVER_STUCK_MS`) is retired, as
one that overflowed its stack is. It answers what else it was asked and is
then ended, and the next layout starts another. With a shorter timeout the
server is left to finish, so that a JVM is not ended at every layout. An
answer that arrived while the host was busy is read before the timeout is
called.

- **The status line is read without the pointer.** What the server says of
a diagram (a `StatusAction`: a layout that was refused, one that was run
roughly) was an icon in the top left corner, under the controls of a
product, with its words shown only under the pointer. A warning or an
error is now a line at the bottom left of the canvas, over the crumbs, in
the look of the loading pill, with the words in it. It keeps clear of the
property panel and of an open outline panel, goes to the top left while
the chat card is shown, and a fit keeps the drawing clear of it. GLSP's
own progress in the same place ("Model loading in progress") is not
drawn: the loading indicator tells it. The note of a rough layout is a
warning now, so that it is on the line. The rules are `status-line.css`,
which a product with a stylesheet of its own imports alone.

- **A layout that fails leaves the diagram as it was.** The layout commands
clear every edge route before ELK is asked, and Untangled and Free Ports
move the ports first. A layout that then failed, for any reason, left the
Expand Down
2 changes: 2 additions & 0 deletions packages/diagram-client/src/canvas-overlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const CANVAS_OVERLAYS = [
'.minimize-palette-button',
'.floating-tool-btn',
'.workflow-breadcrumb-overlay',
// The status line (status-line.css): not drawn, and so not counted, without words.
'.sprotty-status',
'.workflow-fab-stack',
'.property-panel.floating:not(.collapsed)',
'.workflow-chat-panel.visible',
Expand Down
1 change: 1 addition & 0 deletions packages/diagram-client/src/diagram-client.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@import './floating-buttons.css';
@import './hierarchy-outline.css';
@import './diagram-find.css';
@import './status-line.css';

:root {
--sprotty-background: var(--vscode-editor-background, #1e1e1e);
Expand Down
103 changes: 103 additions & 0 deletions packages/diagram-client/src/status-line.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* The status line: what the diagram's server says of the diagram (GLSP's
* status overlay, a `StatusAction`). Its own stylesheet, as the loading
* indicator has, so a product with a stylesheet of its own imports it alone:
* `import '@dialogram/diagram-client/status-line.css'`.
* @imported by diagram-client.css, so the stock webview bundle has it.
*/
/* GLSP draws an icon in the top left corner and keeps the words for the
pointer that finds it. What is said here is why a layout was not run, or
that it was run roughly: nobody looks for that under an icon, and in the
top left corner the icon lies under other controls. So a status that has
words is a line at the bottom left of the canvas, over the crumbs (one row
of them, at the same left edge), in the look of the loading pill.

Only a warning or an error is a line. GLSP says its own progress in the
same place ("Model loading in progress", "Validate Model..."), which the
loading indicator already tells better: those are not drawn at all. */
.sprotty-status {
position: fixed;
top: auto;
right: auto;
left: 12px;
bottom: calc(var(--workflow-wf-nav-height, 0px) + 44px);
z-index: 1001;
display: flex;
align-items: flex-start;
gap: 8px;
box-sizing: border-box;
/* Clear of the buttons at the bottom right, and inside a narrow editor. */
max-width: min(640px, calc(100vw - 120px));
padding: 6px 12px;
border: 1px solid var(--vscode-editorWidget-border, #454545);
border-radius: 4px;
background: var(--vscode-editorWidget-background, #252526);
box-shadow: 0 2px 8px var(--vscode-widget-shadow, rgb(0 0 0 / 35%));
color: var(--vscode-foreground, #cccccc);
font-family: var(--vscode-font-family, sans-serif);
font-size: 12px;
line-height: 1.4;
}

.sprotty-status:has(> .sprotty-status-message:empty),
.sprotty-status:not(:has(> .sprotty-status-message:is(.warning, .error, .fatal))) {
display: none;
}

/* The chat card has the bottom of the canvas, at its middle and as wide as
half of it or more. With the card shown the line is at the top left, under
the row of buttons there and under the bar of a stale graph. */
body:has(.workflow-chat-panel.visible) .sprotty-status {
top: calc(var(--wf-stale-bar-height, 0px) + 52px);
bottom: auto;
}

/* With the property panel open the line starts where the crumbs do, clear of
the panel. */
body.workflow-properties-visible .sprotty-status {
left: calc(var(--workflow-property-panel-width, 0px) + 10px);
max-width: min(640px, calc(100vw - var(--workflow-property-panel-width, 0px) - 120px));
}

/* An open outline panel takes the bottom right, beside its button and up to
half the editor (hierarchy-outline.css). The line keeps to what is left of
it, and wraps. */
body:has(.workflow-hierarchy-outline:not([hidden])) .sprotty-status {
max-width: calc(100vw - 86px - min(380px, 50vw));
}

.sprotty-status .sprotty-status-message {
visibility: visible;
min-width: 0;
padding-left: 0;
/* The words are the reason: they can be selected and copied. */
user-select: text;
overflow-wrap: anywhere;
}

/* The icon keeps the line height of the words it stands beside. */
.sprotty-status > .codicon {
flex: none;
line-height: 1.4;
}

.sprotty-status .fatal,
.sprotty-status .error {
color: var(--vscode-editorError-foreground, #f14c4c);
}

.sprotty-status .warning {
color: var(--vscode-editorWarning-foreground, #cca700);
}

/* The words are read in the text colour: the icon carries the severity. */
.sprotty-status .sprotty-status-message.fatal,
.sprotty-status .sprotty-status-message.error,
.sprotty-status .sprotty-status-message.warning {
color: var(--vscode-foreground, #cccccc);
}

.sprotty-status:has(> .sprotty-status-message.error),
.sprotty-status:has(> .sprotty-status-message.fatal) {
border-color: var(--vscode-inputValidation-errorBorder, var(--vscode-editorError-foreground, #f14c4c));
}
97 changes: 97 additions & 0 deletions packages/diagram-client/test/status-line-css-split.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* The status line's rules live in their own stylesheet, which a product with
* a stylesheet of its own imports alone. diagram-client.css @imports it, so
* the stock bundle keeps every rule, and holds none of them itself.
*
* GLSP hides the words of a status until the pointer is on its icon. A
* status is why a layout was not run: the words of a warning or an error are
* shown, and GLSP's own progress, which the loading indicator tells, is not
* drawn.
*/
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import * as path from 'node:path';
import { describe, it, expect } from 'vitest';

const SRC = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../src');
const read = (file: string) => readFileSync(path.join(SRC, file), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '');

function statusSelectors(css: string): string[] {
return [...css.matchAll(/([^{}]+)\{[^{}]*\}/g)]
.map(match => match[1].trim())
.filter(selector => selector.includes('.sprotty-status'));
}

describe('status-line.css', () => {
it('shows the words of a status without the pointer, and draws nothing for a status without words', () => {
const css = read('status-line.css');
expect(css).toMatch(/\.sprotty-status \.sprotty-status-message\s*\{[^}]*visibility:\s*visible/);
expect(css).toMatch(/\.sprotty-status:has\(> \.sprotty-status-message:empty\),[^{]*\{[^}]*display:\s*none/);
});

it('is a line at the bottom left, over the crumbs and clear of the top left corner the controls of a product take', () => {
const css = read('status-line.css');
const line = /\.sprotty-status\s*\{([^}]*)\}/.exec(css)?.[1] ?? '';
expect(line).toMatch(/position:\s*fixed/);
expect(line).toMatch(/top:\s*auto/);
expect(line).toMatch(/max-width:/);
// The crumbs are at the bottom left too: the line has their left edge, a row higher.
const crumbs = /\.workflow-breadcrumb-overlay\s*\{([^}]*)\}/.exec(read('diagram-client.css'))?.[1] ?? '';
expect(crumbs).toMatch(/left:\s*12px/);
expect(crumbs).toMatch(/bottom:\s*calc\(var\(--workflow-wf-nav-height, 28px\) \+ 16px\)/);
expect(line).toMatch(/left:\s*12px/);
expect(line).toMatch(/bottom:\s*calc\(var\(--workflow-wf-nav-height, 0px\) \+ 44px\)/);
});

it('moves clear of the property panel as the crumbs do', () => {
const css = read('status-line.css');
expect(css).toMatch(
/body\.workflow-properties-visible \.sprotty-status\s*\{[^}]*left:\s*calc\(var\(--workflow-property-panel-width, 0px\) \+ 10px\)/
);
});

it('draws a warning or an error only: GLSP says its own progress in the same place', () => {
const css = read('status-line.css');
expect(css).toMatch(
/\.sprotty-status:not\(:has\(> \.sprotty-status-message:is\(\.warning, \.error, \.fatal\)\)\)\s*\{[^}]*display:\s*none/
);
expect(css).not.toMatch(/\.info\b/);
});

it('goes to the top left, under the buttons and the bar of a stale graph, while the chat card has the bottom', () => {
const css = read('status-line.css');
expect(css).toMatch(
/body:has\(\.workflow-chat-panel\.visible\) \.sprotty-status\s*\{[^}]*top:\s*calc\(var\(--wf-stale-bar-height, 0px\) \+ 52px\);[^}]*bottom:\s*auto/
);
// The class the chat card is shown by, and the height the bar gives the page.
expect(read('chat-panel.css')).toMatch(/\.workflow-chat-panel\.visible\s*\{/);
expect(readFileSync(path.join(SRC, 'graph-status.ts'), 'utf8')).toContain("'--wf-stale-bar-height'");
});

it('is an overlay a fit keeps the drawing clear of', () => {
expect(readFileSync(path.join(SRC, 'canvas-overlays.ts'), 'utf8')).toMatch(/'\.sprotty-status',/);
});

it('keeps to the left of an open outline panel, which has the bottom right', () => {
const css = read('status-line.css');
const outline = read('hierarchy-outline.css');
// The width and the place the line reckons with are the panel's own.
expect(outline).toMatch(/\.workflow-hierarchy-outline\s*\{[^}]*right:\s*60px[^}]*width:\s*min\(380px, 50vw\)/);
expect(css).toMatch(
/body:has\(\.workflow-hierarchy-outline:not\(\[hidden\]\)\) \.sprotty-status\s*\{[^}]*max-width:\s*calc\(100vw - 86px - min\(380px, 50vw\)\)/
);
});

it('takes its colours from the theme alone', () => {
const css = read('status-line.css');
// A literal colour is a fallback inside var(), or the shadow's.
const bare = css.replace(/var\([^()]*(\([^()]*\)[^()]*)*\)/g, '').match(/#[0-9a-f]{3,8}\b/gi) ?? [];
expect(bare).toEqual([]);
});

it('is @imported by diagram-client.css, which keeps no status rule of its own', () => {
const stock = read('diagram-client.css');
expect(stock).toMatch(/@import '\.\/status-line\.css';/);
expect(statusSelectors(stock)).toEqual([]);
});
});
3 changes: 2 additions & 1 deletion packages/diagram-server/resources/elk-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ copying this file into its extension and naming it in its profile
jar's ELK together.
- SHA-256: `230f85d9db016031c0af74e3645dc90224de8a7abe4b4c64da12b90964de7da3`
- Needs: Java 17 or later (class file version 61) on the machine, since ELK
0.10 is built for it. Without it every layout stays on elkjs.
0.10 is built for it. Without it elkjs lays out what it finishes in time,
and a larger graph is not laid out.
- Run: `java -jar elk-server-0.3.0-all.jar --socket`, port from the
`ELK_SERVER_PORT` environment variable. Talk to it only in the framed mode
(`GZ10`, a 4-byte big-endian length, a gzip body, both ways): the plain JSON
Expand Down
2 changes: 1 addition & 1 deletion packages/diagram-server/src/server/elk-layout-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class WorkflowElkLayoutEngine extends GlspElkLayoutEngine {
// status line, since the result looks nothing like a usual layout.
if (tier === 'fast' && this.actionDispatcher) {
const message = `${size.nodes} nodes: laid out roughly. Run Layout for the full layout.`;
void Promise.resolve(this.actionDispatcher.dispatch(StatusAction.create(message, { severity: 'INFO', timeout: 10000 })))
void Promise.resolve(this.actionDispatcher.dispatch(StatusAction.create(message, { severity: 'WARNING', timeout: 10000 })))
.catch(e => console.warn('[cal-elk] layout status not shown:', e));
}
return root;
Expand Down
20 changes: 16 additions & 4 deletions packages/diagram-server/src/server/elk-server/elk-server-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ export async function encodeFrame(json: string): Promise<Buffer> {
return Buffer.concat([header, body]);
}

/**
* A layout the server did not answer within its time. The server is still on
* it: a layout cannot be taken back from it ({@link ElkServerProcess.during}
* ends a server that has nothing else to answer).
*/
export class ElkServerTimeoutError extends Error {
constructor(readonly timeoutMs: number) {
super(`the ELK server took longer than ${timeoutMs} ms`);
this.name = 'ElkServerTimeoutError';
}
}

/**
* Lay `graph` out on the server at `port`, writing the positions, sizes and
* routes back into it (as elkjs would) and resolving with it.
Expand All @@ -54,10 +66,10 @@ export function layoutOnServer(port: number, graph: ElkNode, timeoutMs: number):
resolve(result!);
}
};
const timer = setTimeout(
() => finish(new Error(`the ELK server took longer than ${timeoutMs} ms`)),
timeoutMs
);
// A host kept busy (by an elkjs layout of another diagram, say) runs
// this timer before it reads an answer that arrived meanwhile: the
// answer is read first, and only a server that has none timed out.
const timer = setTimeout(() => setImmediate(() => finish(new ElkServerTimeoutError(timeoutMs))), timeoutMs);

const chunks: Buffer[] = [];
let received = 0;
Expand Down
Loading
Loading