metals icon indicating copy to clipboard operation
metals copied to clipboard

feat: implement `Convert to collect` code action

Open scarf005 opened this issue 1 year ago • 5 comments

collect.webm

resolves: https://github.com/scalameta/metals-feature-requests/issues/288

scarf005 avatar Nov 23 '24 17:11 scarf005

sorry for late response, i accidentally marked notification to this as None.

i'm fine with either approach; (to be honest, doesn't know which way is the best)

if you are interested I can explain exactly what can be done and let you work on that

that would be great!

scarf005 avatar Nov 27 '24 10:11 scarf005

I will try to merge https://github.com/scalameta/metals/pull/6978 tomorrow, but it adds the possibility of using codeAction/resolve.

We can add something similar to FilterMapChain class to data and no edits. If not edits are provided codeAction/resolve will be invoked, where we can additionally check if collect exists by:

  1. First send go to compilers.definition on filter or map
  2. Replace last map or filter with collect in the semanticdb symbol
  3. Use compilers.info to see if that symbol exists and if it exists if it's in an expected shape.
  4. If that's known we just create the edits.

tgodzik avatar Nov 27 '24 17:11 tgodzik

Ok, the other PR is merged, let me know if you have any problems with what I suggested, I can also help finish the PR

tgodzik avatar Nov 28 '24 11:11 tgodzik

currently stuck on NPE while converting to codeAction/resolve.

==> X tests.codeactions.FilterMapToCollectCodeActionSuite.cursor-on-filter  4.928s java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.Range.getStart()" because "range$1" is null

let me know if you have any problems with what I suggested, I can also help finish the PR

I'd be grateful!

scarf005 avatar Nov 28 '24 14:11 scarf005

@tgodzik i've rebased and migrated to codeAction/resolve. still stuck on semanticDB part.

strangely, while it doesn't happen on my local machine the NPE still seems to happen in CI:

tests.codeactions.FilterMapToCollectCodeActionSuite:
  + cursor-on-filter 8.24s
  + cursor-on-filter-newline 2.663s
  + cursor-on-map 2.07s
  + higher-order-function 1.943s
  + higher-order-function-rename-filter-argument 1.924s
  + higher-order-function-rename-map-argument 1.516s
  + multiple-map-calls 1.744s
  + complex-predicate 1.779s
  + multiline-predicate 1.406s
  + multiline-predicate-block 1.843s
  + with-type-annotations 1.632s
[info] Passed: Total 11, Failed 0, Errors 0, Passed 11

https://github.com/scalameta/metals/actions/runs/12094357358/job/33726319967?pr=6969#step:5:1816 image

scarf005 avatar Nov 30 '24 07:11 scarf005