Skip to content

How to disable code auto-format in VS Code? #544

Closed

Description

@mihaiconstantin

I am asking it here because I can't seem to find an answer in the docs or elsewhere. The posts that I find (e.g., this StackOverflow question) don't help.

Activity

  1. renkun-ken commented on May 2, 2022

    @renkun-ken
    Member

    See https://code.visualstudio.com/docs/editor/codebasics#_formatting.

    If you want to disable format on save only for R, add the following in the vscode settings.json:

    "[r]": {
        "editor.formatOnSave": false
    }
  2. mihaiconstantin commented on May 2, 2022

    @mihaiconstantin
    Author

    Thanks, I was not aware it was this obvious!

    I now realize that the issue I am experiencing is not due to auto-formatting. The issue is that when there is a syntax error in the code (e.g., missing )) then the code folding (i.e., including #region ...) stops working. Sometimes it happens that the syntax error is already in a folded region, but I cannot unfold to get to it (i.e., unless I disable the extension and reenable it after fixing the error).

    Do you know by any chance what is causing this? I thought it was the auto-format.

  3. renkun-ken commented on May 2, 2022

    @renkun-ken
    Member

    It has the same cause with #501. The folding provider is based on parsed data, which assumes that the code could be fully parsed.

  4. mihaiconstantin commented on May 2, 2022

    @mihaiconstantin
    Author

    Oh, I see. This answers my question, thank you! Will close this one.

  5. mihaiconstantin commented on May 3, 2022

    @mihaiconstantin
    Author

    I am sorry to comment again on this, but even with

    "[r]": {
        "editor.formatOnSave": false
    }

    I am still facing the auto-format:

    auto_format_issue.mov

    Is this related to the linter? If so do you have any ideas on how to disable this behavior?

  6. renkun-ken commented on May 4, 2022

    @renkun-ken
    Member

    You could tweak styler's tidyverse_style by putting the following in your ~/.Rprofile:

    options(languageserver.formatting_style = function(options) {
      style <- styler::tidyverse_style(
        scope = "indention",
        indent_by = options$tabSize
      )
      style$space$start_comments_with_space <- NULL
      style
    })
  7. mihaiconstantin commented on May 4, 2022

    @mihaiconstantin
    Author

    Thank you @renkun-ken. This did it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions