mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.76k stars 191 forks source link

verilator linter does not take other files into account #567

Closed goekce closed 1 month ago

goekce commented 2 months ago

Test case:

test_pkg.sv:

package test_pkg;
  localparam int test = 2;
endpackage

test.sv:

module test
  import test_pkg::*;
(
    input clk
);
endmodule

The linter outputs:

Importing from missing package 'test_pkg' verilator () [2, 10]

Taking all files in the folder using verilator --lint-only *.sv does not output any error.

Is this a problem of verilator or nvim-lint configuration?

max-kudinov commented 1 month ago

As far as I understand, currently nvim-lint passes only the opened file to Verilator, so it has no clue about your imports or top module. As a workaround a have a verilator.f config file with following contents:

-Wall
--timing
--trace-fst
--trace-structs
--x-assign unique
--x-initial unique
-Irtl
-Irtl/include
rtl/board_top.sv

This config is in project's root directory, my modules is in rtl directory and packages in rtl/include. I also specify top. It doesn't have --lint-only option, because I use it not only for linting, but for simulation is well.

After writing your config, the only thing that is left to do is to pass it as an argument:

local verilator = require('lint').linters.verilator

verilator.args = {
    '--lint-only',
    '-F',
    vim.fs.find("verilator.f", {
        upward = true,
        stop = "/home",
        type = "file"
    })[1]
}

Here I specify --lint-only option and look for a file in current or parent directories until /home. I have a basic verilator.f in my home with -Wall and --timing for small files without their own config. [1] is needed, because vim.fs.find() returns a list and we need the first element

goekce commented 1 month ago

This is a good workaround @max-kudinov, thanks.

Taking all the .sv or .v files in current directory could be better, however Verilator does not order the files during compilation — so even this could lead to some problems for linting.

I believe currently there is nothing that nvim-lint can do better without parsing the source files, so I'll close this issue.