vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

Reindent Lines commands don't work

Open andycraig opened this issue 5 years ago • 9 comments

Describe the bug

Commands Reindent Lines, Reindent Selected Lines do nothing.

To Reproduce

  1. Create a file temp.R with the following content:
    for(i in 1:2) {
    print(i)
    }
    
  2. Use command Reindent Lines; nothing happens
  3. Select all lines
  4. Use command Reindent Selected Lines; nothing happens

Contrast with JavaScript:

  1. Create a file temp.js with the following content:
    for (let index = 0; index < array.length; index++) {
    const element = array[index];   
    }
    
  2. Use command Reindent Lines; middle line is indented as expected

EDIT: For Javascript, it also works if only lines 2-3 are selected and the Reindent Selected Lines command is used.

Notes

Not sure if this is a vscode-R bug or a VS Code bug, as there seem to be quite a few VS Code issues related to reindenting, e.g., https://github.com/microsoft/vscode/issues/19847

andycraig avatar Nov 03 '20 08:11 andycraig

Might be because we have no indentation rules in r-configuration.json etc. https://code.visualstudio.com/api/language-extensions/language-configuration-guide#indentation-rules

andycraig avatar Nov 05 '20 23:11 andycraig

I did some testing and I believe this is because we have no indentation rules. Indentation after (, { etc. while typing is provided by default, but not indentation when running Reindent Lines. Issue about this at VS Code: https://github.com/microsoft/vscode/issues/111088

If we did add indentation after pipes, we would run into an additional complication: It seems like VS Code would indent them differently as they were typed than it would indent them when running Reindent Lines. Issue about this at VS Code: https://github.com/microsoft/vscode/issues/111089

andycraig avatar Nov 21 '20 12:11 andycraig

As discussed on Twitter, {styler} first needs to support reindention only, which is not the case with styler <= 1.3.2.9000. E.g. reindenting always also implies styling spaces. I opened https://github.com/r-lib/styler/issues/703 to track the status of this.

lorenzwalthert avatar Jan 02 '21 17:01 lorenzwalthert

Thanks @lorenzwalthert. At present the VS Code command Reindent Lines uses a language's indentation rules, not the language server. So styler supporting reindentation only wouldn't help with Reindent Lines, although we could (for example) add our own R: Reindent Lines command. VS Code may add language server reindentation at some point: https://github.com/microsoft/vscode/issues/19847

andycraig avatar Jan 03 '21 02:01 andycraig

Thanks @andycraig. Sorry, I did not read this thread properly and concluded from our Twitter discussion that styler was the bottleneck. If you want to use styler to build your own command for indenting lines, at least you now have the tools to do so. Doesn't look like there is much progress on the Microsoft language server side of this issue at the moment...

lorenzwalthert avatar Jan 03 '21 08:01 lorenzwalthert

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Mar 17 '23 01:03 github-actions[bot]

unstale

ElianHugh avatar Mar 18 '23 00:03 ElianHugh

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Mar 18 '24 01:03 github-actions[bot]