【问题标题】:VSCode: disable code formatting on small portion of codeVSCode:禁用一小部分代码的代码格式化
【发布时间】:2019-02-24 14:49:50
【问题描述】:

所以我正在嵌入式 c 环境中开发引导加载程序。为了让引导加载程序“跳转”,.c 文件中需要一些汇编语言。

在 VSCode 中是否有类似于 This(或其他)的方法允许暂时禁用格式化?

为了进一步澄清,代码如下所示:

__asm void boot_jump(uint32_t address)
{
LDR SP, [R0];   Load new stack pointer address
LDR PC,     [ R0, #4 ]; Load new program counter address
}

并且 VSCode 不断将此代码格式化为:

__asm void boot_jump(uint32_t address)
{
LDR SP, [R0];
Load new stack pointer address
    LDR PC,
    [ R0, #4 ];
Load new program counter address
}

这将导致编译错误并且不会构建。提前感谢您的帮助。

【问题讨论】:

    标签: c visual-studio-code formatting inline-assembly


    【解决方案1】:

    如果您更改代码以使用 C 注释分隔符,例如:

    __asm void boot_jump(uint32_t address)
    {
    LDR SP, [R0];   // Load new stack pointer address
    LDR PC,     [ R0, #4 ]; // Load new program counter address
    }
    

    然后格式化程序将不会做更多的缩进代码,这是良性的(而且更漂亮):

    __asm void boot_jump(uint32_t address)
    {
        LDR SP, [R0];       // Load new stack pointer address
        LDR PC, [ R0, #4 ]; // Load new program counter address
    }
    

    【讨论】:

    • 呃,太简单了!仍然很高兴知道是否可以有选择地禁用格式化。
    猜你喜欢
    • 2021-03-26
    • 2021-02-24
    • 2012-08-14
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    相关资源
    最近更新 更多