nova-rust icon indicating copy to clipboard operation
nova-rust copied to clipboard

[BUG] Code action's misbehavior

Open belcar-s opened this issue 3 years ago • 1 comments

Describe the bug After clicking on the Inline into all callers option displayed in the code actions menu, changes are made to the document which may have been unforeseen by the programmer(s) (?).

To Reproduce Steps to reproduce the behavior:

  1. Write a function.
  2. Click on the light bulb.
  3. Click on Inline into all callers.
  4. Observe the changes made to the document.

Expected behavior In the conditions demonstrated in the video below, I expected area(width1, height1) to be replaced with width1 * height1.

Screenshots If applicable, add screenshots to help explain your problem.

https://user-images.githubusercontent.com/73370025/171007547-fa491331-3171-4a33-8e11-e65989cab040.mov

Versions (please complete the following information):

  • macOS: Monterey
  • Processor: Apple Silicon
  • Nova: 9.3
  • Extension Version: 2.1.0

Additional context I don't know what additional information can be useful :(.

belcar-s avatar May 30 '22 14:05 belcar-s

Code Actions are handled by Nova and not forwarded to extensions. It's why Code Actions were broken for many extensions (including this one) until Panic fixed a lot of language client issues in Nova 9.

That said, I think this is actually a bug with Rust Analyzer. When I use your sample code, this is the response to Nova's request for CodeActions:

{
  "jsonrpc":"2.0",
  "id":5,
  "result":[
    {
      "title":"Inline into all callers",
      "kind":"refactor.inline",
      "edit":{
        "documentChanges":[
          {
            "textDocument":{"uri":"file:///Users/xxxx/issue-30/src/main.rs","version":1},
            "edits":[
              {"range":{"start":{"line":4,"character":1},"end":{"line":4,"character":5}},"newText":"width1"},
              {"range":{"start":{"line":4,"character":5},"end":{"line":4,"character":21}},"newText":" "},
              {"range":{"start":{"line":4,"character":21},"end":{"line":4,"character":21}},"newText":"*"},
              {"range":{"start":{"line":4,"character":21},"end":{"line":4,"character":21}},"newText":" "},
              {"range":{"start":{"line":4,"character":21},"end":{"line":4,"character":21}},"newText":"height1"},
              {"range":{"start":{"line":9,"character":0},"end":{"line":11,"character":1}},"newText":""}
            ]
          }
        ]
      }
    },
    {
      "title":"Generate a documentation template",
      "kind":"",
      "edit":{"documentChanges":[
        {
          "textDocument":{"uri":"file:///Users/xxxx/issue-30/src/main.rs","version":1},
          "edits":[
            {"range":{"start":{"line":9,"character":0},"end":{"line":9,"character":0}},"newText":"/// .\n"}
          ]
        }
      ]
    }
  }
  ]
}Content-Length: 188

Line/character values are zero-indexed, so as you see above Nova is doing what Rust Analyzer is telling it and overwriting line 5. I tried changing the function name to rect_area, but it still replaces 'area' in the string. I'll go ahead and file an issue with Rust Analyzer.

kilbd avatar May 31 '22 16:05 kilbd