umple-lsp-server 0.2.2 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/diagramNavigation.d.ts +25 -0
- package/out/diagramNavigation.js +193 -0
- package/out/diagramNavigation.js.map +1 -0
- package/out/diagramRequests.d.ts +15 -0
- package/out/diagramRequests.js +66 -0
- package/out/diagramRequests.js.map +1 -0
- package/out/formatRules.d.ts +27 -0
- package/out/formatRules.js +114 -0
- package/out/formatRules.js.map +1 -0
- package/out/formatter.d.ts +38 -16
- package/out/formatter.js +336 -52
- package/out/formatter.js.map +1 -1
- package/out/referenceSearch.d.ts +1 -1
- package/out/referenceSearch.js +35 -9
- package/out/referenceSearch.js.map +1 -1
- package/out/resolver.js +26 -2
- package/out/resolver.js.map +1 -1
- package/out/server.js +271 -25
- package/out/server.js.map +1 -1
- package/out/symbolIndex.d.ts +41 -0
- package/out/symbolIndex.js +161 -2
- package/out/symbolIndex.js.map +1 -1
- package/out/treeUtils.js +3 -2
- package/out/treeUtils.js.map +1 -1
- package/package.json +1 -1
- package/tree-sitter-umple.wasm +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagram-specific navigation: resolve click targets from SVG diagram payloads.
|
|
3
|
+
* Owns the AST walking and symbol lookup logic for diagram click-to-select.
|
|
4
|
+
* Depends on SymbolIndex for symbol queries and tree parsing.
|
|
5
|
+
*/
|
|
6
|
+
import { SymbolIndex, SymbolEntry } from "./symbolIndex";
|
|
7
|
+
type LocationRange = {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
endLine: number;
|
|
11
|
+
endColumn: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resolve a state location from a diagram click payload.
|
|
15
|
+
* Uses the symbol index for path-aware state lookup.
|
|
16
|
+
* Scoped to the clicked file.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveStateLocation(si: SymbolIndex, filePath: string, className: string | undefined, stateMachine: string, statePath: string[]): SymbolEntry | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve a transition location from a diagram click payload.
|
|
21
|
+
* Path-aware: navigates class → SM → source state path before searching transitions.
|
|
22
|
+
* Uses tree-sitter tree walk (transitions are not in the symbol index).
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveTransitionLocation(si: SymbolIndex, filePath: string, content: string, className: string | undefined, stateMachine: string, sourcePath: string[], event: string, targetPath: string[], guard?: string): LocationRange | undefined;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Diagram-specific navigation: resolve click targets from SVG diagram payloads.
|
|
4
|
+
* Owns the AST walking and symbol lookup logic for diagram click-to-select.
|
|
5
|
+
* Depends on SymbolIndex for symbol queries and tree parsing.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.resolveStateLocation = resolveStateLocation;
|
|
9
|
+
exports.resolveTransitionLocation = resolveTransitionLocation;
|
|
10
|
+
const path = require("path");
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a state location from a diagram click payload.
|
|
13
|
+
* Uses the symbol index for path-aware state lookup.
|
|
14
|
+
* Scoped to the clicked file.
|
|
15
|
+
*/
|
|
16
|
+
function resolveStateLocation(si, filePath, className, stateMachine, statePath) {
|
|
17
|
+
const smContainer = className
|
|
18
|
+
? `${className}.${stateMachine}`
|
|
19
|
+
: stateMachine;
|
|
20
|
+
const targetName = statePath[statePath.length - 1];
|
|
21
|
+
const preceding = statePath.slice(0, -1);
|
|
22
|
+
const reachableFiles = new Set([path.normalize(filePath)]);
|
|
23
|
+
// Try each candidate container in order (alias-local first, then base fallback)
|
|
24
|
+
const containers = si.getSmContainerCandidates(smContainer);
|
|
25
|
+
for (const container of containers) {
|
|
26
|
+
let symbol;
|
|
27
|
+
if (preceding.length > 0) {
|
|
28
|
+
symbol = si.resolveStateInPath(preceding, targetName, container, reachableFiles);
|
|
29
|
+
}
|
|
30
|
+
if (!symbol) {
|
|
31
|
+
const candidates = si
|
|
32
|
+
.getSymbols({
|
|
33
|
+
name: targetName,
|
|
34
|
+
kind: "state",
|
|
35
|
+
container,
|
|
36
|
+
})
|
|
37
|
+
.filter((s) => reachableFiles.has(path.normalize(s.file)));
|
|
38
|
+
if (preceding.length === 0) {
|
|
39
|
+
symbol = candidates[0];
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const targetPath = [...preceding, targetName];
|
|
43
|
+
symbol = candidates.find((s) => s.statePath &&
|
|
44
|
+
s.statePath.length >= targetPath.length &&
|
|
45
|
+
targetPath.every((seg, i) => s.statePath[s.statePath.length - targetPath.length + i] === seg));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (symbol)
|
|
49
|
+
return symbol;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
// ── Transition AST walking ───────────────────────────────────────────────────
|
|
54
|
+
/**
|
|
55
|
+
* Find a named child node of specific types within a parent node.
|
|
56
|
+
* Recurses into class_definition and source_file nodes.
|
|
57
|
+
*/
|
|
58
|
+
function findNamedChild(parent, types, name) {
|
|
59
|
+
for (let i = 0; i < parent.childCount; i++) {
|
|
60
|
+
const child = parent.child(i);
|
|
61
|
+
if (types.includes(child.type)) {
|
|
62
|
+
const nameNode = child.childForFieldName("name");
|
|
63
|
+
if (nameNode && nameNode.text === name)
|
|
64
|
+
return child;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (let i = 0; i < parent.childCount; i++) {
|
|
68
|
+
const child = parent.child(i);
|
|
69
|
+
if (child.type === "class_definition" || child.type === "source_file" || child.type === "statemachine_definition") {
|
|
70
|
+
const found = findNamedChild(child, types, name);
|
|
71
|
+
if (found)
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/** SM node types: inline, reused, and standalone definitions. */
|
|
78
|
+
const SM_NODE_TYPES = ["state_machine", "referenced_statemachine", "statemachine_definition"];
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a transition location from a diagram click payload.
|
|
81
|
+
* Path-aware: navigates class → SM → source state path before searching transitions.
|
|
82
|
+
* Uses tree-sitter tree walk (transitions are not in the symbol index).
|
|
83
|
+
*/
|
|
84
|
+
function resolveTransitionLocation(si, filePath, content, className, stateMachine, sourcePath, event, targetPath, guard) {
|
|
85
|
+
const tree = si.parse(content);
|
|
86
|
+
if (!tree)
|
|
87
|
+
return undefined;
|
|
88
|
+
const targetName = targetPath.join(".");
|
|
89
|
+
// Step 1: Find the class node (if className provided)
|
|
90
|
+
let classScope = tree.rootNode;
|
|
91
|
+
if (className) {
|
|
92
|
+
const classNode = findNamedChild(classScope, ["class_definition"], className);
|
|
93
|
+
if (!classNode)
|
|
94
|
+
return undefined;
|
|
95
|
+
classScope = classNode;
|
|
96
|
+
}
|
|
97
|
+
// Step 2: Find the state machine node (state_machine or referenced_statemachine)
|
|
98
|
+
const smNode = findNamedChild(classScope, SM_NODE_TYPES, stateMachine);
|
|
99
|
+
if (!smNode)
|
|
100
|
+
return undefined;
|
|
101
|
+
// Try to find the transition in the alias SM first, then fall back to base
|
|
102
|
+
const result = findTransitionInSm(smNode, sourcePath, event, targetName, guard);
|
|
103
|
+
if (result)
|
|
104
|
+
return result;
|
|
105
|
+
// Fallback: if this is a referenced_statemachine, try the base standalone SM
|
|
106
|
+
if (smNode.type === "referenced_statemachine") {
|
|
107
|
+
const baseName = smNode.childForFieldName("definition")?.text;
|
|
108
|
+
if (baseName) {
|
|
109
|
+
// Search at file root for standalone statemachine_definition
|
|
110
|
+
const baseSmNode = findNamedChild(tree.rootNode, ["statemachine_definition"], baseName);
|
|
111
|
+
if (baseSmNode) {
|
|
112
|
+
return findTransitionInSm(baseSmNode, sourcePath, event, targetName, guard);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Walk the source state path within an SM node and find a matching transition.
|
|
120
|
+
*/
|
|
121
|
+
function findTransitionInSm(smNode, sourcePath, event, targetName, guard) {
|
|
122
|
+
// First: check standalone_transition children at SM scope.
|
|
123
|
+
// These live directly under the SM node (not inside a state body) and encode
|
|
124
|
+
// source state as from_state field: "event fromState -> toState;"
|
|
125
|
+
const fromState = sourcePath.length > 0 ? sourcePath[sourcePath.length - 1] : undefined;
|
|
126
|
+
for (let i = 0; i < smNode.childCount; i++) {
|
|
127
|
+
const child = smNode.child(i);
|
|
128
|
+
if (child.type === "standalone_transition") {
|
|
129
|
+
const eventNode = child.childForFieldName("event");
|
|
130
|
+
const fromNode = child.childForFieldName("from_state");
|
|
131
|
+
const toNode = child.childForFieldName("to_state");
|
|
132
|
+
const eventMatch = eventNode ? eventNode.text === event : !event;
|
|
133
|
+
const fromMatch = fromNode ? fromNode.text === fromState : !fromState;
|
|
134
|
+
const targetMatch = toNode ? toNode.text === targetName : !targetName;
|
|
135
|
+
if (eventMatch && fromMatch && targetMatch) {
|
|
136
|
+
return {
|
|
137
|
+
line: child.startPosition.row,
|
|
138
|
+
column: child.startPosition.column,
|
|
139
|
+
endLine: child.endPosition.row,
|
|
140
|
+
endColumn: child.endPosition.column,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Then: walk down the source state path for regular nested transitions
|
|
146
|
+
let scope = smNode;
|
|
147
|
+
for (const seg of sourcePath) {
|
|
148
|
+
const stateNode = findNamedChild(scope, ["state"], seg);
|
|
149
|
+
if (!stateNode)
|
|
150
|
+
return undefined;
|
|
151
|
+
scope = stateNode;
|
|
152
|
+
}
|
|
153
|
+
// Find the matching transition (regular or standalone within state)
|
|
154
|
+
for (let i = 0; i < scope.childCount; i++) {
|
|
155
|
+
const child = scope.child(i);
|
|
156
|
+
if (child.type === "transition") {
|
|
157
|
+
const eventNode = child.childForFieldName("event");
|
|
158
|
+
const targetNode = child.childForFieldName("target");
|
|
159
|
+
const eventMatch = eventNode ? eventNode.text === event : !event;
|
|
160
|
+
const targetMatch = targetNode ? targetNode.text === targetName : !targetName;
|
|
161
|
+
let guardMatch = true;
|
|
162
|
+
if (guard) {
|
|
163
|
+
const guardNode = child.children.find((c) => c.type === "guard");
|
|
164
|
+
guardMatch = guardNode ? guardNode.text.includes(guard) : false;
|
|
165
|
+
}
|
|
166
|
+
if (eventMatch && targetMatch && guardMatch) {
|
|
167
|
+
return {
|
|
168
|
+
line: child.startPosition.row,
|
|
169
|
+
column: child.startPosition.column,
|
|
170
|
+
endLine: child.endPosition.row,
|
|
171
|
+
endColumn: child.endPosition.column,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// standalone_transition: "event fromState -> toState;"
|
|
176
|
+
if (child.type === "standalone_transition") {
|
|
177
|
+
const eventNode = child.childForFieldName("event");
|
|
178
|
+
const toNode = child.childForFieldName("to_state");
|
|
179
|
+
const eventMatch = eventNode ? eventNode.text === event : !event;
|
|
180
|
+
const targetMatch = toNode ? toNode.text === targetName : !targetName;
|
|
181
|
+
if (eventMatch && targetMatch) {
|
|
182
|
+
return {
|
|
183
|
+
line: child.startPosition.row,
|
|
184
|
+
column: child.startPosition.column,
|
|
185
|
+
endLine: child.endPosition.row,
|
|
186
|
+
endColumn: child.endPosition.column,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=diagramNavigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagramNavigation.js","sourceRoot":"","sources":["../src/diagramNavigation.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAiBH,oDAqDC;AAkCD,8DAiDC;AAvJD,6BAA6B;AAU7B;;;;GAIG;AACH,SAAgB,oBAA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AAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACjE,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;YACtE,IAAI,UAAU,IAAI,WAAW,EAAE,CAAC;gBAC9B,OAAO;oBACL,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG;oBAC7B,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM;oBAClC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG;oBAC9B,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM;iBACpC,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom LSP request handlers for diagram click-to-select.
|
|
3
|
+
* Registers umple/resolveStateLocation and umple/resolveTransitionLocation.
|
|
4
|
+
*/
|
|
5
|
+
import { Connection } from "vscode-languageserver/node";
|
|
6
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
7
|
+
import { SymbolIndex } from "./symbolIndex";
|
|
8
|
+
type DiagramDeps = {
|
|
9
|
+
symbolIndex: SymbolIndex;
|
|
10
|
+
isSymbolIndexReady: () => boolean;
|
|
11
|
+
getDocument: (uri: string) => TextDocument | undefined;
|
|
12
|
+
getDocumentFilePath: (doc: TextDocument) => string | null;
|
|
13
|
+
};
|
|
14
|
+
export declare function registerDiagramRequests(connection: Connection, deps: DiagramDeps): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom LSP request handlers for diagram click-to-select.
|
|
4
|
+
* Registers umple/resolveStateLocation and umple/resolveTransitionLocation.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.registerDiagramRequests = registerDiagramRequests;
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const url_1 = require("url");
|
|
10
|
+
const diagramNavigation_1 = require("./diagramNavigation");
|
|
11
|
+
function registerDiagramRequests(connection, deps) {
|
|
12
|
+
// Resolve a state location from a diagram click payload
|
|
13
|
+
connection.onRequest("umple/resolveStateLocation", async (params) => {
|
|
14
|
+
if (!deps.isSymbolIndexReady() || !params.statePath.length)
|
|
15
|
+
return null;
|
|
16
|
+
const filePath = deps.getDocumentFilePath({
|
|
17
|
+
uri: params.uri,
|
|
18
|
+
});
|
|
19
|
+
if (!filePath)
|
|
20
|
+
return null;
|
|
21
|
+
// Ensure the file is indexed
|
|
22
|
+
const doc = deps.getDocument(params.uri);
|
|
23
|
+
if (doc) {
|
|
24
|
+
deps.symbolIndex.indexFile(filePath, doc.getText());
|
|
25
|
+
}
|
|
26
|
+
const symbol = (0, diagramNavigation_1.resolveStateLocation)(deps.symbolIndex, filePath, params.className, params.stateMachine, params.statePath);
|
|
27
|
+
if (!symbol)
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
uri: (0, url_1.pathToFileURL)(symbol.file).toString(),
|
|
31
|
+
range: {
|
|
32
|
+
start: { line: symbol.line, character: symbol.column },
|
|
33
|
+
end: { line: symbol.endLine, character: symbol.endColumn },
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
// Resolve a transition location from a diagram click payload
|
|
38
|
+
connection.onRequest("umple/resolveTransitionLocation", async (params) => {
|
|
39
|
+
if (!deps.isSymbolIndexReady() || !params.event)
|
|
40
|
+
return null;
|
|
41
|
+
const filePath = deps.getDocumentFilePath({
|
|
42
|
+
uri: params.uri,
|
|
43
|
+
});
|
|
44
|
+
if (!filePath)
|
|
45
|
+
return null;
|
|
46
|
+
const doc = deps.getDocument(params.uri);
|
|
47
|
+
const content = doc
|
|
48
|
+
? doc.getText()
|
|
49
|
+
: fs.existsSync(filePath)
|
|
50
|
+
? fs.readFileSync(filePath, "utf8")
|
|
51
|
+
: null;
|
|
52
|
+
if (!content)
|
|
53
|
+
return null;
|
|
54
|
+
const result = (0, diagramNavigation_1.resolveTransitionLocation)(deps.symbolIndex, filePath, content, params.className, params.stateMachine, params.sourcePath, params.event, params.targetPath, params.guard);
|
|
55
|
+
if (!result)
|
|
56
|
+
return null;
|
|
57
|
+
return {
|
|
58
|
+
uri: (0, url_1.pathToFileURL)(filePath).toString(),
|
|
59
|
+
range: {
|
|
60
|
+
start: { line: result.line, character: result.column },
|
|
61
|
+
end: { line: result.endLine, character: result.endColumn },
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=diagramRequests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagramRequests.js","sourceRoot":"","sources":["../src/diagramRequests.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiBH,0DAgGC;AA/GD,yBAAyB;AAEzB,6BAAoC;AAIpC,2DAAsF;AAStF,SAAgB,uBAAuB,CACrC,UAAsB,EACtB,IAAiB;IAEjB,wDAAwD;IACxD,UAAU,CAAC,SAAS,CAClB,4BAA4B,EAC5B,KAAK,EAAE,MAKN,EAAiD,EAAE;QAClD,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAExE,MAAM,QAAQ,GAAG,IAAI,CAAC,mBAAmB,CAAC;YACxC,GAAG,EAAE,MAAM,CAAC,GAAG;SACA,CAAC,CAAC;QACnB,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAE3B,6BAA6B;QAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,EAA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AC,CAAC,IAAI,CAAC;QACX,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAE1B,MAAM,MAAM,GAAG,IAAA,6CAAyB,EACtC,IAAI,CAAC,WAAW,EAChB,QAAQ,EACR,OAAO,EACP,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,KAAK,CACb,CAAC;QAEF,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAEzB,OAAO;YACL,GAAG,EAAE,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;YACvC,KAAK,EAAE;gBACL,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;gBACtD,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE;aAC3D;SACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatting rule definitions for the syntax-aware formatter.
|
|
3
|
+
*
|
|
4
|
+
* Node-type classification for indentation and skip regions.
|
|
5
|
+
* All node names are verified against the actual tree-sitter grammar.
|
|
6
|
+
*/
|
|
7
|
+
declare const TreeSitter: any;
|
|
8
|
+
type Tree = InstanceType<typeof TreeSitter.Tree>;
|
|
9
|
+
/** Node types whose body content gets +1 indent level. */
|
|
10
|
+
export declare const INDENT_NODES: Set<string>;
|
|
11
|
+
/** Top-level declaration node types that should be separated by blank lines. */
|
|
12
|
+
export declare const TOP_LEVEL_DECL_NODES: Set<string>;
|
|
13
|
+
/** Node types whose content is verbatim (embedded code — do not reindent). */
|
|
14
|
+
export declare const SKIP_NODES: Set<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a line falls strictly inside a verbatim/skip node.
|
|
17
|
+
* Boundary lines (the line with opening `{` and closing `}`) are NOT skipped —
|
|
18
|
+
* they're Umple-structural and should be formatted normally.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isVerbatimLine(tree: Tree, line: number): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Compute the structural indent depth for a line from its AST ancestors.
|
|
23
|
+
* Only counts indent-contributing ancestors whose body starts ABOVE this line
|
|
24
|
+
* (so the opening line of `class A {` doesn't get +1 from its own node).
|
|
25
|
+
*/
|
|
26
|
+
export declare function computeStructuralDepth(tree: Tree, line: number, column: number): number;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Formatting rule definitions for the syntax-aware formatter.
|
|
4
|
+
*
|
|
5
|
+
* Node-type classification for indentation and skip regions.
|
|
6
|
+
* All node names are verified against the actual tree-sitter grammar.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SKIP_NODES = exports.TOP_LEVEL_DECL_NODES = exports.INDENT_NODES = void 0;
|
|
10
|
+
exports.isVerbatimLine = isVerbatimLine;
|
|
11
|
+
exports.computeStructuralDepth = computeStructuralDepth;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
13
|
+
const TreeSitter = require("web-tree-sitter");
|
|
14
|
+
/** Node types whose body content gets +1 indent level. */
|
|
15
|
+
exports.INDENT_NODES = new Set([
|
|
16
|
+
"class_definition",
|
|
17
|
+
"interface_definition",
|
|
18
|
+
"trait_definition",
|
|
19
|
+
"association_class_definition",
|
|
20
|
+
"enum_definition",
|
|
21
|
+
"association_definition",
|
|
22
|
+
"mixset_definition",
|
|
23
|
+
"state_machine",
|
|
24
|
+
"statemachine_definition",
|
|
25
|
+
"state",
|
|
26
|
+
"before_after",
|
|
27
|
+
"toplevel_code_injection",
|
|
28
|
+
"filter_definition",
|
|
29
|
+
"method_declaration",
|
|
30
|
+
]);
|
|
31
|
+
/** Top-level declaration node types that should be separated by blank lines. */
|
|
32
|
+
exports.TOP_LEVEL_DECL_NODES = new Set([
|
|
33
|
+
"class_definition",
|
|
34
|
+
"interface_definition",
|
|
35
|
+
"trait_definition",
|
|
36
|
+
"association_class_definition",
|
|
37
|
+
"enum_definition",
|
|
38
|
+
"association_definition",
|
|
39
|
+
"statemachine_definition",
|
|
40
|
+
"mixset_definition",
|
|
41
|
+
"toplevel_code_injection",
|
|
42
|
+
"namespace_declaration",
|
|
43
|
+
"use_statement",
|
|
44
|
+
"generate_statement",
|
|
45
|
+
"requirement_definition",
|
|
46
|
+
"external_definition",
|
|
47
|
+
]);
|
|
48
|
+
/** Node types whose content is verbatim (embedded code — do not reindent). */
|
|
49
|
+
exports.SKIP_NODES = new Set([
|
|
50
|
+
"code_content",
|
|
51
|
+
"template_body",
|
|
52
|
+
]);
|
|
53
|
+
/**
|
|
54
|
+
* Check if a line falls strictly inside a verbatim/skip node.
|
|
55
|
+
* Boundary lines (the line with opening `{` and closing `}`) are NOT skipped —
|
|
56
|
+
* they're Umple-structural and should be formatted normally.
|
|
57
|
+
*/
|
|
58
|
+
function isVerbatimLine(tree, line) {
|
|
59
|
+
// Walk the tree to find skip nodes that contain this line
|
|
60
|
+
const cursor = tree.rootNode.walk();
|
|
61
|
+
let reachedEnd = false;
|
|
62
|
+
while (!reachedEnd) {
|
|
63
|
+
const node = cursor.currentNode;
|
|
64
|
+
if (exports.SKIP_NODES.has(node.type)) {
|
|
65
|
+
// Strictly between start and end rows (boundary lines are formatted)
|
|
66
|
+
if (node.startPosition.row < line && line < node.endPosition.row) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
// Don't descend into skip nodes
|
|
70
|
+
if (!cursor.gotoNextSibling()) {
|
|
71
|
+
while (!cursor.gotoNextSibling()) {
|
|
72
|
+
if (!cursor.gotoParent()) {
|
|
73
|
+
reachedEnd = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (!cursor.gotoFirstChild()) {
|
|
80
|
+
if (!cursor.gotoNextSibling()) {
|
|
81
|
+
while (!cursor.gotoNextSibling()) {
|
|
82
|
+
if (!cursor.gotoParent()) {
|
|
83
|
+
reachedEnd = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Compute the structural indent depth for a line from its AST ancestors.
|
|
94
|
+
* Only counts indent-contributing ancestors whose body starts ABOVE this line
|
|
95
|
+
* (so the opening line of `class A {` doesn't get +1 from its own node).
|
|
96
|
+
*/
|
|
97
|
+
function computeStructuralDepth(tree, line, column) {
|
|
98
|
+
const node = tree.rootNode.descendantForPosition({ row: line, column });
|
|
99
|
+
if (!node)
|
|
100
|
+
return 0;
|
|
101
|
+
let depth = 0;
|
|
102
|
+
let current = node;
|
|
103
|
+
while (current) {
|
|
104
|
+
if (exports.INDENT_NODES.has(current.type)) {
|
|
105
|
+
// Only count if this line is INSIDE the body (not the header line)
|
|
106
|
+
if (current.startPosition.row < line) {
|
|
107
|
+
depth++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
current = current.parent;
|
|
111
|
+
}
|
|
112
|
+
return depth;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=formatRules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatRules.js","sourceRoot":"","sources":["../src/formatRules.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAsDH,wCAkCC;AAOD,wDAkBC;AA/GD,iEAAiE;AACjE,MAAM,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAI9C,0DAA0D;AAC7C,QAAA,YAAY,GAAG,IAAI,GAAG,CAAC;IAClC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
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Uses tree-sitter AST to compute structural indentation instead of
|
|
5
|
+
* naive brace counting. Preserves embedded code regions (code_content,
|
|
6
|
+
* template_body) as verbatim islands.
|
|
6
7
|
*/
|
|
7
8
|
import { TextEdit } from "vscode-languageserver/node";
|
|
9
|
+
declare const TreeSitter: any;
|
|
10
|
+
type Tree = InstanceType<typeof TreeSitter.Tree>;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param tree Pre-parsed tree (caller handles tree acquisition)
|
|
12
|
+
* Expand eligible single-line compact state blocks into multi-line format.
|
|
13
|
+
* Returns the modified text (or the original if nothing changed).
|
|
13
14
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
startLine: number;
|
|
16
|
-
endLine: number;
|
|
17
|
-
}[];
|
|
15
|
+
export declare function expandCompactStates(text: string, tree: Tree): string;
|
|
18
16
|
/**
|
|
19
|
-
* Compute indent edits for an Umple document.
|
|
17
|
+
* Compute indent edits for an Umple document using syntax-aware indentation.
|
|
20
18
|
*
|
|
21
|
-
* @param text
|
|
19
|
+
* @param text Document text
|
|
22
20
|
* @param options Formatting options (tabSize, insertSpaces)
|
|
23
|
-
* @param
|
|
21
|
+
* @param tree Pre-parsed tree-sitter tree
|
|
22
|
+
* @returns Array of TextEdits to apply for correct indentation
|
|
24
23
|
*/
|
|
25
24
|
export declare function computeIndentEdits(text: string, options: {
|
|
26
25
|
tabSize: number;
|
|
27
26
|
insertSpaces: boolean;
|
|
28
|
-
},
|
|
27
|
+
}, tree: Tree): TextEdit[];
|
|
28
|
+
/**
|
|
29
|
+
* Normalize whitespace around `->` in transition and standalone_transition nodes.
|
|
30
|
+
* Only handles single-line nodes. Leaves event, guard, action, and target text verbatim.
|
|
31
|
+
*/
|
|
32
|
+
export declare function fixTransitionSpacing(text: string, tree: Tree): TextEdit[];
|
|
33
|
+
/**
|
|
34
|
+
* Normalize whitespace around the arrow in association_inline and association_member nodes.
|
|
35
|
+
* Only handles single-line nodes. Same child-walking approach as fixTransitionSpacing.
|
|
36
|
+
*/
|
|
37
|
+
export declare function fixAssociationSpacing(text: string, tree: Tree): TextEdit[];
|
|
38
|
+
/**
|
|
39
|
+
* Normalize blank lines between top-level declarations in source_file.
|
|
40
|
+
* Ensures exactly 1 blank line between consecutive top-level named children.
|
|
41
|
+
* Does NOT touch interior body spacing.
|
|
42
|
+
*/
|
|
43
|
+
export declare function normalizeTopLevelBlankLines(text: string, tree: Tree): TextEdit[];
|
|
44
|
+
/**
|
|
45
|
+
* Collect line ranges of code_content and template_body nodes.
|
|
46
|
+
* Kept for backward compatibility with existing callers; the new
|
|
47
|
+
* formatter uses isVerbatimLine() from formatRules instead.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getCodeContentRanges(tree: any): {
|
|
29
50
|
startLine: number;
|
|
30
51
|
endLine: number;
|
|
31
|
-
}[]
|
|
52
|
+
}[];
|
|
53
|
+
export {};
|