@openrewrite/rewrite 8.92.16 → 8.92.17

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 (79) hide show
  1. package/dist/javascript/comparator.d.ts.map +1 -1
  2. package/dist/javascript/comparator.js +4 -0
  3. package/dist/javascript/comparator.js.map +1 -1
  4. package/dist/javascript/format/tabs-and-indents-visitor.d.ts.map +1 -1
  5. package/dist/javascript/format/tabs-and-indents-visitor.js +31 -4
  6. package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
  7. package/dist/javascript/markers.d.ts +12 -0
  8. package/dist/javascript/markers.d.ts.map +1 -1
  9. package/dist/javascript/markers.js +17 -2
  10. package/dist/javascript/markers.js.map +1 -1
  11. package/dist/javascript/node-resolution-result.js +3 -2
  12. package/dist/javascript/node-resolution-result.js.map +1 -1
  13. package/dist/javascript/parser.d.ts +9 -0
  14. package/dist/javascript/parser.d.ts.map +1 -1
  15. package/dist/javascript/parser.js +185 -88
  16. package/dist/javascript/parser.js.map +1 -1
  17. package/dist/javascript/print.d.ts +10 -1
  18. package/dist/javascript/print.d.ts.map +1 -1
  19. package/dist/javascript/print.js +120 -77
  20. package/dist/javascript/print.js.map +1 -1
  21. package/dist/javascript/templating/engine.d.ts.map +1 -1
  22. package/dist/javascript/templating/engine.js +8 -3
  23. package/dist/javascript/templating/engine.js.map +1 -1
  24. package/dist/javascript/type-mapping.d.ts +1 -0
  25. package/dist/javascript/type-mapping.d.ts.map +1 -1
  26. package/dist/javascript/type-mapping.js +18 -3
  27. package/dist/javascript/type-mapping.js.map +1 -1
  28. package/dist/print.d.ts +6 -1
  29. package/dist/print.d.ts.map +1 -1
  30. package/dist/print.js +21 -7
  31. package/dist/print.js.map +1 -1
  32. package/dist/rewrite-javascript-version.txt +1 -1
  33. package/dist/rpc/java-rpc-client.d.ts +2 -0
  34. package/dist/rpc/java-rpc-client.d.ts.map +1 -1
  35. package/dist/rpc/java-rpc-client.js +1 -0
  36. package/dist/rpc/java-rpc-client.js.map +1 -1
  37. package/dist/rpc/queue.d.ts +8 -0
  38. package/dist/rpc/queue.d.ts.map +1 -1
  39. package/dist/rpc/queue.js +45 -3
  40. package/dist/rpc/queue.js.map +1 -1
  41. package/dist/rpc/request/get-object.d.ts +4 -0
  42. package/dist/rpc/request/get-object.d.ts.map +1 -1
  43. package/dist/rpc/request/get-object.js +23 -1
  44. package/dist/rpc/request/get-object.js.map +1 -1
  45. package/dist/rpc/request/parse.d.ts.map +1 -1
  46. package/dist/rpc/request/parse.js +3 -1
  47. package/dist/rpc/request/parse.js.map +1 -1
  48. package/dist/rpc/request/print.d.ts +8 -2
  49. package/dist/rpc/request/print.d.ts.map +1 -1
  50. package/dist/rpc/request/print.js +12 -9
  51. package/dist/rpc/request/print.js.map +1 -1
  52. package/dist/rpc/rewrite-rpc.d.ts +3 -2
  53. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  54. package/dist/rpc/rewrite-rpc.js +9 -3
  55. package/dist/rpc/rewrite-rpc.js.map +1 -1
  56. package/dist/rpc/server.d.ts.map +1 -1
  57. package/dist/rpc/server.js +19 -5
  58. package/dist/rpc/server.js.map +1 -1
  59. package/dist/test/java-rpc.d.ts.map +1 -1
  60. package/dist/test/java-rpc.js +3 -0
  61. package/dist/test/java-rpc.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/javascript/comparator.ts +10 -0
  64. package/src/javascript/format/tabs-and-indents-visitor.ts +30 -3
  65. package/src/javascript/markers.ts +34 -4
  66. package/src/javascript/node-resolution-result.ts +3 -2
  67. package/src/javascript/parser.ts +200 -91
  68. package/src/javascript/print.ts +123 -76
  69. package/src/javascript/templating/engine.ts +7 -2
  70. package/src/javascript/type-mapping.ts +19 -3
  71. package/src/print.ts +23 -8
  72. package/src/rpc/java-rpc-client.ts +3 -0
  73. package/src/rpc/queue.ts +37 -3
  74. package/src/rpc/request/get-object.ts +24 -0
  75. package/src/rpc/request/parse.ts +4 -1
  76. package/src/rpc/request/print.ts +12 -8
  77. package/src/rpc/rewrite-rpc.ts +16 -5
  78. package/src/rpc/server.ts +18 -6
  79. package/src/test/java-rpc.ts +3 -0
