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,501 @@
1
+ /**
2
+ * Java tree-sitter symbol extractor.
3
+ *
4
+ * Tree-sitter grammar: tree-sitter-java (https://github.com/tree-sitter/tree-sitter-java)
5
+ * The official tree-sitter Java grammar, maintained by the tree-sitter core team.
6
+ * Supports modern Java up to Java 21 (records, sealed types, pattern matching,
7
+ * switch expressions, text blocks).
8
+ */
9
+
10
+ import type { Node } from "web-tree-sitter";
11
+ import type { SymbolInfo, ImportInfo } from "../types.js";
12
+
13
+ /**
14
+ * Extract structural symbols from Java source code.
15
+ */
16
+ export function extractJava(
17
+ node: Node,
18
+ source: string,
19
+ depth: number,
20
+ ): SymbolInfo[] {
21
+ const results: SymbolInfo[] = [];
22
+ const MAX_DEPTH = depth + 10;
23
+
24
+ for (let i = 0; i < node.namedChildCount; i++) {
25
+ const child = node.namedChild(i);
26
+ if (!child) continue;
27
+
28
+ const symbol = extractJavaTopLevel(child, source, depth, MAX_DEPTH);
29
+ if (symbol) results.push(symbol);
30
+ }
31
+
32
+ return results;
33
+ }
34
+
35
+ function extractJavaType(
36
+ node: Node,
37
+ source: string,
38
+ depth: number,
39
+ MAX_DEPTH: number,
40
+ ): SymbolInfo | null {
41
+ switch (node.type) {
42
+ case "class_declaration":
43
+ case "interface_declaration":
44
+ case "enum_declaration":
45
+ case "record_declaration":
46
+ case "annotation_type_declaration":
47
+ return extractJavaTypeDeclaration(node, source, depth, MAX_DEPTH);
48
+ default:
49
+ return null;
50
+ }
51
+ }
52
+
53
+ function extractJavaTopLevel(
54
+ child: Node,
55
+ source: string,
56
+ depth: number,
57
+ MAX_DEPTH: number,
58
+ ): SymbolInfo | null {
59
+ return extractJavaType(child, source, depth, MAX_DEPTH);
60
+ }
61
+
62
+ function extractJavaTypeDeclaration(
63
+ child: Node,
64
+ source: string,
65
+ depth: number,
66
+ MAX_DEPTH: number,
67
+ ): SymbolInfo | null {
68
+ let typeName = "<unknown>";
69
+ let typeLabel = "class";
70
+ const modifiers: string[] = [];
71
+ let superClass: string | undefined;
72
+ const interfaces: string[] = [];
73
+ const extendsInterfaces: string[] = [];
74
+
75
+ if (child.type === "interface_declaration") typeLabel = "interface";
76
+ else if (child.type === "enum_declaration") typeLabel = "enum";
77
+ else if (child.type === "record_declaration") typeLabel = "record";
78
+ else if (child.type === "annotation_type_declaration") typeLabel = "annotation";
79
+
80
+ for (let j = 0; j < child.namedChildCount; j++) {
81
+ const c = child.namedChild(j);
82
+ if (!c) continue;
83
+
84
+ if (c.type === "modifiers") {
85
+ for (let k = 0; k < c.namedChildCount; k++) {
86
+ const sub = c.namedChild(k);
87
+ if (sub && sub.type !== "annotation") {
88
+ modifiers.push(source.slice(sub.startIndex, sub.endIndex));
89
+ }
90
+ }
91
+ } else if (c.type === "identifier") {
92
+ typeName = source.slice(c.startIndex, c.endIndex);
93
+ } else if (c.type === "superclass") {
94
+ for (let k = 0; k < c.namedChildCount; k++) {
95
+ const sub = c.namedChild(k);
96
+ if (sub && sub.type !== "extends") {
97
+ superClass = source.slice(sub.startIndex, sub.endIndex);
98
+ }
99
+ }
100
+ } else if (c.type === "super_interfaces") {
101
+ for (let k = 0; k < c.namedChildCount; k++) {
102
+ const sub = c.namedChild(k);
103
+ if (sub && sub.type !== "implements") {
104
+ interfaces.push(source.slice(sub.startIndex, sub.endIndex));
105
+ }
106
+ }
107
+ } else if (c.type === "extends_interfaces") {
108
+ for (let k = 0; k < c.namedChildCount; k++) {
109
+ const sub = c.namedChild(k);
110
+ if (sub && sub.type !== "extends") {
111
+ extendsInterfaces.push(source.slice(sub.startIndex, sub.endIndex));
112
+ }
113
+ }
114
+ }
115
+ }
116
+
117
+ const [sl, el] = [child.startPosition.row + 1, child.endPosition.row + 1];
118
+ const detailParts: string[] = [];
119
+ if (modifiers.length > 0) detailParts.push(modifiers.join(" "));
120
+ if (superClass) detailParts.push("extends " + superClass);
121
+ if (interfaces.length > 0) detailParts.push("implements " + interfaces.join(", "));
122
+ if (extendsInterfaces.length > 0) detailParts.push("extends " + extendsInterfaces.join(", "));
123
+
124
+ const symbol: SymbolInfo = {
125
+ name: typeName,
126
+ type: typeLabel,
127
+ startLine: sl,
128
+ endLine: el,
129
+ detail: detailParts.length > 0 ? detailParts.join(" ") : undefined,
130
+ };
131
+
132
+ if (depth < MAX_DEPTH) {
133
+ const body = findClassBody(child);
134
+ if (body) {
135
+ const children = extractJavaClassBody(body, source, depth + 1, MAX_DEPTH);
136
+ if (children.length > 0) symbol.children = children;
137
+ }
138
+ }
139
+
140
+ return symbol;
141
+ }
142
+
143
+ function findClassBody(node: Node): Node | null {
144
+ for (let i = 0; i < node.namedChildCount; i++) {
145
+ const c = node.namedChild(i);
146
+ if (!c) continue;
147
+ if (
148
+ c.type === "class_body" ||
149
+ c.type === "enum_body" ||
150
+ c.type === "interface_body" ||
151
+ c.type === "annotation_type_body"
152
+ ) {
153
+ return c;
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+
159
+ function extractJavaClassBody(
160
+ body: Node,
161
+ source: string,
162
+ depth: number,
163
+ MAX_DEPTH: number,
164
+ ): SymbolInfo[] {
165
+ const results: SymbolInfo[] = [];
166
+
167
+ for (let i = 0; i < body.namedChildCount; i++) {
168
+ const child = body.namedChild(i);
169
+ if (!child) continue;
170
+
171
+ switch (child.type) {
172
+ case "method_declaration": {
173
+ const method = extractJavaMethod(child, source);
174
+ if (method) results.push(method);
175
+ break;
176
+ }
177
+ case "constructor_declaration": {
178
+ const ctor = extractJavaConstructor(child, source);
179
+ if (ctor) results.push(ctor);
180
+ break;
181
+ }
182
+ case "field_declaration": {
183
+ const fields = extractJavaFields(child, source);
184
+ results.push(...fields);
185
+ break;
186
+ }
187
+ case "class_declaration":
188
+ case "interface_declaration":
189
+ case "enum_declaration":
190
+ case "record_declaration":
191
+ case "annotation_type_declaration": {
192
+ const type = extractJavaTypeDeclaration(child, source, depth, MAX_DEPTH);
193
+ if (type) results.push(type);
194
+ break;
195
+ }
196
+ case "enum_constant": {
197
+ const ec = extractJavaEnumConstant(child, source);
198
+ if (ec) results.push(ec);
199
+ break;
200
+ }
201
+ case "static_initializer": {
202
+ const [sl, el] = [child.startPosition.row + 1, child.endPosition.row + 1];
203
+ results.push({ name: "static", type: "static_initializer", startLine: sl, endLine: el });
204
+ break;
205
+ }
206
+ }
207
+ }
208
+
209
+ return results;
210
+ }
211
+
212
+ function extractModifiers(node: Node, source: string): string[] {
213
+ const mods: string[] = [];
214
+ for (let i = 0; i < node.namedChildCount; i++) {
215
+ const c = node.namedChild(i);
216
+ if (!c) continue;
217
+ if (c.type !== "annotation") {
218
+ mods.push(source.slice(c.startIndex, c.endIndex));
219
+ }
220
+ }
221
+ return mods;
222
+ }
223
+
224
+ function extractJavaMethod(
225
+ child: Node,
226
+ source: string,
227
+ ): SymbolInfo | null {
228
+ let methodName = "<unknown>";
229
+ const modifiers: string[] = [];
230
+ let returnType: string | undefined;
231
+ let params: string | undefined;
232
+ let typeParams: string | undefined;
233
+
234
+ for (let j = 0; j < child.namedChildCount; j++) {
235
+ const c = child.namedChild(j);
236
+ if (!c) continue;
237
+
238
+ if (c.type === "modifiers") {
239
+ for (let k = 0; k < c.namedChildCount; k++) {
240
+ const sub = c.namedChild(k);
241
+ if (sub && sub.type !== "annotation") {
242
+ modifiers.push(source.slice(sub.startIndex, sub.endIndex));
243
+ }
244
+ }
245
+ } else if (c.type === "_method_header") {
246
+ for (let k = 0; k < c.namedChildCount; k++) {
247
+ const sub = c.namedChild(k);
248
+ if (!sub) continue;
249
+
250
+ if (sub.type === "type_parameters") {
251
+ typeParams = source.slice(sub.startIndex, sub.endIndex);
252
+ } else if (sub.type === "_method_declarator") {
253
+ for (let m = 0; m < sub.namedChildCount; m++) {
254
+ const decl = sub.namedChild(m);
255
+ if (!decl) continue;
256
+ if (decl.type === "identifier") {
257
+ methodName = source.slice(decl.startIndex, decl.endIndex);
258
+ } else if (decl.type === "formal_parameters") {
259
+ params = source.slice(decl.startIndex, decl.endIndex);
260
+ }
261
+ }
262
+ } else if (sub.type !== "type_parameters" && sub.type !== "_method_declarator" && sub.type !== "throws") {
263
+ returnType = source.slice(sub.startIndex, sub.endIndex);
264
+ }
265
+ }
266
+ }
267
+ }
268
+
269
+ const [sl, el] = [child.startPosition.row + 1, child.endPosition.row + 1];
270
+ const detailParts: string[] = [];
271
+ if (modifiers.length > 0) detailParts.push(modifiers.join(" "));
272
+ if (typeParams) detailParts.push(typeParams);
273
+ if (returnType) detailParts.push(returnType);
274
+ if (params) detailParts.push(params);
275
+
276
+ return {
277
+ name: methodName,
278
+ type: "method",
279
+ startLine: sl,
280
+ endLine: el,
281
+ detail: detailParts.length > 0 ? detailParts.join(" ") : undefined,
282
+ };
283
+ }
284
+
285
+ function extractJavaConstructor(
286
+ child: Node,
287
+ source: string,
288
+ ): SymbolInfo | null {
289
+ let ctorName = "<unknown>";
290
+ const modifiers: string[] = [];
291
+ let params: string | undefined;
292
+ let typeParams: string | undefined;
293
+
294
+ for (let j = 0; j < child.namedChildCount; j++) {
295
+ const c = child.namedChild(j);
296
+ if (!c) continue;
297
+
298
+ if (c.type === "modifiers") {
299
+ for (let k = 0; k < c.namedChildCount; k++) {
300
+ const sub = c.namedChild(k);
301
+ if (sub && sub.type !== "annotation") {
302
+ modifiers.push(source.slice(sub.startIndex, sub.endIndex));
303
+ }
304
+ }
305
+ } else if (c.type === "_constructor_declarator") {
306
+ for (let k = 0; k < c.namedChildCount; k++) {
307
+ const sub = c.namedChild(k);
308
+ if (!sub) continue;
309
+ if (sub.type === "type_parameters") {
310
+ typeParams = source.slice(sub.startIndex, sub.endIndex);
311
+ } else if (sub.type === "identifier") {
312
+ ctorName = source.slice(sub.startIndex, sub.endIndex);
313
+ } else if (sub.type === "formal_parameters") {
314
+ params = source.slice(sub.startIndex, sub.endIndex);
315
+ }
316
+ }
317
+ }
318
+ }
319
+
320
+ const [sl, el] = [child.startPosition.row + 1, child.endPosition.row + 1];
321
+ const detailParts: string[] = [];
322
+ if (modifiers.length > 0) detailParts.push(modifiers.join(" "));
323
+ if (typeParams) detailParts.push(typeParams);
324
+ if (params) detailParts.push(params);
325
+
326
+ return {
327
+ name: ctorName,
328
+ type: "constructor",
329
+ startLine: sl,
330
+ endLine: el,
331
+ detail: detailParts.length > 0 ? detailParts.join(" ") : undefined,
332
+ };
333
+ }
334
+
335
+ function extractJavaFields(
336
+ child: Node,
337
+ source: string,
338
+ ): SymbolInfo[] {
339
+ const results: SymbolInfo[] = [];
340
+ const modifiers: string[] = [];
341
+ let fieldType: string | undefined;
342
+
343
+ for (let j = 0; j < child.namedChildCount; j++) {
344
+ const c = child.namedChild(j);
345
+ if (!c) continue;
346
+
347
+ if (c.type === "modifiers") {
348
+ for (let k = 0; k < c.namedChildCount; k++) {
349
+ const sub = c.namedChild(k);
350
+ if (sub && sub.type !== "annotation") {
351
+ modifiers.push(source.slice(sub.startIndex, sub.endIndex));
352
+ }
353
+ }
354
+ } else if (c.type === "_unannotated_type" || c.type === "type") {
355
+ fieldType = source.slice(c.startIndex, c.endIndex);
356
+ } else if (c.type === "_variable_declarator_list") {
357
+ for (let k = 0; k < c.namedChildCount; k++) {
358
+ const decl = c.namedChild(k);
359
+ if (!decl) continue;
360
+ if (decl.type === "variable_declarator") {
361
+ const field = extractJavaVariableDeclarator(decl, source, modifiers, fieldType);
362
+ if (field) results.push(field);
363
+ }
364
+ }
365
+ }
366
+ }
367
+
368
+ return results;
369
+ }
370
+
371
+ function extractJavaVariableDeclarator(
372
+ node: Node,
373
+ source: string,
374
+ modifiers: string[],
375
+ fieldType: string | undefined,
376
+ ): SymbolInfo | null {
377
+ let fieldName = "<unknown>";
378
+ let fieldValue: string | undefined;
379
+
380
+ for (let i = 0; i < node.namedChildCount; i++) {
381
+ const c = node.namedChild(i);
382
+ if (!c) continue;
383
+
384
+ if (c.type === "_variable_declarator_id") {
385
+ for (let j = 0; j < c.namedChildCount; j++) {
386
+ const sub = c.namedChild(j);
387
+ if (sub && sub.type === "identifier") {
388
+ fieldName = source.slice(sub.startIndex, sub.endIndex);
389
+ }
390
+ }
391
+ } else if (c.type === "=") {
392
+ for (let j = 0; j < c.namedChildCount; j++) {
393
+ const sub = c.namedChild(j);
394
+ if (sub) {
395
+ fieldValue = source.slice(sub.startIndex, sub.endIndex);
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+ const [sl, el] = [node.startPosition.row + 1, node.endPosition.row + 1];
402
+ const detailParts: string[] = [];
403
+ if (modifiers.length > 0) detailParts.push(modifiers.join(" "));
404
+ if (fieldType) detailParts.push(fieldType);
405
+ if (fieldValue) detailParts.push("= " + fieldValue);
406
+
407
+ return {
408
+ name: fieldName,
409
+ type: "field",
410
+ startLine: sl,
411
+ endLine: el,
412
+ detail: detailParts.length > 0 ? detailParts.join(" ") : undefined,
413
+ };
414
+ }
415
+
416
+ function extractJavaEnumConstant(
417
+ child: Node,
418
+ source: string,
419
+ ): SymbolInfo | null {
420
+ let constName = "<unknown>";
421
+ let constArgs: string | undefined;
422
+
423
+ for (let j = 0; j < child.namedChildCount; j++) {
424
+ const c = child.namedChild(j);
425
+ if (!c) continue;
426
+
427
+ if (c.type === "identifier") {
428
+ constName = source.slice(c.startIndex, c.endIndex);
429
+ } else if (c.type === "argument_list") {
430
+ constArgs = source.slice(c.startIndex, c.endIndex);
431
+ }
432
+ }
433
+
434
+ const [sl, el] = [child.startPosition.row + 1, child.endPosition.row + 1];
435
+ const detailParts: string[] = [];
436
+ if (constArgs) detailParts.push(constArgs);
437
+
438
+ return {
439
+ name: constName,
440
+ type: "enum_constant",
441
+ startLine: sl,
442
+ endLine: el,
443
+ detail: detailParts.length > 0 ? detailParts.join(" ") : undefined,
444
+ };
445
+ }
446
+
447
+ /**
448
+ * Extract Java imports.
449
+ */
450
+ export function extractJavaImports(
451
+ node: Node,
452
+ source: string,
453
+ ): ImportInfo[] {
454
+ const results: ImportInfo[] = [];
455
+
456
+ for (let i = 0; i < node.namedChildCount; i++) {
457
+ const child = node.namedChild(i);
458
+ if (!child) continue;
459
+
460
+ if (child.type === "import_declaration") {
461
+ let importSource = "";
462
+ let isStatic = false;
463
+ let isWildcard = false;
464
+
465
+ for (let j = 0; j < child.namedChildCount; j++) {
466
+ const c = child.namedChild(j);
467
+ if (!c) continue;
468
+
469
+ if (c.type === "static" || source.slice(c.startIndex, c.endIndex) === "static") {
470
+ isStatic = true;
471
+ } else if (c.type === "asterisk") {
472
+ isWildcard = true;
473
+ } else if (c.type === "scoped_identifier" || c.type === "identifier") {
474
+ importSource = source.slice(c.startIndex, c.endIndex);
475
+ }
476
+ }
477
+
478
+ // Build the full import path
479
+ let fullPath = importSource;
480
+ if (isWildcard) {
481
+ fullPath += ".*";
482
+ }
483
+
484
+ // Extract the last segment as the imported name
485
+ const names: string[] = [];
486
+ if (!isWildcard) {
487
+ const parts = importSource.split(".");
488
+ const lastName = parts[parts.length - 1];
489
+ if (lastName) names.push(lastName);
490
+ }
491
+
492
+ results.push({
493
+ source: isStatic ? "static " + fullPath : fullPath,
494
+ names,
495
+ lineNumber: child.startPosition.row + 1,
496
+ });
497
+ }
498
+ }
499
+
500
+ return results;
501
+ }