microsoft / microsoft/vscode-cpptools

"Format Selection" will use style based of preceding function instead of `C_Cpp:Clang_format_style`

Open
#10,839 7 comments 0 reactions 1 assignee View on GitHub

@michelleangela is already working on this.

Since Apr 19, 2023.

bug Feature: Code Formatting investigate: repro Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and Version: Windows 11, Version 22H2 (OS Build 22621.1413)
  • VS Code Version: 1.77.2
  • C/C++ Extension Version: v1.14.5
  • If using SSH remote, specify OS of remote machine: Ubuntu 20.04.6 LTS
Bug Summary and Steps to Reproduce

Bug Summary:

I have set C_Cpp:Clang_format_style to:

{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, SortIncludes: Never }.

However, when I select a block of code that use a different number of spaces for indentation (four, for example) and select Format Selection from the command palette, the indentation does not change.

Steps to reproduce:

  1. Select Preferences: Open Settings (UI) from the command palette
  2. Click on 'User'
  3. Enter C_Cpp:Clang_format_style in the search box
  4. Paste { BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, SortIncludes: Never } into the text box
  5. Open C++ source file
  6. Select method using four spaces for indentation
  7. Select Format Selection from the command palette
  8. Observe that indentation of selected block does not change

Expected behavior:

Indentation of selected block does changes from four spaces to two spaces.

Configuration and Logs
LSP: textDocument/hover: file:///<redacted>.cpp (id: 2495)
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///<redacted>.cpp (id: 2496)
LSP: cpptools/formatRange: file:///<redacted>.cpp (id: 2497)
Formatting document: file:///<redacted>.cpp
Formatting Engine: clangFormat
Other Extensions

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.