When trying to set up common Neovim plugins for use with SystemVerilog, I discovered that there were very few examples of working configurations. in addition, many of the configuration examples provided by maintainers of plugins for SystemVerilog were often lacking documentation. Therefore, I wanted to share a small configuration based on my own to close the loop for future users like me.
To provide a minimum viable config as a point of reference for configuring an LSP, linter, and Treesitter plugin for use with SystemVerilog. It is not meant to replace your own configuration; only a point of reference.
example
- Contains an example SystemVerilog project to test the config
lua
- Contains the plugin specs and configurations for SystemVerilog. These files are called from within init.lua
init.lua
- The entry point for all Neovim configuration
lazy-lock.json
- Locks the various plugins at known-good versions that work together.
lazy.nvim
- Plugin installation, configuration, and management
nvim-lspconfig
- Configurations for the built-in LSP functionality
nvim-lint
- provides linting for various filetypes
nvim-treesitter
- Provides Treesitter interation for various filetypes
This configuration targets verilator
for linting, and verible-verilog-ls
as the language server. Other providers can be used, but are outside the scope of this project. You will need to make sure to have both verilator
and verible-verilog-ls
on your path. https://verilator.org/guide/latest/install.html
- Clone the repo, making sure to not over write your Neovim config, for example:
git clone [email protected]:thecooldaniel/nvim-config-systemverilog.git ~/.config/nvim-systemverilog
- Launch Neovim, specifying the new config:
NVIM_APPNAME=nvim-systemverilog nvim
lazy.nvim
should be installed, an in turn it should install all the other plugins- Run
:Lazy
to verify. Pressq
to close the window. - IMPORTANT: Set the CWD of the editor/tab to the root of a SystemVerilog project. The root is defined as the directory from which
verilator
should be run - Open
example\sim\tb_counter.sv
,example\rtl\counter.sv
, orexample\rtl\include\packageExample.svh
. Each of these files should contain warnings and/or errors.
verilator
needs to be given include directories explicitly when it is called; this is done similiar to GCC with syntax such as-Irtl
. In this project, the include flags are present inexample\verilator.f
. For details, seelua\setup_systemverilog.lua
.- If you do not set the CWD of the editor/tab, linting will not work.
- Syntax highlighting provided via
nvim-tressitter
can be hit or miss. Seelua\setup_systemverilog.lua
on how to disable it. - While the linter is configured to fire on several Neovim events, it only reliably fires on file save.
:LspConfig
should showverible
attached to at least one open*.sv/*.svh
buffer:InspectTree
should spawn a window with the tree structure generated by Treesitter. You might get Lua errors on first run.:lua =require(
lint).linters.verilator
will show you all of the arguments passed toverilator
when linting. The last argument should be a path; if the argument list ends with-f
thenvim.fs.find
cannot locateverilator.f
- Ensure you have set the CWD. See above.
- Ensure you have either set include flags in the argument sent to
verilator
inlua\setup_systemverilog.lua
, or inverilator.f
. - If the include flags are present, make sure they are either absolute, or relative to the current CWD.
- Save the buffer with
:w
- This is most likely caused by an error/warning present in an imported package.
- trouble.nvim
- mason.nvim (Not used in this project because it only supports the
verible-verilog-xxxx
binaries for all functionality, including linting.)