[vcFormat] Extra spaces around `=` are removed if `space.aroundAssignmentOperator` is set to `insert`

未关闭
#14,413 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
cpp
领域
tooling

调研方向

首先定位 C_Cpp.vcFormat.space.aroundAssignmentOperator 的 vcFormat 实现和测试。在设置为 insert 的 .c 文件中复现 enum 示例,然后验证格式化器在处理没有空格的一侧时仍会保留现有的对齐空格。

由索引模型根据 Issue 内容生成。

描述

Feature Request Feature: Code Formatting Language Service Visual Studio
Environment
  • OS and Version: Various (assuming all)
  • VS Code Version: 1.117.0
  • C/C++ Extension Version: 1.31.5
Bug Summary and Steps to Reproduce

Bug Summary:

When C_Cpp.vcFormat.space.aroundAssignmentOperator is set to insert, vcFormat will remove all extra spaces around an assignment operator leaving exactly one space on each side. However, there many times where extra spaces are warranted for the sake of columnar alignment to improve readability.

Therefore, I believe there are two possible solutions to this problem:

  1. Change the behavior of insert so that it only modifies the file by adding a space if no space is present on a side of the assignment operator
  2. Remove the insert and remove options and replace them with the following options (retaining the ignore option):
    • none: Formatter will remove spaces from both sides of the assignment operator
    • one: Formatter will add or remove spaces from both sides of the assignment operator so that the result is one space on each side of the assignment operator
    • oneOrMore: Formatter will only add one space to a side of the assignment operator if zero spaces exist on that side. If one or more spaces exist, the formatter will not make any changes.

Steps to reproduce:

  1. Ensure C_Cpp.vcFormat.space.aroundAssignmentOperator is set to insert
  2. Add the following lines to a .c file:
enum {
    short_name          = 0x00,
    longer_name         = 0x01,
    even_longer_name    = 0x02,
    another_longer_name = 0x04,
    shorter_name        = 0x08,
};
  1. Format the file using vcFormat

Expected behavior:

  • The file should not change

Actual output:

enum {
    short_name = 0x00,
    longer_name = 0x01,
    even_longer_name = 0x02,
    another_longer_name = 0x04,
    shorter_name = 0x08,
};
Configuration and Logs
N/A
Other Extensions

No response

Additional context

No response

主要语言
TypeScript
星标
6.2k
派生
1.7k
平均合并
14 小时 46 分钟
30 天内合并 PR
61

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/vscode-cpptools 的其他 Issue

查看 microsoft/vscode-cpptools 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。