Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Verilog BeginEnd FixerNew to Visual Studio Code? Get it now.
Verilog BeginEnd Fixer

Verilog BeginEnd Fixer

hades841

|
4 installs
| (0) | Free
Auto-complete Verilog/SystemVerilog begin/end blocks with Vivado xvlog validation.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Verilog BeginEnd Fixer

Verilog BeginEnd Fixer automatically adds missing begin / end blocks to Verilog and SystemVerilog control statements. Before applying any change, it validates the transformed candidate with Vivado xvlog; the active file remains unchanged when validation fails.

It is intended for FPGA development workflows that need to normalize single-statement always, if, else, and for control structures quickly and safely.

Project and support

  • Source repository: hades841/verilog-beginend-fixer
  • Report issues: GitHub Issues
  • For bugs, compatibility issues, or feature suggestions, email 1842384443@qq.com. I will do my best to reproduce and fix the issue.

Features

  • Automatically adds begin / end blocks where a control statement needs a code block.
  • Inserts begin at the end of the control-statement line and before any end-of-line comment.
  • Supports .v and .sv files. Testbench files whose names end in _tb are skipped.
  • Validates candidate code with Vivado xvlog before writing changes.
  • Finds referenced SystemVerilog packages in the workspace and include directories, then compiles them in dependency order before the candidate file.
  • Leaves the editor unchanged after validation failure, and writes Vivado output plus the complete candidate file to a log.
  • Overwrites one workspace log file on every run so it always represents the latest result.

Usage

  1. Open a Verilog or SystemVerilog file in VS Code.
  2. Configure the Vivado installation directory, for example D:\Vivado\2022.2.
  3. Press Ctrl+Alt+K (Cmd+Alt+K on macOS), or run Verilog: Auto add begin-end from the Command Palette.
  4. The transformed result is written to the active file only after xvlog validation succeeds.

Example

Before conversion:

always @(posedge clk or negedge rst_n)
    if (!rst_n)
        rx_busy <= 1'b0;
    else if (state != IDLE)
        rx_busy <= 1'b1;
    else
        rx_busy <= 1'b0;

After conversion:

always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        rx_busy <= 1'b0;
    end else if (state != IDLE) begin
        rx_busy <= 1'b1;
    end else begin
        rx_busy <= 1'b0;
    end
end

End-of-line comments are retained after begin:

if (enable) begin // Update only when enabled
    data <= next_data;
end

Settings

Search for Verilog BeginEnd Fixer in VS Code Settings, or add the following to settings.json:

{
  "verilog-helper.vivadoPath": "D:\\Vivado\\2022.2",
  "verilog-helper.vivadoTimeoutMs": 120000,
  "verilog-helper.vivadoIncludePaths": [
    "D:\\FPGAProject\\common\\include"
  ],
  "verilog-helper.vivadoPackageFiles": [
    "D:\\FPGAProject\\shared\\configPackage.sv"
  ]
}

verilog-helper.vivadoPath accepts either the Vivado installation directory or the full path to xvlog.bat. The extension automatically collects the current source directory, relative include directories, and nested include directories for xvlog. Use verilog-helper.vivadoIncludePaths for shared project include directories that cannot be found automatically. If Vivado is not configured, xvlog is unavailable, or validation fails, the extension does not write the transformed result.

For import configPackage::*; or configPackage::member, the extension searches saved .sv, .v, .svh, and .vh files in the current workspace, source directory, and include directories by package declaration. Required packages and their dependencies are compiled before the candidate. Open the project root folder in VS Code so packages in sibling directories can be found. Use the optional verilog-helper.vivadoPackageFiles setting for packages outside these directories or to select one definition when multiple files declare the same package. Relative include and package settings are resolved from the current file's workspace folder. The example paths above should be replaced with your project paths; both lists can be empty when automatic discovery is sufficient.

Logs

The log file is always written to:

<workspace>/.verilog-helper-logs/vivado-validation.log

The log contains Vivado xvlog output and the complete transformed candidate source. Each command execution overwrites the previous log.

It also records the package compilation order, unresolved scope references, and the actual xvlog invocation. Missing or invalid dependencies still cause validation to fail.

Notes

  • Use version control or a backup before applying batch conversion results.
  • xvlog validation confirms that the transformed file passes Vivado Verilog/SystemVerilog syntax and semantic analysis. Project-level dependencies, macro definitions, and include directories should still be verified in the corresponding Vivado project environment.

中文说明

