+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_analyze): refactor code actions to use batch mutations #2915

Merged
merged 2 commits into from
Jul 25, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Jul 21, 2022

Summary

This PR refactors the RuleAction and AnalyzerAction to have lint rules provide code actions in the form of BatchMutation objects instead of returning a mutated syntax tree. In addition to possible improvements to performances unlocked by batching the mutations, this change allows the set of changes to be inspected in order to efficiently generate smaller text diffs that directly represent the mutation operations that were executed on the syntax tree using rome_text_edit (in fact for most use-cases code actions can directly be turned into a text-based diff operation without having to go through the mutation commit operation to build the mutated syntax tree)

In order to support this I had to extend the BatchMutation to support additional mutation operations that were used by existing lint rules, as well as replicating the "automatic trivia transfer" feature of the replace_node and replace_token method of the AstNode mutation extensions

Test Plan

The lint rules test suite has been adapted to the new internal representation of code actions with no changes to the content of snapshots, from a user perspective all rules continue to emit the exact same code actions as before the change

@leops leops temporarily deployed to aws July 21, 2022 16:14 Inactive
@leops
Copy link
Contributor Author

leops commented Jul 21, 2022

!bench_analyzer

@github-actions
Copy link

github-actions bot commented Jul 21, 2022

@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 395 395 0
Failed 5551 5551 0
Panics 0 0 0
Coverage 6.64% 6.64% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12393 12393 0
Failed 3864 3864 0
Panics 0 0 0
Coverage 76.23% 76.23% 0.00%

@github-actions
Copy link

Analyzer Benchmark Results

group                     main                                   pr
-----                     ----                                   --
analyzer/css.js           1.10      3.0±0.01ms     3.9 MB/sec    1.00      2.7±0.01ms     4.3 MB/sec
analyzer/index.js         1.00      6.0±0.02ms     5.3 MB/sec    1.00      6.0±0.05ms     5.4 MB/sec
analyzer/lint.ts          1.00      3.7±0.02ms    11.2 MB/sec    1.01      3.7±0.01ms    11.2 MB/sec
analyzer/parser.ts        1.08      9.3±0.02ms     5.2 MB/sec    1.00      8.6±0.06ms     5.6 MB/sec
analyzer/router.ts        1.05      6.3±0.01ms     9.7 MB/sec    1.00      6.0±0.03ms    10.2 MB/sec
analyzer/statement.ts     1.00      7.7±0.07ms     4.6 MB/sec    1.01      7.8±0.07ms     4.6 MB/sec
analyzer/typescript.ts    1.00     11.2±0.07ms     4.8 MB/sec    1.01     11.3±0.04ms     4.8 MB/sec

@leops leops force-pushed the feature/code-action-batch-mutation branch from 63ad55b to d46f232 Compare July 22, 2022 09:44
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 22, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ec50d8d
Status: ✅  Deploy successful!
Preview URL: https://e1db45c2.tools-8rn.pages.dev
Branch Preview URL: https://feature-code-action-batch-mu.tools-8rn.pages.dev

View logs

@leops leops temporarily deployed to aws July 22, 2022 09:44 Inactive
@leops leops marked this pull request as ready for review July 22, 2022 09:54
@leops leops requested review from ematipico and xunilrj as code owners July 22, 2022 09:54
@leops leops requested a review from a team July 22, 2022 09:54
fn from(action: AnalyzerAction<L>) -> Self {
let indels = action.as_indels();

let range = indels.iter().fold(None, |state, indel| match state {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to move this closer to the BatchMutation?

I can see this being helpful when renaming inside the LSP, for example.
Today I return the whole file, instead of the snippets that changed.

@leops leops temporarily deployed to aws July 25, 2022 10:33 Inactive
@leops leops force-pushed the feature/code-action-batch-mutation branch from 5c1bfc1 to ec50d8d Compare July 25, 2022 12:08
@leops leops requested a review from MichaReiser as a code owner July 25, 2022 12:08
@leops leops temporarily deployed to aws July 25, 2022 12:08 Inactive
@leops leops merged commit 22b9964 into main Jul 25, 2022
@leops leops deleted the feature/code-action-batch-mutation branch July 25, 2022 12:55
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
…e#2915)

* feat(rome_analyze): refactor code actions to use batch mutations

* refactor the text edit generation from batch mutation to be used in renaming operations
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载