Skip to content

[feature request]: format selected range with diagnostic-languageserver #57

@hereGittyGitty

Description

@hereGittyGitty

Hi iamcoo,

thx a lot for 'diagnostic-languageserver'. I am trying to format visually selected python code with black or autopep8. Whenever I try to trigger the formatting with the mapping

vmap <leader>p  <Plug>(coc-format-selected)
nmap <leader>p  <Plug>(coc-format-selected)

I get the following error:

Notification error: formatSelected [ 'V' ] Error: formatRange provider not found for current buffer, your language server doesn't support it.

Formatting the whole file with the command

command! -nargs=0 Format :call CocAction('format')

works without a problem.

I did not find any related issues neither here on this site nor by using Google. Therefore I guess it must be a problem that might be only affecting me?

Here is the diagnostic-languageserver part of my coc-settings.json file that looks as unspectacular as my formatting mappings above:

{
  "languageserver": {
    "dls": {
      "command": "diagnostic-languageserver",
      "args": ["--stdio"],
      "filetypes": ["python"],
      "trace.server": "verbose",
      "initializationOptions": {
        "linters": {
          "pylint": {
            "sourceName": "pylint",
            "command": "pylint",
            "args": [
              "--output-format",
              "text",
              "--score",
              "no",
              "--msg-template",
              "'{line}:{column}:{category}:{msg} ({msg_id}:{symbol})'",
              "%file"
            ],
            "formatPattern": [
              "^(\\d+?):(\\d+?):([a-z]+?):(.*)$",
              {
                "line": 1,
                "column": 2,
                "security": 3,
                "message": 4
              }
            ],
            "rootPatterns": [".vim", ".git", "pyproject.toml", "setup.py"],
            "securities": {
              "informational": "hint",
              "refactor": "info",
              "convention": "info",
              "warning": "warning",
              "error": "error",
              "fatal": "error"
            },
            "offsetColumn": 1,
            "formatLines": 1
          }
        },
        "formatters": {
          "autopep8": {
            "command": "autopep8",
            "args": ["-"]
          },
          "black": {
            "command": "black",
            "args": ["--quiet", "-"]
          },
          "isort": {
            "command": "isort",
            "args": ["--quiet", "-"]
          }
        },
        "filetypes": {
          "python": "pylint"
        },
        "formatFiletypes": {
          "python": ["autopep8", "isort"]
        }
      }
    }
  }
}

Thank you very much for any help. If you need any more input just ask.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions