Skip to content

Format only modified lines #44075

@kylegmaxwell

Description

@kylegmaxwell

Issue Type

Feature Request

Description

It would be helpful if there were a way to format only the modified lines. What is modified would be determined by source control. Currently formatOnType only works with semi colon (see microsoft/vscode-cpptools#1419), and formatOnSave formats the entire file. This is undesirable when working on large codebases with legacy code. In that case I want to make a small change, and have it automatically formatted on save, but not modify the rest of the file, which would create a huge diff.
It would also be great to have similar behavior for trimming trailing white space.

VS Code Info

VS Code version: Code 1.20.1 (f88bbf9, 2018-02-13T15:31:21.019Z)
OS version: Linux x64 4.14.16-200.fc26.x86_64

Steps to Reproduce:

  1. Set preferences:
    "editor.formatOnSave": true,
    "C_Cpp.clang_format_path": "/usr/bin/clang-format",
  2. Open a C++ file with multiple formatting errors
  3. Modify the file on one line.
  4. Note that multiple modifications have been made to the file.

Does this issue occur when all extensions are disabled?:

No, formatting does not work at all in that case.

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityformattingSource formatter issuesinsiders-releasedPatch has been released in VS Code Insiderson-testplan

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions