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

Illegal value for line #6

Open
kylebarron opened this issue Dec 7, 2022 · 6 comments
Open

Illegal value for line #6

kylebarron opened this issue Dec 7, 2022 · 6 comments

Comments

@kylebarron
Copy link
Owner

this warning happens when running shift+enter on the last line of a text editor. Presumably I'm trying to set a line one after what exists in the editor

@zuo-ls
Copy link

zuo-ls commented Jan 13, 2023

found the same problem. cmd+enter works well for the last line. anyway, please fix this, this extension is awesome.

@xclrr
Copy link

xclrr commented Feb 4, 2023

Hey, I'm also a fan of Atom Hydrogen. Yesterday I found this extension and found the same problem. I've fixed it by editting the run-code.js.
And here's my code. Replace this function in run-code.js with my code below. It is expected to work.

function runInferredCodeBlockAndMoveDown() {
    const textEditor = vscode.window.activeTextEditor;
    if (!textEditor) {
        return;
    }
    const expandedCodeRange = inferCodeBlock(textEditor);
    const inferredBlockText = textEditor.document.getText(expandedCodeRange);
    console.log("inferredBlockText", inferredBlockText);
    var empty_line_count = 0;
    for(var i = expandedCodeRange.end.line; i >= expandedCodeRange.start.line; i--){
        if(textEditor.document.lineAt(i).text.match(/^\s*$/)){
            empty_line_count += 1;
        }
        else{
            break;
        }
    }
    console.log("empty_line_count", empty_line_count);
    executeText(inferredBlockText);
    //add a new line to the end of the code block
    var endPosition;
    var newSelection;
    if(textEditor.document.lineCount <= expandedCodeRange.end.line + 1){
        console.log("the last block")
        if(expandedCodeRange.start.line == expandedCodeRange.end.line-empty_line_count){
            console.log("the last block is a single line")
            if(empty_line_count == 0){
                console.log("need to add a new line")
                vscode.commands.executeCommand("editor.action.insertLineAfter");
            }
            endPosition = new vscode_1.Position(expandedCodeRange.end.line + 1 - empty_line_count, 0);
            newSelection = new vscode_1.Selection(endPosition, endPosition);
            setSelectionAndMoveDown(textEditor, newSelection);
        }
        else{
            console.log("the last block is a multi-line block")
            endPosition = new vscode_1.Position(expandedCodeRange.end.line + 1 - empty_line_count, 0);
            newSelection = new vscode_1.Selection(endPosition, endPosition);
            setSelectionAndMoveDown(textEditor, newSelection);
            if(empty_line_count == 0){
                console.log("need to add a new line")
                endPosition = new vscode_1.Position(expandedCodeRange.end.line + 1, 0);
                newSelection = new vscode_1.Selection(endPosition, endPosition);
                vscode.commands.executeCommand("editor.action.insertLineAfter");
                setSelectionAndMoveDown(textEditor, newSelection);
            }
        }
    } 
    else {
        endPosition = new vscode_1.Position(expandedCodeRange.end.line + 1, 0);
        newSelection = new vscode_1.Selection(endPosition, endPosition);
        setSelectionAndMoveDown(textEditor, newSelection);
    }
}

@andycraig
Copy link

@kylebarron Hi, is there any chance that this solution from @xclrr could be integrated in? I love this extension and I run into this issue multiple times a day. If there's anything I could do to help, please let me know.

@kylebarron
Copy link
Owner Author

A PR is welcome. Some sort of test for this would be ideal, though I never figured out the initial setup for how to do tests on vscode

@andycraig
Copy link

@xclrr Would you like to do a PR? If so, great! If not, would you mind if I did a PR based on your code?

@kylebarron I think a test for this would be trickier than ones I've done in the past but I'll have a look into it.

@andycraig
Copy link

@kylebarron I'm afraid I still don't have a solution for testing but would it be possible to merge @xclrr's PR in the meantime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants