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

Reindent Lines commands don't work #435

Open
andycraig opened this issue Nov 3, 2020 · 9 comments
Open

Reindent Lines commands don't work #435

andycraig opened this issue Nov 3, 2020 · 9 comments
Assignees
Labels

Comments

@andycraig
Copy link
Collaborator

andycraig commented Nov 3, 2020

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., microsoft/vscode#19847

@andycraig andycraig added the bug label Nov 3, 2020
@andycraig andycraig self-assigned this Nov 3, 2020
@andycraig
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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: microsoft/vscode#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: microsoft/vscode#111089

@lorenzwalthert
Copy link

lorenzwalthert commented Jan 2, 2021

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 r-lib/styler#703 to track the status of this.

@andycraig
Copy link
Collaborator Author

andycraig commented Jan 3, 2021

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: microsoft/vscode#19847

@lorenzwalthert
Copy link

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

@github-actions
Copy link

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

@github-actions github-actions bot added the stale label Mar 17, 2023
@ElianHugh
Copy link
Collaborator

unstale

@github-actions github-actions bot removed the stale label Mar 18, 2023
Copy link

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

@github-actions github-actions bot added the stale label Mar 18, 2024
@ElianHugh ElianHugh removed the stale label Mar 18, 2024
@dvg-p4
Copy link

dvg-p4 commented Oct 2, 2024

Are there any workarounds for this, other than "open up Rstudio to do the reindent in there instead"?

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

No branches or pull requests

4 participants