rksm / paredit.js

Generic reader and editor for s-expressions.
MIT License
107 stars 21 forks source link

indentRange not working on unbalanced code #12

Closed shaunlebron closed 7 years ago

shaunlebron commented 7 years ago

We are trying to use indentRange to indent the line at the cursor, when AST is unbalanced:

Run it here

const paredit = require("paredit.js")
const parseWithCursor = (text) => {
  const i = text.indexOf('|');
  return {text: text.replace('|',''), cursor: i === -1 ? null : i};
};
const {text, cursor} = parseWithCursor(`
[[[[[
  |bar
`);

let ast = paredit.parse(text);
paredit.editor.indentRange(ast, text, cursor, cursor).src

Expected:

[[[[[
     bar

Actual:

[[[[[
bar
rksm commented 7 years ago

OK, as of 0.3 I put in an extension that makes the error objects behave more like sexprs. I think this should be enough to cover unbalanced situations.

shaunlebron commented 7 years ago

thanks 👍

anmonteiro commented 7 years ago

I've tested 0.3 and I think it's exactly what I was looking for. Thanks!