Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Verilog CompanionNew to Visual Studio Code? Get it now.
Verilog Companion

Verilog Companion

fknejdcwnfi

|
5 installs
| (0) | Free
Verilog/SystemVerilog companion for mshr-h.veriloghdl: workspace module index, cross-file completion, port/function hints, instantiation separators, real-time diagnostics, and theme-aware semantic coloring for ports and signals.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Verilog Companion

一個輕量、唯讀、零機器路徑的 VS Code 伴生插件,補足 mshr-h.veriloghdl 缺少的「全工作區索引」與「語意分色」能力。

mshr-h.veriloghdl 的 README 明確說明:它只對當前開啟的檔案做 Ctags,不會自動索引整個 HDL 工作區;其 semantic token provider 也只在外部語言伺服器啟用時才存在。Verilog Companion 用獨立的 Provider API 疊加以下能力:

  • 全工作區模組索引與跨檔補全
  • 模組 / port / function hover 與 signature help
  • 實例化分隔線
  • 即時結構診斷
  • input / output / inout / interface / parameter / signal 語意分色

插件不註冊新語言、不接管既有語法、不修改 mshr-h.veriloghdl,也不主動寫入你的 settings.json。


功能

1. 跨檔案模組提示(含 .v 檔名、介面、output)

  • 在語句開頭輸入模組名時,列出整個工作區的模組。
  • 補全項目右側顯示定義檔案的相對路徑。
  • 選中後在說明面板顯示完整簽名、parameter、port 方向 / 型別 / 位寬。
  • 在實例化的 .po| 位置輸入時,只提示該模組的 port 名稱,並標示方向與位寬。
  • 已連線的 port 會自動排到後面,減少重複選擇。
  • 支援 ANSI / 非 ANSI port、parameter、interface port(如 axi_if.slave s_axi 或 axi_if s_axi)、.*。

2. 實例化之間的分隔橫線

  • 在每個 module instantiation 的第一行上方畫一條細橫線。
  • 顏色預設跟隨主題(editorIndentGuide.activeBackground1),深色 / 淺色主題都不突兀。
  • 可調整粗細、顏色,或改成同時標記 module / function / task 宣告。
  • 只影響目前可見的 Verilog / SystemVerilog 編輯器,不影響其他語言。

3. 模組、函式與輸入輸出提示

  • Hover:
    • 模組宣告或使用處 → 模組簽名、檔案位置、parameter 表、port 表。
    • 實例化的模組型別 / 實例名 → 模組介面 + 實例名稱。
    • .port(...) 的 port 名 → 該 port 的方向、型別、位寬。
    • function / task 宣告或呼叫 → 返回型別、參數表、檔案位置。
  • Signature Help:
    • 在 #(...) 內顯示 parameter 列表。
    • 在實例 port 列表內顯示 port 列表,支援 .name(...) 具名連線定位。
    • 在 function / task 呼叫內顯示參數列表。
  • 模組清單指令:Verilog Companion: Show Workspace Modules,可快速跳到任一模組定義。

4. 即時結構診斷(Problems 面板 + 波浪線)

停止打字約 350ms 後自動分析,不需要執行編譯器、不寫任何檔案:

檢查 嚴重度 說明
宣告但未使用的 port Information(Unnecessary) input / output / inout / interface port 在模組 body 中從未被引用
重複的具名連線 Error 同一個實例把 .clk(...) 連了兩次
具名 + 位置混用 Error Verilog 不允許同一個實例混用具名與位置連線
位置連線數量不符 Warning / Error 少接會列出缺少的 port;多接會報錯
不存在的 port 名 Warning .foo(...) 但模組沒有 foo
未連接的 port Warning / Information input 未接 = Warning;output 未接 = Information + Unnecessary
多重驅動 Warning 兩個以上的實例 output 接到同一條 signal
未定義模組 Information 工作區索引中找不到模組(外部 IP / 生成的 model / 真的漏檔)
大小寫不符 Warning Verilog 識別字區分大小寫,FIFO ≠ fifo
重複模組定義 Hint(預設關閉) 同一模組名稱出現在多個檔案

降噪規則:

  • 空 body 的骨架模組不報 unused port。
  • 含 .* 連線的模組不報 unused port。
  • 同名模組有多份定義時跳過 port 檢查,避免猜錯定義。
  • Vivado 生成目錄與 IP netlist(.cache、.sim、.hw、.runs、ip_user_files、ipstatic、simulation、*_sim_netlist.v、*_funcsim.v、*_timing_netlist.v)不索引、不診斷。
  • 多個 input 共用同一條 signal 是正常 fan-out,不告警;只有多個 output 驅動同一條 signal 才會告警。

即時報錯的邊界:這些是「結構級」即時檢查。完整的語法 / 型別 / 綜合錯誤仍由 mshr-h.veriloghdl 設定的 xvlog 負責(儲存時或手動 lint)。本插件刻意不在每次打字時啟動 Vivado 工具鏈,避免拖慢編輯器、產生暫存檔或與既有 lint 流程衝突。

5. 變數語意分色

使用 DocumentRangeSemanticTokensProvider(不是 full-document provider),只對可見範圍回傳 token;不會與 full-document provider 硬碰硬。

類別 範例 One Dark Pro Darker 淺色主題
input port / input input wire clk #61afef 藍 #005cc5
output port / output output reg [7:0] q #98c379 綠 #22863a
inout port / inout inout wire pad #c678dd 紫 #6f42c1
interface port axi_if.slave s_axi #56b6c2 青 #0b7285
parameter / localparam parameter int WIDTH = 8 #abb2bf 灰白 #24292e
internal signal wire [7:0] data #e06c75 紅 #d73a49
module / instance child u0 金 / 橘 深金 / 棕
function / task function int add #61afef 藍 #005cc5
  • 顏色由 contributes.configurationDefaults.editor.semanticTokenColorCustomizations 提供,沒有寫入你的 settings。
  • 你的既有主題/使用者自訂 semantic token 顏色優先;可用標準設定覆寫,例如:
"editor.semanticTokenColorCustomizations": {
  "rules": {
    "variable.inputPort.companion": { "foreground": "#4FC1FF" },
    "variable.outputPort.companion": { "foreground": "#FFB86C" }
  }
}
  • 若你之後啟用 mshr-h 的外部 language server(svls / veridian / verible-verilog-ls…),本插件預設自動讓位(highlighting.respectLanguageServer: true),避免兩個 provider 競爭。你仍可用設定關閉此讓位行為,但不建議。

6. 中文註解與編碼(GBK / UTF-8 / Vivado 2018.3)

  • 插件索引跨檔模組時會自動辨識:UTF-8(含 BOM)、UTF-16 BOM、GB18030(GBK/GB2312 的超集)。預設 auto 不會修改任何檔案。
  • verilogCompanion.index.encoding 可強制 utf8 或 gb18030;只有在你確定整個工作區編碼一致時才需要。
  • VS Code 建議保持 "files.autoGuessEncoding": true;多數 GBK 舊檔會自動辨識。個別檔案若仍亂碼,用右下角 Reopen with Encoding → GB18030。index.encoding 只影響跨檔索引,不會改變編輯器目前 buffer 的顯示;插件不會改寫你的檔案,也不會改你的 encoding 設定。
  • 少數極短 GBK 檔若位元組剛好也是合法 UTF-8,auto 可能誤判;此時把 index.encoding 設為 gb18030 可強制正確解碼。
  • Vivado 2018.3 在中文 Windows 的內建編輯器只正確辨識 GBK/GB2312(Linux 版通常相反,以 UTF-8 為主)。若把 .v/.sv 全部轉成 UTF-8,Windows 上的 Vivado 會顯示亂碼。因此:
    • 要繼續用 Vivado 內建編輯器:原始檔維持 GBK/GB2312,VS Code 用 autoGuess 開啟即可。這是本插件測試工作區(依索引規則 87 個可索引檔中有 59 個是 GBK)建議的方式。
    • 一定要用 UTF-8:Vivado 2018.3 的 IDE 沒有可靠的預設編碼切換;請用 VS Code 編輯,Vivado 只負責綜合,或在 Vivado 設定改用外部編輯器。網路上「Properties → Resource → Text file encoding」是 **Xilinx SDK(Eclipse)**的設定,不是 Vivado IDE。
    • 若 Vivado 中文顯示成方框/豆腐字(不是亂碼),那是字型問題:在 Vivado 的 Settings → Text Editor → Fonts and Colors(或 Tools → Options → General → Text Editor,依版本選單略有不同)選 Microsoft YaHei 或 SimSun。

安裝

前置需求:本插件是 mshr-h.veriloghdl 的伴生插件,需要它提供 verilog / systemverilog 語言 ID 與 grammar;請先安裝 mshr-h.veriloghdl。若要在 WSL Remote 編輯 Verilog,請在 WSL 內也安裝(本插件不會強制安裝其他插件;未安裝時不會啟用,因為沒有對應語言 ID)。

Marketplace(推薦;Settings Sync 會自動安裝)

code --install-extension fknejdcwnfi.verilog-companion

Marketplace 頁面:

https://marketplace.visualstudio.com/items?itemName=fknejdcwnfi.verilog-companion

  • Windows:開啟 Settings Sync 後,新電腦會像其他 Marketplace 插件一樣自動下載。
  • WSL / Remote:Settings Sync 不覆蓋 remote extension;請在 user settings 加入(只包含本插件):
"remote.defaultExtensionsIfInstalledLocally": ["fknejdcwnfi.verilog-companion"]

Windows 已安裝時,WSL 連線後會從 Marketplace 自動補裝。若沒有自動補裝,也可以在 WSL 內手動執行 code --install-extension fknejdcwnfi.verilog-companion。

舊 ID 遷移

舊版 ID 是 fknej.verilog-companion(v1.0–1.1)。新 ID 是 fknejdcwnfi.verilog-companion。請移除舊版,避免兩個插件同時啟用:

code --uninstall-extension fknej.verilog-companion

舊 ID 會保留在 settingsSync.ignoredExtensions 作為陳舊同步條目的防護;這是你的 user settings,插件不會寫入。新 ID 不要加入 ignore。

離線 VSIX(備援)

若無網路或 Marketplace 暫時不可用,仍可安裝同目錄下的 VSIX:

code --install-extension .\verilog-companion-1.2.2.vsix --force
code --install-extension /path/to/verilog-companion-1.2.2.vsix --force

安裝後執行 Developer: Reload Window。若你是從 source checkout 使用,repo 內另有 install.sh / install.ps1;Marketplace/VSIX 安裝不需要它們。


雲端同步設計

項目 設計
設定 全部是布林 / 數字 / 字串 / 通用 glob,沒有 D:\、C:\ 或使用者名稱路徑。
顏色 由 configurationDefaults 提供;不寫入 settings.json。
索引 / token 只存在記憶體,不落地快取檔。
網路 無網路請求、無 telemetry。
檔案 只讀取 .v/.sv/.vh/.svh/.vl,從不寫入 HDL 檔。
舊 ID 由使用者在 settingsSync.ignoredExtensions 保留,避免舊的 pinned 1.0.0 條目被新機器嘗試安裝(插件不會寫入此設定)。
新 ID 不 ignore;發布後由 Settings Sync / Marketplace 正常安裝。

公開上架說明:VS Code Marketplace 對個人開發者沒有 unlisted 選項。本插件是公開 listing,VSIX 可被下載、程式碼可被檢視。上架免費。本 Publisher 的 vsce publish --azure-credential 曾回 InvalidAccessException;實務上需建立短期、僅 Marketplace Manage 權限的 PAT,或設定 GitHub Actions OIDC / Azure Pipelines WIF。PAT 只放在本機環境變數,不寫入 repo,發布後撤銷。


設定

插件不需要任何 settings.json 設定;所有功能預設開啟。

設定 預設 說明
verilogCompanion.enabled true 總開關
verilogCompanion.completion.enabled true 模組 / port 補全
verilogCompanion.completion.maxItems 300 單次補全最多回傳幾個模組
verilogCompanion.hover.enabled true Hover 提示
verilogCompanion.signatureHelp.enabled true 參數 / port 提示
verilogCompanion.highlighting.enabled true 語意分色總開關
verilogCompanion.highlighting.portDirections true port 名稱與方向關鍵字分色
verilogCompanion.highlighting.parameters true parameter / localparam 分色
verilogCompanion.highlighting.signals true 內部 signal 分色
verilogCompanion.highlighting.connections true 具名連線 port 名分色
verilogCompanion.highlighting.instances true instance 名稱分色
verilogCompanion.highlighting.functions true function / task 名稱與呼叫分色
verilogCompanion.highlighting.directionKeywords true input/output/inout 關鍵字分色
verilogCompanion.highlighting.respectLanguageServer true 有 mshr-h LSP 時自動讓位
verilogCompanion.highlighting.maxTokens 20000 單次可見範圍 token 上限
verilogCompanion.highlighting.maxFileSizeKB 1024 超過此大小的檔案跳過分色
verilogCompanion.diagnostics.enabled true 即時結構診斷總開關
verilogCompanion.diagnostics.unusedPorts true 未使用 port
verilogCompanion.diagnostics.unconnectedPorts true 未連接的實例 port
verilogCompanion.diagnostics.duplicateConnections true 重複 / 混用 / 不存在的 port 連線
verilogCompanion.diagnostics.multipleDrivers true 多個 output 驅動同一條 signal
verilogCompanion.diagnostics.undefinedModules true 未定義模組(外部 IP 會產生 Information)
verilogCompanion.diagnostics.duplicateModules false 重複模組定義提示(多 lab 工作區預設關閉)
verilogCompanion.diagnostics.maxProblems 200 單檔最多幾個診斷
verilogCompanion.diagnostics.debounceMs 350 停止打字後多久執行
verilogCompanion.separators.enabled true 實例化分隔線
verilogCompanion.separators.thickness 1px 1px / 2px / 3px
verilogCompanion.separators.color "" 空字串 = 跟隨主題
verilogCompanion.separators.includeModules false 也標記 module / function / task
verilogCompanion.separators.maxPerFile 2000 單檔分隔線上限
verilogCompanion.index.exclude 見套件預設 排除 .git、node_modules、Vivado .cache/.sim/.hw/.runs、ip_user_files、ipstatic、simulation 等
verilogCompanion.index.maxFiles 3000 索引檔案數上限
verilogCompanion.index.maxFileSizeKB 2048 超過此大小的檔案跳過
verilogCompanion.index.encoding auto 跨檔索引解碼:auto / utf8 / gb18030;auto 先試 UTF-8,再試 GB18030

建議的專案工作區

直接把你的 Verilog 工作區(例如 D:\your-verilog-workspace)或單一 Vivado 專案資料夾當作工作區即可。預設排除規則會避開:

  • Vivado 產生的 .cache、.sim、.hw、.runs、.gen
  • IP 的 ip_user_files、ipstatic、simulation 模型
  • .git、node_modules、out、build、dist

安全性與效能

  • 唯讀:只使用 workspace.fs.readFile / TextDocument.getText(),沒有任何寫檔路徑。
  • 不干擾其他插件:
    • 不註冊 language、grammar、snippet、formatter、linter。
    • 不覆寫 mshr-h.veriloghdl 的任何設定。
    • 只新增 Completion / Hover / SignatureHelp / DocumentRangeSemanticTokens Provider 與一個 DiagnosticCollection。
    • 所有 token 都帶 companion modifier,避免顏色規則影響其他語言。
    • Command 全部使用 verilogCompanion.* 命名空間。
  • 效能:
    • 初始索引非同步進行,每 40 個檔案讓出一次 event loop。
    • 檔案變更 / 儲存才重新解析;打字時 900ms debounce。
    • 重建索引以 mtime + ctime + size + encoding + relPath 快取未變更檔,不重讀、不重解析;500 檔 mock 重建約 1ms(首次約 16ms),可用 node scripts/benchmark-index.js 500 重現。真實 87 檔第二次約 266ms,主要剩 stat 成本。
    • 可見編輯器的分隔線 180ms debounce;診斷 350ms debounce。
    • 語意 token 以 document version 快取,只回傳可見範圍。
    • 真實工作區 87 檔 / 3175 tokens 約 9ms(模型建立);10k 行大檔解析約 24ms、模型約 55ms。
  • 失敗容忍:任何解析、Provider 或診斷錯誤都只寫入 Verilog Companion output channel,不會彈窗、不會中斷編輯器。

指令

指令 用途
Verilog Companion: Rebuild Workspace Index 手動重建索引
Verilog Companion: Show Workspace Modules 列出工作區模組,選中後跳到定義位置

疑難排解

  1. 安裝後沒反應 → Developer: Reload Window。
  2. 沒看到語意分色 → 確認 verilogCompanion.highlighting.enabled 為 true,且目前檔案語言是 Verilog / SystemVerilog;若使用的主題關閉 semantic highlighting,插件已用 language-scoped default 強制開啟,但你的使用者設定若明確關閉仍會優先。
  3. 你啟用了 mshr-h 的外部 language server → 本插件預設讓位;這是刻意設計,避免 provider 競爭。可設 highlighting.respectLanguageServer: false 覆寫(不建議)。
  4. 某個模組沒出現在補全 → 確認它位在未被排除的資料夾,或執行 Rebuild Workspace Index。
  5. 想看索引 / 分色狀態 → Output 面板選擇 Verilog Companion。
  6. 大型專案索引太慢 → 調低 verilogCompanion.index.maxFiles,或在 index.exclude 加入更多生成目錄。
  7. 個別檔案在 VS Code 仍顯示亂碼 → 右下角編碼指示 → Reopen with Encoding → GB18030。若你還要使用 Vivado 2018.3 內建編輯器,請不要用 Save with Encoding → UTF-8;Vivado 在 Windows 上只認 GBK/GB2312。

開發與測試

# 解析器 + 分析器 + semantic model + Provider mock + activation 測試
node --test

# 對真實工作區做唯讀解析 / 診斷 / 分色報告
node scripts/report-workspace.js /path/to/workspace
node scripts/report-diagnostics.js /path/to/workspace
node scripts/report-highlight.js /path/to/workspace

# 索引快取 microbenchmark(mock stat,只量讀取/解析節省)
node scripts/benchmark-index.js 500

# 打包 VSIX
npx --yes @vscode/vsce@4.1.1 package --no-dependencies --allow-missing-repository

專案沒有 runtime npm 依賴;src/ 是純 JavaScript,不需要編譯。


與 mshr-h.veriloghdl 的關係

能力 mshr-h.veriloghdl Verilog Companion
語法高亮 / snippet ✅ —
xvlog / verilator lint ✅ —
verible 格式化 ✅ —
當前檔案 Ctags ✅ —
全工作區模組補全 ❌ ✅
跨檔 port / function 提示 ❌ ✅
實例化分隔線 ❌ ✅
即時結構診斷 ❌ ✅
語意分色(port / signal) ❌(僅外部 LSP) ✅

兩者可以同時啟用;本插件不覆寫 mshr-h 的設定,且在其 LSP 啟用時自動讓位。


License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft