Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | 1x 18x 18x 11x 6x 42x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 18x 18x 1x 17x 1x 1x 16x 18x 4x 4x 12x 18x 18x 6x 1x 1x 11x 11x 11x 11x 11x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 11x 11x 11x | import * as vscode from 'vscode';
import { type Element as XmlElement } from '@xmldom/xmldom';
import { resolveActiveBpmnUri, isBpmnFileName } from './bpmnEditorRouting';
import { parseXmlDocument } from './flowable/xmlParser';
interface BpmnNodeInfo {
id: string;
name: string;
type: string;
children: BpmnNodeInfo[];
}
const ELEMENT_ICONS: Record<string, vscode.ThemeIcon> = {
'process': new vscode.ThemeIcon('symbol-namespace'),
'startEvent': new vscode.ThemeIcon('play'),
'endEvent': new vscode.ThemeIcon('stop'),
'userTask': new vscode.ThemeIcon('person'),
'serviceTask': new vscode.ThemeIcon('gear'),
'scriptTask': new vscode.ThemeIcon('code'),
'sendTask': new vscode.ThemeIcon('mail'),
'receiveTask': new vscode.ThemeIcon('inbox'),
'manualTask': new vscode.ThemeIcon('tools'),
'businessRuleTask': new vscode.ThemeIcon('law'),
'callActivity': new vscode.ThemeIcon('references'),
'subProcess': new vscode.ThemeIcon('symbol-class'),
'transaction': new vscode.ThemeIcon('symbol-class'),
'exclusiveGateway': new vscode.ThemeIcon('git-compare'),
'inclusiveGateway': new vscode.ThemeIcon('git-merge'),
'parallelGateway': new vscode.ThemeIcon('split-horizontal'),
'eventBasedGateway': new vscode.ThemeIcon('git-compare'),
'complexGateway': new vscode.ThemeIcon('git-compare'),
'boundaryEvent': new vscode.ThemeIcon('bell'),
'intermediateCatchEvent': new vscode.ThemeIcon('bell'),
'intermediateThrowEvent': new vscode.ThemeIcon('bell-dot'),
'sequenceFlow': new vscode.ThemeIcon('arrow-right'),
'textAnnotation': new vscode.ThemeIcon('note'),
'participant': new vscode.ThemeIcon('organization'),
'lane': new vscode.ThemeIcon('layout'),
'collaboration': new vscode.ThemeIcon('organization'),
};
function getLocalName(nodeName: string): string {
const colonIdx = nodeName.indexOf(':');
return colonIdx >= 0 ? nodeName.substring(colonIdx + 1) : nodeName;
}
function formatLabel(type: string): string {
return type.replace(/([A-Z])/g, ' $1').trim();
}
function getElementChildren(element: XmlElement): XmlElement[] {
return Array.from(element.childNodes).filter(
(node): node is XmlElement => node.nodeType === 1,
);
}
function parseProcessElements(xml: string): BpmnNodeInfo[] {
const roots: BpmnNodeInfo[] = [];
let document;
try {
document = parseXmlDocument(xml);
} catch {
return roots;
}
const definitions = document.documentElement;
Iif (!definitions) {
return roots;
}
const SKIP_TYPES = new Set([
'definitions', 'extensionElements', 'documentation', 'conditionExpression',
'script', 'multiInstanceLoopCharacteristics', 'timerEventDefinition',
'errorEventDefinition', 'signalEventDefinition', 'messageEventDefinition',
'signal', 'message', 'loopCardinality', 'completionCondition',
'BPMNDiagram', 'BPMNPlane', 'BPMNShape', 'BPMNEdge', 'Bounds', 'waypoint',
'dataObject', 'dataObjectReference', 'dataStoreReference',
'field', 'string', 'expression', 'formProperty',
'taskListener', 'executionListener', 'eventListener',
'in', 'out', 'localization',
]);
const CONTAINER_TYPES = new Set(['process', 'subProcess', 'transaction', 'collaboration', 'lane']);
const FLATTENED_CONTAINER_TYPES = new Set(['laneSet', 'childLaneSet']);
function parseChildren(parent: XmlElement): BpmnNodeInfo[] {
const nodes: BpmnNodeInfo[] = [];
for (const child of getElementChildren(parent)) {
const type = getLocalName(child.nodeName);
if (SKIP_TYPES.has(type)) {
continue;
}
if (FLATTENED_CONTAINER_TYPES.has(type)) {
nodes.push(...parseChildren(child));
continue;
}
const id = child.getAttribute('id') || '';
if (!id) {
Iif (CONTAINER_TYPES.has(type)) {
nodes.push(...parseChildren(child));
}
continue;
}
const name = child.getAttribute('name') || '';
const node: BpmnNodeInfo = {
id,
name: name || id,
type,
children: CONTAINER_TYPES.has(type) ? parseChildren(child) : [],
};
nodes.push(node);
}
return nodes;
}
roots.push(...parseChildren(definitions));
return roots;
}
class BpmnTreeItem extends vscode.TreeItem {
constructor(
public readonly nodeInfo: BpmnNodeInfo,
public readonly hasChildren: boolean,
) {
super(
nodeInfo.name,
hasChildren
? vscode.TreeItemCollapsibleState.Expanded
: vscode.TreeItemCollapsibleState.None,
);
this.description = nodeInfo.id === nodeInfo.name ? undefined : nodeInfo.id;
this.tooltip = `${formatLabel(nodeInfo.type)}: ${nodeInfo.name} (${nodeInfo.id})`;
this.iconPath = ELEMENT_ICONS[nodeInfo.type] || new vscode.ThemeIcon('symbol-misc');
this.contextValue = nodeInfo.type;
}
}
export class ProcessNavigatorProvider implements vscode.TreeDataProvider<BpmnTreeItem> {
private readonly _onDidChangeTreeData = new vscode.EventEmitter<BpmnTreeItem | undefined | null>();
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
private roots: BpmnNodeInfo[] = [];
private readonly nodeMap = new Map<string, BpmnTreeItem>();
refresh(xml?: string): void {
this.nodeMap.clear();
if (xml) {
this.roots = parseProcessElements(xml);
} else E{
this.roots = [];
}
this._onDidChangeTreeData.fire(undefined);
}
getTreeItem(element: BpmnTreeItem): vscode.TreeItem {
return element;
}
getChildren(element?: BpmnTreeItem): BpmnTreeItem[] {
const nodes = element ? element.nodeInfo.children : this.roots;
return nodes.map((node) => {
const item = new BpmnTreeItem(node, node.children.length > 0);
this.nodeMap.set(node.id, item);
return item;
});
}
dispose(): void {
this._onDidChangeTreeData.dispose();
}
}
export function registerProcessNavigator(context: vscode.ExtensionContext): ProcessNavigatorProvider {
const provider = new ProcessNavigatorProvider();
let refreshRequestId = 0;
const treeView = vscode.window.createTreeView('flowable-bpmn-designer.processNavigator', {
treeDataProvider: provider,
});
// Refresh when the active custom editor changes
const refreshFromDocument = () => {
refreshRequestId += 1;
const requestId = refreshRequestId;
const activeUri = resolveActiveBpmnUri();
if (!activeUri) {
provider.refresh();
return;
}
vscode.workspace.openTextDocument(activeUri).then((doc) => {
if (requestId !== refreshRequestId || resolveActiveBpmnUri()?.toString() !== activeUri.toString()) {
return;
}
provider.refresh(doc.getText());
}, () => {
if (requestId !== refreshRequestId) {
return;
}
provider.refresh();
});
};
// Refresh when text document is saved or changed
context.subscriptions.push(
treeView,
vscode.workspace.onDidSaveTextDocument((doc) => {
if ((isBpmnFileName(doc.fileName) || resolveActiveBpmnUri()?.toString() === doc.uri.toString()) && resolveActiveBpmnUri()?.toString() === doc.uri.toString()) {
provider.refresh(doc.getText());
}
}),
vscode.workspace.onDidChangeTextDocument((event) => {
const doc = event.document;
if ((isBpmnFileName(doc.fileName) || resolveActiveBpmnUri()?.toString() === doc.uri.toString()) && resolveActiveBpmnUri()?.toString() === doc.uri.toString()) {
provider.refresh(doc.getText());
}
}),
vscode.window.tabGroups.onDidChangeTabs(() => {
refreshFromDocument();
}),
);
// Initial refresh
refreshFromDocument();
return provider;
}
|