apheleia icon indicating copy to clipboard operation
apheleia copied to clipboard

Point is sometimes moved small distances

Open raxod502 opened this issue 5 years ago • 2 comments

Example:

  if (node.type === "CallExpression" && (node.callee.type === "Import" || (node.callee.type === "Identifier" && node.callee.name === "require"))) {
    //@
  }

with point represented by @ is reformatted by Prettier to:

  if (
    node.type === "CallExpression" &&
    (node.callee.type === "Import" ||
      (node.callee.type === "Identifier" && node.callee.name === "require"))
  ) {@
    //
  }

instead of:

  if (
    node.type === "CallExpression" &&
    (node.callee.type === "Import" ||
      (node.callee.type === "Identifier" && node.callee.name === "require"))
  ) {
    //@
  }

I suspect that this problem could be solved by tweaking the weights used in the dynamic programming algorithm.

raxod502 avatar Jul 18 '19 23:07 raxod502

I was having that pointer moving out of place problem and seems like I was able to fix it by setting the --line-length in apheleia to 78. What's weird is that the only thing I have I have using 78 is the warning-fill-column variable which doesn't seem like it can be related, so not sure.

  (setf (alist-get 'black apheleia-formatters)
      '("black" "--line-length" "78" "-"))

But does seem like Black/Emacs format-conflicts can lead to these types of issues.

jpablobr avatar Apr 16 '22 13:04 jpablobr

I think this is unlikely to be directly related to the line length configuration. I think what you're observing is just that the diff being applied is slightly different, which happens to trigger the (somewhat nondeterministic) limitation in Apheleia's dynamic programming algorithm that is the cause of point moving.

raxod502 avatar Apr 17 '22 18:04 raxod502

This is fixed now #290 is merged.

raxod502 avatar Mar 31 '24 18:03 raxod502