pi-hashline-edit-pro 6.1.2 → 6.2.0

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.
Files changed (66) hide show
  1. package/README.md +14 -12
  2. package/index.ts +20 -12
  3. package/package.json +3 -2
  4. package/src/auto-read-all.ts +39 -21
  5. package/src/config-ui.ts +135 -55
  6. package/src/config.ts +27 -9
  7. package/src/copy-move.ts +4 -4
  8. package/src/grep.ts +3 -3
  9. package/src/insert.ts +3 -3
  10. package/src/outline/index.ts +45 -0
  11. package/src/outline/parsers.ts +42 -0
  12. package/src/outline/render.ts +166 -0
  13. package/src/outline/vendor/LICENSE +201 -0
  14. package/src/outline/vendor/README.md +17 -0
  15. package/src/outline/vendor/parsers/blade.ts +138 -0
  16. package/src/outline/vendor/parsers/index.ts +75 -0
  17. package/src/outline/vendor/parsers/java.ts +501 -0
  18. package/src/outline/vendor/parsers/manager.ts +1721 -0
  19. package/src/outline/vendor/parsers/php.ts +332 -0
  20. package/src/outline/vendor/parsers/sass.ts +416 -0
  21. package/src/outline/vendor/parsers/scss.ts +566 -0
  22. package/src/outline/vendor/types.ts +82 -0
  23. package/src/outline/vendor/wasm/LICENSES.md +37 -0
  24. package/src/outline/vendor/wasm/tree-sitter-blade.wasm +0 -0
  25. package/src/outline/vendor/wasm/tree-sitter-go.wasm +0 -0
  26. package/src/outline/vendor/wasm/tree-sitter-java.wasm +0 -0
  27. package/src/outline/vendor/wasm/tree-sitter-javascript.wasm +0 -0
  28. package/src/outline/vendor/wasm/tree-sitter-php.wasm +0 -0
  29. package/src/outline/vendor/wasm/tree-sitter-python.wasm +0 -0
  30. package/src/outline/vendor/wasm/tree-sitter-rust.wasm +0 -0
  31. package/src/outline/vendor/wasm/tree-sitter-sass.wasm +0 -0
  32. package/src/outline/vendor/wasm/tree-sitter-scss.wasm +0 -0
  33. package/src/outline/vendor/wasm/tree-sitter-solidity.wasm +0 -0
  34. package/src/outline/vendor/wasm/tree-sitter-tsx.wasm +0 -0
  35. package/src/outline/vendor/wasm/tree-sitter-typescript.wasm +0 -0
  36. package/src/read.ts +108 -36
  37. package/src/replace-match.ts +3 -3
  38. package/src/replace-undo.ts +3 -3
  39. package/src/replace.ts +3 -3
  40. package/tool-prompts/read-guidelines.md +3 -0
  41. package/{prompts → tool-prompts}/read.md +2 -0
  42. package/prompts/read-guidelines.md +0 -1
  43. package/src/auto-read-all-state.ts +0 -27
  44. /package/{prompts → tool-prompts}/copy-guidelines.md +0 -0
  45. /package/{prompts → tool-prompts}/copy-snippet.md +0 -0
  46. /package/{prompts → tool-prompts}/copy.md +0 -0
  47. /package/{prompts → tool-prompts}/grep-guidelines.md +0 -0
  48. /package/{prompts → tool-prompts}/grep-snippet.md +0 -0
  49. /package/{prompts → tool-prompts}/grep.md +0 -0
  50. /package/{prompts → tool-prompts}/insert-guidelines.md +0 -0
  51. /package/{prompts → tool-prompts}/insert-snippet.md +0 -0
  52. /package/{prompts → tool-prompts}/insert.md +0 -0
  53. /package/{prompts → tool-prompts}/move-guidelines.md +0 -0
  54. /package/{prompts → tool-prompts}/move-snippet.md +0 -0
  55. /package/{prompts → tool-prompts}/move.md +0 -0
  56. /package/{prompts → tool-prompts}/read-snippet.md +0 -0
  57. /package/{prompts → tool-prompts}/replace-guidelines.md +0 -0
  58. /package/{prompts → tool-prompts}/replace-match-guidelines.md +0 -0
  59. /package/{prompts → tool-prompts}/replace-match-snippet.md +0 -0
  60. /package/{prompts → tool-prompts}/replace-match.md +0 -0
  61. /package/{prompts → tool-prompts}/replace-snippet.md +0 -0
  62. /package/{prompts → tool-prompts}/replace.md +0 -0
  63. /package/{prompts → tool-prompts}/transfer-guidelines.md +0 -0
  64. /package/{prompts → tool-prompts}/undo-last-change-guidelines.md +0 -0
  65. /package/{prompts → tool-prompts}/undo-last-change-snippet.md +0 -0
  66. /package/{prompts → tool-prompts}/undo-last-change.md +0 -0
@@ -0,0 +1,332 @@
1
+ import type { Node } from "web-tree-sitter";
2
+ import type { SymbolInfo } from "../types.js";
3
+
4
+ const PHP_TYPE_LABELS: Record<string, string> = {
5
+ class_declaration: "class",
6
+ interface_declaration: "interface",
7
+ trait_declaration: "trait",
8
+ enum_declaration: "enum",
9
+ };
10
+
11
+ const MODIFIER_TYPES = new Set([
12
+ "visibility_modifier",
13
+ "static_modifier",
14
+ "abstract_modifier",
15
+ "final_modifier",
16
+ "readonly_modifier",
17
+ ]);
18
+
19
+ function textOf(node: Node, source: string): string {
20
+ return source.slice(node.startIndex, node.endIndex);
21
+ }
22
+
23
+ function rangeOf(node: Node): [number, number] {
24
+ return [node.startPosition.row + 1, node.endPosition.row + 1];
25
+ }
26
+
27
+ function detailOf(parts: Array<string | undefined>): string | undefined {
28
+ const kept = parts.filter((part): part is string => part !== undefined && part.length > 0);
29
+ return kept.length > 0 ? kept.join(" ") : undefined;
30
+ }
31
+
32
+ function modifiersOf(node: Node, source: string): string[] {
33
+ const modifiers: string[] = [];
34
+ for (let i = 0; i < node.namedChildCount; i++) {
35
+ const child = node.namedChild(i);
36
+ if (child && MODIFIER_TYPES.has(child.type)) modifiers.push(textOf(child, source));
37
+ }
38
+ return modifiers;
39
+ }
40
+
41
+ function findChild(node: Node, type: string): Node | undefined {
42
+ for (let i = 0; i < node.namedChildCount; i++) {
43
+ const child = node.namedChild(i);
44
+ if (child !== null && child.type === type) return child;
45
+ }
46
+ return undefined;
47
+ }
48
+
49
+ function nameFieldsOf(node: Node, source: string): string[] {
50
+ const names: string[] = [];
51
+ for (let i = 0; i < node.namedChildCount; i++) {
52
+ const child = node.namedChild(i);
53
+ if (child !== null && child.type === "name") names.push(textOf(child, source));
54
+ }
55
+ return names;
56
+ }
57
+
58
+ function nameOf(node: Node, source: string): string {
59
+ const name = findChild(node, "name");
60
+ return name === undefined ? "<unknown>" : textOf(name, source);
61
+ }
62
+
63
+ function paramsOf(node: Node, source: string): string | undefined {
64
+ const params = node.childForFieldName("parameters");
65
+ return params === null ? undefined : textOf(params, source);
66
+ }
67
+
68
+ function returnOf(node: Node, source: string): string | undefined {
69
+ const returned = node.childForFieldName("return_type");
70
+ return returned === null ? undefined : `: ${textOf(returned, source)}`;
71
+ }
72
+
73
+ function signatureOf(node: Node, source: string): string | undefined {
74
+ const params = paramsOf(node, source);
75
+ const returned = returnOf(node, source);
76
+ if (params === undefined) return returned;
77
+ return returned === undefined ? params : `${params}${returned}`;
78
+ }
79
+
80
+ function extractMethod(node: Node, source: string): SymbolInfo {
81
+ const [startLine, endLine] = rangeOf(node);
82
+ return {
83
+ name: node.childForFieldName("name")?.text ?? "<unknown>",
84
+ type: "method",
85
+ startLine,
86
+ endLine,
87
+ detail: detailOf([...modifiersOf(node, source), signatureOf(node, source)]),
88
+ };
89
+ }
90
+
91
+ function extractFunction(node: Node, source: string): SymbolInfo {
92
+ const [startLine, endLine] = rangeOf(node);
93
+ return {
94
+ name: node.childForFieldName("name")?.text ?? "<unknown>",
95
+ type: "function",
96
+ startLine,
97
+ endLine,
98
+ detail: detailOf([signatureOf(node, source)]),
99
+ };
100
+ }
101
+
102
+ function extractProperties(node: Node, source: string): SymbolInfo[] {
103
+ const modifiers = modifiersOf(node, source);
104
+ const typeNode = node.childForFieldName("type");
105
+ const propertyType = typeNode === null ? undefined : textOf(typeNode, source);
106
+ const results: SymbolInfo[] = [];
107
+ for (let i = 0; i < node.namedChildCount; i++) {
108
+ const element = node.namedChild(i);
109
+ if (element === null || element.type !== "property_element") continue;
110
+ const [startLine, endLine] = rangeOf(element);
111
+ results.push({
112
+ name: element.childForFieldName("name")?.text ?? "<unknown>",
113
+ type: "property",
114
+ startLine,
115
+ endLine,
116
+ detail: detailOf([...modifiers, propertyType]),
117
+ });
118
+ }
119
+ return results;
120
+ }
121
+
122
+ function extractConstants(node: Node, source: string): SymbolInfo[] {
123
+ const modifiers = modifiersOf(node, source);
124
+ const results: SymbolInfo[] = [];
125
+ for (let i = 0; i < node.namedChildCount; i++) {
126
+ const element = node.namedChild(i);
127
+ if (element === null || element.type !== "const_element") continue;
128
+ const value = element.namedChild(element.namedChildCount - 1);
129
+ const [startLine, endLine] = rangeOf(element);
130
+ results.push({
131
+ name: nameOf(element, source),
132
+ type: "const",
133
+ startLine,
134
+ endLine,
135
+ detail: detailOf([...modifiers, value === null ? undefined : `= ${textOf(value, source)}`]),
136
+ });
137
+ }
138
+ return results;
139
+ }
140
+
141
+ function extractEnumCase(node: Node, source: string): SymbolInfo {
142
+ const value = node.childForFieldName("value");
143
+ const [startLine, endLine] = rangeOf(node);
144
+ return {
145
+ name: node.childForFieldName("name")?.text ?? "<unknown>",
146
+ type: "case",
147
+ startLine,
148
+ endLine,
149
+ detail: detailOf([value === null ? undefined : `= ${textOf(value, source)}`]),
150
+ };
151
+ }
152
+
153
+ function extractMembers(body: Node, source: string): SymbolInfo[] {
154
+ const results: SymbolInfo[] = [];
155
+ for (let i = 0; i < body.namedChildCount; i++) {
156
+ const child = body.namedChild(i);
157
+ if (child === null) continue;
158
+ switch (child.type) {
159
+ case "method_declaration":
160
+ results.push(extractMethod(child, source));
161
+ break;
162
+ case "property_declaration":
163
+ results.push(...extractProperties(child, source));
164
+ break;
165
+ case "const_declaration":
166
+ results.push(...extractConstants(child, source));
167
+ break;
168
+ case "enum_case":
169
+ results.push(extractEnumCase(child, source));
170
+ break;
171
+ default:
172
+ break;
173
+ }
174
+ }
175
+ return results;
176
+ }
177
+
178
+ function extractTypeDeclaration(node: Node, source: string, depth: number, maxDepth: number): SymbolInfo {
179
+ const detailParts: string[] = [...modifiersOf(node, source)];
180
+ const base = findChild(node, "base_clause");
181
+ if (base !== undefined) {
182
+ const baseNames = nameFieldsOf(base, source);
183
+ if (node.type === "interface_declaration") {
184
+ if (baseNames.length > 0) detailParts.push(`extends ${baseNames.join(", ")}`);
185
+ } else if (baseNames.length > 0 && baseNames[0] !== undefined) {
186
+ detailParts.push(`extends ${baseNames[0]}`);
187
+ }
188
+ }
189
+ if (node.type === "enum_declaration") {
190
+ const backing = findChild(node, "primitive_type");
191
+ if (backing !== undefined) detailParts.push(`: ${textOf(backing, source)}`);
192
+ }
193
+ const implemented = findChild(node, "class_interface_clause");
194
+ if (implemented !== undefined) {
195
+ const implementedNames = nameFieldsOf(implemented, source);
196
+ if (implementedNames.length > 0) detailParts.push(`implements ${implementedNames.join(", ")}`);
197
+ }
198
+ const [startLine, endLine] = rangeOf(node);
199
+ const symbol: SymbolInfo = {
200
+ name: node.childForFieldName("name")?.text ?? "<unknown>",
201
+ type: PHP_TYPE_LABELS[node.type] ?? "class",
202
+ startLine,
203
+ endLine,
204
+ detail: detailOf(detailParts),
205
+ };
206
+ if (depth < maxDepth) {
207
+ const body = findChild(node, "declaration_list") ?? findChild(node, "enum_declaration_list");
208
+ if (body !== undefined) {
209
+ const children = extractMembers(body, source);
210
+ if (children.length > 0) symbol.children = children;
211
+ }
212
+ }
213
+ return symbol;
214
+ }
215
+
216
+ function extractAssignedFunction(statement: Node, source: string): SymbolInfo | null {
217
+ for (let i = 0; i < statement.namedChildCount; i++) {
218
+ const expression = statement.namedChild(i);
219
+ if (expression === null || expression.type !== "assignment_expression") continue;
220
+ const target = expression.namedChild(0);
221
+ const value = expression.namedChild(expression.namedChildCount - 1);
222
+ if (target === null || value === null) continue;
223
+ if (value.type !== "anonymous_function" && value.type !== "arrow_function") continue;
224
+ const [startLine, endLine] = rangeOf(expression);
225
+ return {
226
+ name: textOf(target, source),
227
+ type: value.type === "arrow_function" ? "arrow_function" : "function",
228
+ startLine,
229
+ endLine,
230
+ detail: detailOf([signatureOf(value, source)]),
231
+ };
232
+ }
233
+ return null;
234
+ }
235
+
236
+ const TEST_CALLEES = new Set(["describe", "test", "it"]);
237
+
238
+ function unquote(text: string): string | undefined {
239
+ const trimmed = text.trim();
240
+ const quoted =
241
+ trimmed.length >= 2 &&
242
+ ((trimmed.startsWith("'") && trimmed.endsWith("'")) || (trimmed.startsWith('"') && trimmed.endsWith('"')));
243
+ return quoted ? trimmed.slice(1, -1) : undefined;
244
+ }
245
+
246
+ function unwrapTestCall(node: Node): Node | undefined {
247
+ if (node.type === "function_call_expression") return node;
248
+ if (node.type === "member_call_expression" || node.type === "nullsafe_member_call_expression") {
249
+ const object = node.childForFieldName("object");
250
+ return object === null ? undefined : unwrapTestCall(object);
251
+ }
252
+ return undefined;
253
+ }
254
+
255
+ function firstStringArgument(args: Node, source: string): string | undefined {
256
+ const argument = args.namedChild(0);
257
+ if (argument === null) return undefined;
258
+ const value = argument.namedChild(0);
259
+ if (value === null || value.type !== "string") return undefined;
260
+ return unquote(textOf(value, source));
261
+ }
262
+
263
+ function testCallSymbol(statement: Node, source: string): SymbolInfo | null {
264
+ const expression = statement.namedChild(0);
265
+ if (expression === null) return null;
266
+ const call = unwrapTestCall(expression);
267
+ if (call === undefined) return null;
268
+ const callee = call.childForFieldName("function");
269
+ const args = call.childForFieldName("arguments");
270
+ if (callee === null || args === null) return null;
271
+ const label = textOf(callee, source);
272
+ if (!TEST_CALLEES.has(label)) return null;
273
+ const name = firstStringArgument(args, source);
274
+ if (name === undefined) return null;
275
+ const [startLine, endLine] = rangeOf(statement);
276
+ const symbol: SymbolInfo = { name, type: label, startLine, endLine };
277
+ const children = extractNestedTestCalls(call, source);
278
+ if (children.length > 0) symbol.children = children;
279
+ return symbol;
280
+ }
281
+
282
+ function extractNestedTestCalls(call: Node, source: string): SymbolInfo[] {
283
+ const results: SymbolInfo[] = [];
284
+ const args = call.childForFieldName("arguments");
285
+ if (args === null) return results;
286
+ for (let i = 0; i < args.namedChildCount; i++) {
287
+ const argument = args.namedChild(i);
288
+ if (argument === null) continue;
289
+ const value = argument.namedChild(0);
290
+ if (value === null || value.type !== "anonymous_function") continue;
291
+ const body = value.childForFieldName("body");
292
+ if (body === null) continue;
293
+ for (let j = 0; j < body.namedChildCount; j++) {
294
+ const statement = body.namedChild(j);
295
+ if (statement === null || statement.type !== "expression_statement") continue;
296
+ const nested = testCallSymbol(statement, source);
297
+ if (nested !== null) results.push(nested);
298
+ }
299
+ }
300
+ return results;
301
+ }
302
+
303
+ export function extractPhp(node: Node, source: string, depth: number): SymbolInfo[] {
304
+ const results: SymbolInfo[] = [];
305
+ const maxDepth = depth + 10;
306
+ for (let i = 0; i < node.namedChildCount; i++) {
307
+ const child = node.namedChild(i);
308
+ if (child === null) continue;
309
+ switch (child.type) {
310
+ case "class_declaration":
311
+ case "interface_declaration":
312
+ case "trait_declaration":
313
+ case "enum_declaration":
314
+ results.push(extractTypeDeclaration(child, source, depth, maxDepth));
315
+ break;
316
+ case "function_definition":
317
+ results.push(extractFunction(child, source));
318
+ break;
319
+ case "const_declaration":
320
+ results.push(...extractConstants(child, source));
321
+ break;
322
+ case "expression_statement": {
323
+ const nested = extractAssignedFunction(child, source) ?? testCallSymbol(child, source);
324
+ if (nested !== null) results.push(nested);
325
+ break;
326
+ }
327
+ default:
328
+ break;
329
+ }
330
+ }
331
+ return results;
332
+ }