@@ -18,6 +18,11 @@ import {RpcObjectData, RpcObjectState, RpcSendQueue} from "../queue";
18
18
  import {ReferenceMap} from "../../reference";
19
19
  import {extractSourcePath, withMetrics} from "./metrics";
20
20
 
21
+ export class AbortGetObject {
22
+ constructor(readonly id: string) {
23
+ }
24
+ }
25
+
21
26
  export class GetObject {
22
27
  constructor(private readonly id: string,
23
28
  private readonly sourceFileType?: string) {
@@ -33,6 +38,24 @@ export class GetObject {
33
38
  metricsCsv?: string,
34
39
  ): void {
35
40
  const pendingData = new Map<string, { data: (RpcObjectData | undefined)[], offset: number }>();
41
+ let latestTransfer: { id: string, refCount: number } | undefined;
42
+
43
+ // The receiver could not read a transfer to its end and has dropped what it took from it.
44
+ connection.onRequest(
45
+ new rpc.RequestType<AbortGetObject, boolean, Error>("AbortGetObject"),
46
+ request => {
47
+ pendingData.delete(request.id);
48
+ remoteObjects.delete(request.id);
49
+ if (latestTransfer?.id === request.id) {
50
+ localRefs.rollbackTo(latestTransfer.refCount);
51
+ } else {
52
+ // which refs that transfer assigned is no longer known; everything goes out whole again
53
+ localRefs.clear();
54
+ }
55
+ latestTransfer = undefined;
56
+ return true;
57
+ }
58
+ );
36
59
 
37
60
  connection.onRequest(
38
61
  new rpc.RequestType<GetObject, any, Error>("GetObject"),
@@ -75,6 +98,7 @@ export class GetObject {
75
98
  };
76
99
  pendingData.set(objId, pending);
77
100
  remoteObjects.set(objId, after);
101
+ latestTransfer = {id: objId, refCount: savedRefCount};
78
102
  } catch (e) {
79
103
  remoteObjects.delete(objId);
80
104
  localRefs.rollbackTo(savedRefCount);
@@ -67,7 +67,10 @@ export class Parse {
67
67
  relativeTo: request.relativeTo
68
68
  })!;
69
69
 
70
- const generator = parser.parse(...request.inputs);
70
+ // an input without its text names a file for the parser to read
71
+ const inputs = request.inputs.map(input =>
72
+ typeof input === 'object' && input.text == null ? input.sourcePath : input);
73
+ const generator = parser.parse(...inputs);
71
74
  const resultIds: UUID[] = [];
72
75
 
73
76
  for (let i = 0; i < request.inputs.length; i++) {
@@ -14,25 +14,31 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import * as rpc from "vscode-jsonrpc/node";
17
- import {isSourceFile, Tree} from "../../tree";
17
+ import {Cursor, isSourceFile, Tree} from "../../tree";
18
18
  import {MarkerPrinter as PrintMarkerPrinter, printer, PrintOutputCapture} from "../../print";
19
19
  import {UUID} from "../../uuid";
20
20
  import {extractSourcePath, withMetrics} from "./metrics";
21
21
 
22
22
  export const enum MarkerPrinter {
23
23
  DEFAULT = "DEFAULT",
24
+ SEARCH_MARKERS_ONLY = "SEARCH_MARKERS_ONLY",
24
25
  FENCED = "FENCED",
25
26
  SANITIZED = "SANITIZED"
26
27
  }
27
28
 
28
29
  export class Print {
30
+ /**
31
+ * @param cursor The ids of what encloses a tree that is not a source file, from its parent outward.
32
+ */
29
33
  constructor(private readonly treeId: UUID,
30
34
  private readonly sourceFileType: string,
31
- readonly markerPrinter: MarkerPrinter = MarkerPrinter.DEFAULT) {
35
+ readonly markerPrinter: MarkerPrinter = MarkerPrinter.DEFAULT,
36
+ readonly cursor?: string[]) {
32
37
  }
33
38
 
34
39
  static handle(connection: rpc.MessageConnection,
35
40
  getObject: (id: string, sourceFileType: string) => any,
41
+ getCursor: (cursorIds: string[] | undefined, sourceFileType?: string) => Promise<Cursor>,
36
42
  logger?: rpc.Logger,
37
43
  metricsCsv?: string): void {
38
44
  connection.onRequest(
@@ -46,14 +52,12 @@ export class Print {
46
52
  if (logger) {
47
53
  logger.log("Printing " + (isSourceFile(tree) ? tree.sourcePath : `tree of type ${tree.kind} in ${context.target}`));
48
54
  }
49
- const out = new PrintOutputCapture(PrintMarkerPrinter[request.markerPrinter]);
50
- let result: string;
55
+ const out = new PrintOutputCapture(PrintMarkerPrinter[request.markerPrinter ?? MarkerPrinter.DEFAULT]);
51
56
  if (isSourceFile(tree)) {
52
- result = await printer(tree).print(tree, out);
53
- } else {
54
- result = await printer(request.sourceFileType).print(tree, out);
57
+ return printer(tree).print(tree, out);
55
58
  }
56
- return result;
59
+ const cursor = request.cursor ? await getCursor(request.cursor, request.sourceFileType) : undefined;
60
+ return printer(request.sourceFileType).print(tree, out, cursor);
57
61
  }
58
62
  )
59
63
  );
@@ -22,6 +22,7 @@ import {
22
22
  DependencyTypes,
23
23
  Generate,
24
24
  GenerateResponse,
25
+ AbortGetObject,
25
26
  GetObject,
26
27
  GetMarketplace,
27
28
  GetMarketplaceResponseRow,
@@ -30,6 +31,7 @@ import {
30
31
  ParseProject,
31
32
  PrepareRecipe,
32
33
  PrepareRecipeResponse,
34
+ MarkerPrinter,
33
35
  Print,
34
36
  TraceGetObject,
35
37
  Visit,
@@ -142,7 +144,7 @@ export class RewriteRpc {
142
144
  Parse.handle(this.connection, this.localObjects, options.metricsCsv);
143
145
  ParseProject.handle(this.connection, this.localObjects, options.metricsCsv);
144
146
  DependencyTypes.handle(this.connection, options?.batchSize || 1000, options.metricsCsv);
145
- Print.handle(this.connection, getObject, options.logger, options.metricsCsv);
147
+ Print.handle(this.connection, getObject, getCursor, options.logger, options.metricsCsv);
146
148
  InstallRecipes.handle(this.connection, options.recipeInstallDir ?? ".rewrite", marketplace, recipeOrigin, options.logger, options.metricsCsv);
147
149
 
148
150
  this.connection.onRequest(
@@ -289,6 +291,15 @@ export class RewriteRpc {
289
291
  await nextPage.catch(() => {
290
292
  });
291
293
  }
294
+ // The sender still counts the object and its refs as delivered until it is told otherwise.
295
+ const rolledBack = await this.connection.sendRequest(
296
+ new rpc.RequestType<AbortGetObject, boolean, Error>("AbortGetObject"),
297
+ new AbortGetObject(id)
298
+ ).catch(() => false);
299
+ if (rolledBack) {
300
+ // a peer that could not roll back goes on sending these refs bare, so they are kept for it
301
+ q.forgetRefs();
302
+ }
292
303
  throw e;
293
304
  }
294
305
 
@@ -321,9 +332,9 @@ export class RewriteRpc {
321
332
  return parsed;
322
333
  }
323
334
 
324
- async print(tree: SourceFile): Promise<string>;
325
- async print(tree: Tree, cursor: Cursor): Promise<string>;
326
- async print(tree: Tree, cursor?: Cursor): Promise<string> {
335
+ async print(tree: SourceFile, cursor?: undefined, markerPrinter?: MarkerPrinter): Promise<string>;
336
+ async print(tree: Tree, cursor: Cursor, markerPrinter?: MarkerPrinter): Promise<string>;
337
+ async print(tree: Tree, cursor?: Cursor, markerPrinter?: MarkerPrinter): Promise<string> {
327
338
  if (!cursor && !isSourceFile(tree)) {
328
339
  throw new Error("Cursor is required for non-SourceFile trees");
329
340
  }
@@ -331,7 +342,7 @@ export class RewriteRpc {
331
342
  const sourceFile = isSourceFile(tree) ? tree : cursor!.firstEnclosing(t => isSourceFile(t))!;
332
343
  return await this.connection.sendRequest(
333
344
  new rpc.RequestType<Print, string, Error>("Print"),
334
- new Print(tree.id, sourceFile.kind)
345
+ new Print(tree.id, sourceFile.kind, markerPrinter, isSourceFile(tree) ? undefined : this.getCursorIds(cursor))
335
346
  );
336
347
  }
337
348
 
package/src/rpc/server.ts CHANGED
@@ -22,6 +22,7 @@ import * as fs from "fs";
22
22
  import {Command} from 'commander';
23
23
  import {dir} from 'tmp-promise';
24
24
  import {DependencyWorkspace} from "../javascript/dependency-workspace";
25
+ import {isMainThread, parentPort, Worker} from "worker_threads";
25
26
 
26
27
  // Include all languages you want this server to support.
27
28
  import "../text";
@@ -30,9 +31,6 @@ import "../yaml";
30
31
  import "../java";
31
32
  import "../javascript";
32
33
 
33
- // Not possible to set the stack size when executing from npx for security reasons
34
- require('v8').setFlagsFromString('--stack-size=8000');
35
-
36
34
  function initPyroscope(logger: rpc.Logger): any {
37
35
  // Strip trailing slashes: the SDK builds the ingest URL as `${serverAddress}/ingest`,
38
36
  // so a trailing slash produces `//ingest`, which the server normalizes via redirect —
@@ -126,8 +124,8 @@ async function main() {
126
124
  }
127
125
  };
128
126
 
129
- process.on('SIGINT', shutdown);
130
- process.on('SIGTERM', shutdown);
127
+ // signals are delivered to the main thread, which passes them on
128
+ parentPort!.on('message', shutdown);
131
129
 
132
130
  const log = options.logFile ? fs.createWriteStream(options.logFile, {flags: 'a'}) : undefined;
133
131
  const logger: rpc.Logger = {
@@ -191,4 +189,18 @@ async function main() {
191
189
  });
192
190
  }
193
191
 
194
- main().catch(console.error);
192
+ if (isMainThread) {
193
+ // A thread's stack is sized when it starts, and the default is too shallow for the type checker
194
+ // on long chains of inferred return types, so the server runs on a thread started with more.
195
+ const server = new Worker(__filename, {
196
+ argv: process.argv.slice(2),
197
+ stdin: true,
198
+ resourceLimits: {stackSizeMb: 8}
199
+ });
200
+ process.stdin.pipe(server.stdin!);
201
+ process.on('SIGINT', () => server.postMessage('SIGINT'));
202
+ process.on('SIGTERM', () => server.postMessage('SIGTERM'));
203
+ server.on('exit', code => process.exit(code));
204
+ } else {
205
+ main().catch(console.error);
206
+ }
@@ -39,6 +39,7 @@
39
39
  */
40
40
  import {describe, type SuiteAPI, test as base} from "vitest";
41
41
  import {findTestClasspath, JavaRpcTestServer} from "../rpc/java-rpc-client";
42
+ import {RewriteRpc} from "../rpc/rewrite-rpc";
42
43
 
43
44
  export {findTestClasspath, JavaRpcTestServer} from "../rpc/java-rpc-client";
44
45
  export type {JavaRpcOptions} from "../rpc/java-rpc-client";
@@ -76,6 +77,8 @@ export const testJavaRpc = base.extend<JavaRpcFixtures>({
76
77
  {scope: "worker"},
77
78
  ],
78
79
  javaRpc: async ({_javaRpcServer}, use) => {
80
+ // any RewriteRpc constructed in this worker since has replaced it as the active connection
81
+ RewriteRpc.set(_javaRpcServer.rpc);
79
82
  await _javaRpcServer.reset();
80
83
  await use(_javaRpcServer);
81
84
  },