calva.evalCurrentTopLevelFormInREPLWindow fails in specific condition

Created on 4 Oct 2019  路  3Comments  路  Source: BetterThanTomorrow/calva

If I run ctrl+alt+c, ctrl+alt+space with my cursor after the last form inside a comment form like this, the command fails to run, with a little notification saying it failed. It seems to do this only if I have another form above it inside the comment form. By itself, it works.

image

image

Most helpful comment

@bpringe This issue is fixed in version 2.0.49.

All 3 comments

@PEZ @bpringe

This is caused by the empty line inside the comment form.

This works:

(comment
  (println "Hello")
  (+ 1 1))

This fails:

(comment
  (println "Hello")

  (+ 1 1))

The failing code is in select.ts:

function _getFormSelection(doc, pos, topLevel, ignoreComment = true): vscode.Selection {
        ...
        ...
        ...
        //   paredit.navigator.rangeForDefun(ast, idx) fails to find the right range.           
        peRange = topLevel ? paredit.navigator.rangeForDefun(ast, idx) : paredit.navigator.sexpRange(ast, idx);
    if (peRange) {
        let range = new vscode.Selection(doc.positionAt(peRange[0]), doc.positionAt(peRange[1]));
        if (ignoreComment) {
            range = _adjustRangeIgnoringComment(doc, range);
            if (topLevel) {
                ...
                //  paredit.parse(doc.getText(range)) returns an error 
                ast = paredit.parse(doc.getText(range));
                ...
                ...
               // peRange will be null because of the previous error.
               peRange = paredit.navigator.rangeForDefun(ast, idx);
               // this statement will fail because peRange is null
               range = new vscode.Selection(doc.positionAt(peRange[0] + idxOffset), doc.positionAt(peRange[1] + idxOffset));
               ...
            }
        }
        return range;
    }
    else {
        return new vscode.Selection(pos, pos);
    }
}

I am not familiar with the paredit code. Perhaps Peter can take a look at this.

Good find. This has been biting me quite a lot lately. I suspect _adjustRange.... There should be a more robust way to do it. Probably we should be using docMirror instead.

@bpringe This issue is fixed in version 2.0.49.

Was this page helpful?
0 / 5 - 0 ratings