microsoft / microsoft/vscode-cpptools
"Format Selection" will use style based of preceding function instead of `C_Cpp:Clang_format_style`
Open
@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:
- Select
Preferences: Open Settings (UI)from the command palette - Click on 'User'
- Enter
C_Cpp:Clang_format_stylein the search box - Paste
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, SortIncludes: Never }into the text box - Open C++ source file
- Select method using four spaces for indentation
- Select
Format Selectionfrom the command palette - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.