为 Verilog / SystemVerilog 代码自动补充缺失的 begin / end,并在写入前调用 Vivado xvlog 校验转换结果。校验失败时,扩展不会修改原文件。

适用于需要快速规范化 always、if、else、for 等单语句控制结构的 FPGA 开发场景。

项目与反馈

  • 源码仓库:hades841/verilog-beginend-fixer
  • 问题反馈:GitHub Issues
  • 使用中如遇到 Bug、兼容性问题或有功能建议,欢迎发送邮件至 1842384443@qq.com。我会尽力复现并修复问题。

功能

  • 自动为需要代码块的控制语句补充 begin / end。
  • begin 添加在控制语句行的末尾,并位于该行注释之前。
  • 支持 .v 与 .sv 文件;文件名以 _tb 结尾的测试平台文件会跳过处理。
  • 写入前使用 Vivado xvlog 校验候选代码。
  • 自动查找工作区及 include 目录中引用的 SystemVerilog 包,并在候选文件之前按依赖顺序编译。
  • 校验失败时保持编辑器内容不变,并将 Vivado 输出与完整候选文件写入日志。
  • 每次运行覆盖工作区中的同一份日志,便于查看本次结果。

使用方法

  1. 在 VS Code 中打开 Verilog 或 SystemVerilog 文件。
  2. 配置 Vivado 安装目录,例如 D:\Vivado\2022.2。
  3. 按 Ctrl+Alt+K(macOS 为 Cmd+Alt+K),或在命令面板执行 Verilog: Auto add begin-end。
  4. 仅当 xvlog 校验通过后,转换结果才会写入当前文件。

示例

转换前:

always @(posedge clk or negedge rst_n)
    if (!rst_n)
        rx_busy <= 1'b0;
    else if (state != IDLE)
        rx_busy <= 1'b1;
    else
        rx_busy <= 1'b0;

转换后:

always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        rx_busy <= 1'b0;
    end else if (state != IDLE) begin
        rx_busy <= 1'b1;
    end else begin
        rx_busy <= 1'b0;
    end
end

行尾注释会被保留在 begin 之后:

if (enable) begin // 仅在使能时更新
    data <= next_data;
end

设置

在 VS Code 设置中搜索 Verilog BeginEnd Fixer,或在 settings.json 中配置:

{
  "verilog-helper.vivadoPath": "D:\\Vivado\\2022.2",
  "verilog-helper.vivadoTimeoutMs": 120000,
  "verilog-helper.vivadoIncludePaths": [
    "D:\\FPGAProject\\common\\include"
  ],
  "verilog-helper.vivadoPackageFiles": [
    "D:\\FPGAProject\\shared\\configPackage.sv"
  ]
}

verilog-helper.vivadoPath 可填写 Vivado 安装目录,也可直接填写 xvlog.bat 的完整路径。扩展会自动收集当前源文件、相对路径 include 文件及其嵌套 include 文件所在目录,并加入 xvlog 搜索路径;无法从源码路径自动找到的工程公共目录,可通过 verilog-helper.vivadoIncludePaths 追加。未配置 Vivado、找不到 xvlog 或 xvlog 校验失败时,扩展不会写入转换结果。

对于 import configPackage::*; 或 configPackage::成员,扩展会在当前工作区、源文件目录及 include 目录内的已保存 .sv、.v、.svh、.vh 文件中按包声明查找定义,并在候选文件之前按顺序编译所需包及其依赖。请在 VS Code 中打开工程根目录,以便查找同级目录内的包。包位于上述范围之外,或工程中存在多个同名包时,可通过可选设置 verilog-helper.vivadoPackageFiles 指定正确文件。include 和包文件配置中的相对路径均以当前文件所属工作区为基准。示例路径请替换为实际路径;自动查找足够时,这两个列表均可留空。

日志

日志文件固定为:

<工作区>/.verilog-helper-logs/vivado-validation.log

日志包含 Vivado xvlog 输出,以及本次转换后的完整候选代码。每次执行命令都会覆盖旧日志。

日志还会记录包文件编译顺序、未找到定义的作用域引用和实际 xvlog 调用命令。依赖文件缺失或存在真正错误时,仍会校验失败并保留原文件。

注意事项

  • 建议在版本控制或备份环境中使用批量转换结果。
  • xvlog 校验用于确认转换后的文件能够通过 Vivado 的 Verilog / SystemVerilog 语法与语义分析;工程级依赖、宏定义与包含目录仍应在对应的 Vivado 工程环境中确认。
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft