Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake8 lintCategoryMap #166

Open
horseinthesky opened this issue Sep 9, 2021 · 11 comments
Open

flake8 lintCategoryMap #166

horseinthesky opened this issue Sep 9, 2021 · 11 comments

Comments

@horseinthesky
Copy link

horseinthesky commented Sep 9, 2021

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
Copy link
Owner

mattn commented Sep 9, 2021

Can you provide what error-line was outputted?

@horseinthesky
Copy link
Author

horseinthesky commented Sep 9, 2021

@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
Copy link
Owner

mattn commented Sep 9, 2021

What do you get with

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

@horseinthesky
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

horseinthesky commented Sep 14, 2021

@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
Copy link
Author

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
Copy link
Contributor

atrautsch commented Sep 15, 2021

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
Copy link
Author

@atrautsch
linkSource doesn't seem to have any effect. Also, it is not mentioned in the schema

efm-langserver/schema.json

Lines 34 to 129 in cf157c6

"tool-definition": {
"additionalProperties": false,
"description": "definition of the tool",
"properties": {
"prefix": {
"description": "prefix string to be able to see where an error comming from",
"type": "string"
},
"format-command": {
"description": "format command",
"type": "string"
},
"format-stdin": {
"description": "use stdin for the format",
"type": "boolean"
},
"hover-command": {
"description": "hover command",
"type": "string"
},
"hover-stdin": {
"description": "use stdin for the hover",
"type": "boolean"
},
"hover-type": {
"description": "hover result type",
"type": "string",
"enum": [
"markdown",
"plaintext"
]
},
"env": {
"description": "command environment variables and values",
"items": {
"type": "string",
"pattern": "^.+=.+$"
},
"type": "array"
},
"lint-command": {
"description": "lint command",
"type": "string"
},
"lint-offset-columns": {
"description": "offset value to skip columns",
"type": "number"
},
"lint-category-map": {
"description": "Map linter categories to LSP categories",
"type": "object"
},
"lint-formats": {
"description": "list of lint format",
"items": {
"type": "string"
},
"type": "array"
},
"lint-ignore-exit-code": {
"default": true,
"description": "ignore exit code of lint",
"type": "boolean"
},
"lint-offset": {
"description": "offset value to skip lines",
"type": "number"
},
"lint-stdin": {
"default": true,
"description": "use stdin for the lint",
"type": "boolean"
},
"completion-command": {
"description": "completion command",
"type": "string"
},
"completion-stdin": {
"default": true,
"description": "use stdin for the completion",
"type": "boolean"
},
"root-markers": {
"description": "markers to find root directory",
"items": {
"type": "string"
},
"type": "array"
},
"commands": {
"$ref": "#/definitions/command-definition"
}
},
"type": "object"
}
},

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
Copy link
Owner

mattn commented Nov 21, 2021

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

@horseinthesky
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants