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

Feature needed : How to add a linter for fortran? #568

Open vickysharma0812 opened 2 months ago

vickysharma0812 commented 2 months ago

I would like to add a linter for Fortran by using gfortran compiler. However, I am not sure how to do it. The linter setting used in vscode is given here: https://github.com/fortran-lang/vscode-fortran-support/blob/main/src/lint/compilers.ts

I need help in parsing.

My settings in neovim is given below:

  {
    "mfussenegger/nvim-lint",
    config = function()
      vim.notify("Loading fortran linting", 3, { title = "LazyVim" })
      local lint = require("lint")

      local pattern = [[^([^:]+):(%d+):(%d+):%s+([^:]+):%s+(.*)$]]
      local groups = { "file", "lnum", "col", "code", "severity", "message" }
      local severity_map = {
        ["error"] = vim.diagnostic.severity.ERROR,
        ["warning"] = vim.diagnostic.severity.WARN,
        ["performance"] = vim.diagnostic.severity.WARN,
        ["style"] = vim.diagnostic.severity.INFO,
        ["information"] = vim.diagnostic.severity.INFO,
      }
      local defaults = { ["source"] = "fortran" }
      lint.linters.gfortran = {
        name = "gfortran",
        cmd = "gfortran",
        args = {
          "-c",
          "-Wunused-variable",
          "-Wunused-dummy-argument",
          "-Wall",
          "-I",
          os.getenv("HOME") .. "/.easifem/install/easifem/extpkgs/include/",
          os.getenv("HOME") .. "/.easifem/install/easifem/extpkgs/include/toml-f/modules/",
          os.getenv("HOME") .. "/.easifem/install/easifem/base/include/",
          os.getenv("HOME") .. "/.easifem/install/easifem/classes/include/",
          os.getenv("HOME") .. "/.easifem/ide/include/",
          "-J",
          os.getenv("HOME") .. "/.easifem/ide/include/",
        }, -- args to pass to the linter
        ignore_exitcode = false, -- set this to true if you don't want to show error messages
        stream = "both", -- set this to "stdout" if the output is not an error, for example with luac
        parser = require("lint.parser").from_pattern(pattern, groups, severity_map, defaults),
      }

      lint.linters_by_ft = { fortran = { "gfortran" } }
    end,
  },
HeathenHeart commented 2 weeks ago

Did you manage to make it work? I'm also interested in enabling a linter for Fortran as well.

lsnow commented 6 days ago

change ignore_exitcode = false to ignore_exitcode = true

add args:

-fsyntax-only -cpp -fdiagnostics-plain-output

and change

local groups = { "file", "lnum", "col", "code", "severity", "message" }

to

local groups = { "file", "lnum", "col", "severity", "message" }

I modified it base on my gcc config, and i have not tested it