mattn / efm-langserver

General purpose Language Server
MIT License
1.38k stars 62 forks source link

flake8 lintCategoryMap #166

Open horseinthesky opened 3 years ago

horseinthesky commented 3 years ago

Hello.

I cannot figure out how to setup categories for flake8 linter.

I have the following config:

M.flake8 = {
  lintCommand = "flake8 --ignore=E501,W503 --stdin-display-name ${INPUT} -",
  lintStdin = true,
  lintIgnoreExitCode = true,
  lintFormats = { "%f:%l:%c: %m" },
}

I've tried to add

  lintCategoryMap = {
    E = "E",
    F = "E",
    W = "W",
  },

block but whatever format I use it leads to Client 2 quit with exit code 2 and signal 0

And also if it is possible to print linter name in Neovim virtual text besides code and message?

image

mattn commented 3 years ago

Can you provide what error-line was outputted?

horseinthesky commented 3 years ago

@mattn Client 2 quit with exit code 2 and signal 0 is the only info i get.

Even if I put logging setting to the setup:

local languages = {
  python = { isort, flake8, black, mypy },
  lua = { stylua },
  yaml = { prettier },
  json = { prettier },
  html = { prettier },
  css = { prettier },
  markdown = { prettier },
}

lspconfig.efm.setup {
  filetypes = vim.tbl_keys(languages),
  init_options = {
    documentFormatting = true,
  },
  settings = {
    languages = languages,
    log_level = 1,
    log_file = vim.fn.expand("~/.config/efm-langserver/efm.log"),
  },
}

~/.config/efm-langserver dir is empty.

mattn commented 3 years ago

What do you get with

flake8 --ignore=E501,W503 --stdin-display-name your-source-code.js - < your-source-code.js
horseinthesky commented 3 years ago

What do you get with

flake8 --ignore=E501,W503 --stdin-display-name your-source-code.js - < your-source-code.js

As expected I get my error from screenshot

flake8 --ignore=E501,W503 --stdin-display-name mondata/juggler_cloud/bgp.py - < mondata/juggler_cloud/bgp.py

mondata/juggler_cloud/bgp.py:7:1: F401 'a_nasty_path_hack' imported but unused
atrautsch commented 3 years ago

I am not able to test this at the moment but I think you are missing category in the format string.

%f:%l:%c: %m would be file:line:col: message but you want category in there which needs to be a single character due to the use of errorformat which implements the quickfix format.

You could try %f:%l:%c: %t%n %m the %t consumes the first character of F401 from your example as category and %n consumes the number. Afterwards %m consumes the rest of the text as message.

horseinthesky commented 3 years ago

@atrautsch Thanks a lot.

%f:%l:%c: %m has this output image

%f:%l:%c: %t%n %m has this image

That is cool it uses category now but now it doesn't show the code (which was shown with the original format). Also is it possible to print linters name?

horseinthesky commented 3 years ago

I do not quite understand how this works but using different combinations from here breaks the diagnostics in most cases :P

%f:%l:%c: %m and %f:%l:%c: %t%n %m are basically speaking the only options which work.

atrautsch commented 3 years ago

The idea is that the line mondata/juggler_cloud/bgp.py:7:1: F401 'a_nasty_path_hack' imported but unused is completely consumed by the format string. %f consumes the path and filename, %l the line and so on. That is why no other format works and also why the code is not shown. Only the part that is consumed by %m is shown and the code is already consumed by %t and %c.

I am not sure if it is possible to show the code. It may require a change to efm-langserver which allows formatting the string returned to the LSP client so that it could include parts of the errorformat again.

The linters name should be possible with using lintSource or prefix in the configuration. lintStdin = true, prefix = "flake8", lintSource = "flake8"

horseinthesky commented 3 years ago

@atrautsch linkSource doesn't seem to have any effect. Also, it is not mentioned in the schema https://github.com/mattn/efm-langserver/blob/cf157c6d2c81c877426338b4ac1b109f5516ca5d/schema.json#L34-L129

prefix does work though. Thank you. image

Would be great to keep error code but if it is not possible at the moment I am ready to close the issue.

@mattn Do you have anything to add?

mattn commented 2 years ago

Still I don't understand what is wrong. Hmm.

horseinthesky commented 2 years ago

Just wondering if it is possible to set efm to show error codes like this image