Skip to content

FormatOnType is formatting too many lines #10016

Description

@sean-mcmanus
  VSCode: Version: 1.72.0 (Universal)

Commit: 64bbfbf67ada9953918d72e1df2f4d8e537d340e
Date: 2022-10-04T23:21:58.256Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin arm64 21.6.0
Sandboxed: No
Cpp-tools: v1.12.4

Using clang-format that is bundled with VSCode. .clang-format setting is BasedOnType: Google only.

Repro process:

I edited the question because I forgot to put the close brace for the for-loop statement.

  1. With the environment above(also formatOnType is on), prepare the code below.
for(int i = 0)


int foo = 0;
  1. Type ; at the end of the if statement
for(int i = 0;)


int foo = 0;
  1. Formats like below
for(int i = 0;) int foo = 0;

Log
This is the log(somehow in Japanese even though my VSCode is in English 🤔 )
So it seems like VSCode is sending the int foo = 0; line as well. Is it by design or a bug? Also FormatSelection has the same behavior.

IMO, when you try to format the for-loop statement, it should not affect the lines that is more than one empty lines away.

cpptools/formatOnType: /Users/xxxx/main.cpp (id: 637)
入力の書式設定:
for (int i = 0;)


int foo = 0;

ドキュメントの書式設定: file:///Users/xxxx/main.cpp
Formatting Engine: clangFormat
未加工の出力の書式設定:
{ "Cursor": 15, "IncompleteFormat": false }
for (int i = 0;) int foo = 0;

Originally posted by @yusuke-kadowaki in #9983 (reply in thread)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions