Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calva.evalCurrentTopLevelFormInREPLWindow fails in specific condition #374

Closed
bpringe opened this issue Oct 3, 2019 · 3 comments
Closed

calva.evalCurrentTopLevelFormInREPLWindow fails in specific condition #374

bpringe opened this issue Oct 3, 2019 · 3 comments

Comments

@bpringe
Copy link
Contributor

@bpringe bpringe commented Oct 3, 2019

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

@cfehse

This comment has been minimized.

Copy link
Contributor

@cfehse cfehse commented Oct 10, 2019

@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.

@PEZ

This comment has been minimized.

Copy link
Collaborator

@PEZ PEZ commented Oct 10, 2019

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.

@cfehse cfehse mentioned this issue Oct 10, 2019
6 of 6 tasks complete
PEZ added a commit that referenced this issue Oct 11, 2019
Fix issue #374
@cfehse

This comment has been minimized.

Copy link
Contributor

@cfehse cfehse commented Oct 12, 2019

@bpringe This issue is fixed in version 2.0.49.

@cfehse cfehse closed this Oct 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.