TypeScript ScanningRecipe sends no edit preconditions over RPC

Open
#9,734 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
69/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

Start by reading ScanningRecipe.editor() and PrepareRecipe.optimizePreconditions in the TypeScript package, then compare the plain and scanning recipe repro in the issue. Trace why the lazy editor wrapper hides the visitor type or check() from precondition optimization. Done means the scanning recipe produces the appropriate edit precondition and the host no longer sends incompatible source files to its edit visitor.

Written by the indexing model from the issue text.

Description

In @openrewrite/rewrite 8.100.3, PrepareRecipe sends no editPreconditions for a TypeScript ScanningRecipe. ScanningRecipe.editor() returns a lazy wrapper around editorWithData, so optimizePreconditions never sees the editor's visitor type or its check(). The host then sends every source file to the edit visitor. A Python requirements.txt fails with No RPC codec registered on the TypeScript side for 'org.openrewrite.python.marker.PythonResolutionResult'.

Repro (npm i @openrewrite/[email protected]):

const {Recipe, ScanningRecipe} = require("@openrewrite/rewrite");
const {JsonVisitor} = require("@openrewrite/rewrite/json");
const {PrepareRecipe} = require(require.resolve("@openrewrite/rewrite").replace(/index\.js$/, "rpc/request/prepare-recipe.js"));

class Plain extends Recipe { name = "repro.plain"; displayName = "plain"; description = "plain"; async editor() { return new JsonVisitor(); } }
class Scanning extends ScanningRecipe {
    name = "repro.scanning"; displayName = "scanning"; description = "scanning";
    initialValue() { return {}; }
    async scanner() { return new JsonVisitor(); }
    async editorWithData() { return new JsonVisitor(); }
}
(async () => {
    for (const r of [new Plain(), new Scanning()]) {
        const pre = [];
        await PrepareRecipe.optimizePreconditions(r, "edit", pre);
        console.log(r.name, JSON.stringify(pre));
    }
})();

Output: repro.plain gets the FindTreesOfType Json gate; repro.scanning gets [].

Seen with Moderne CLI 4.13.0-SNAPSHOT on splunk/splunk-app-examples, running org.openrewrite.react.migrate.enzyme-to-react-testing-library. Related: #9582 (scan batching, fixed by #9669).

Dominant language
Java
Stars
3.9k
Forks
599
Avg merge
9h 38m
Merged PRs (30d)
557

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openrewrite/rewrite

All issues in openrewrite/rewrite

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.