0

Getting this error message when running the shortcut:

[coc.nvim]: Error on "formatSelected": formatRange provider not found for current buffer, your language server doesn't support it.

Using golang, here's the CocConfig (omitting irrelevant info):

{
  "languageserver": {
    "golang": {
      "command": "gopls",
      "rootPatterns": [
        "go.mod"
      ],
      "trace.server": "verbose",
      "filetypes": [
        "go"
      ],
      "initializationOptions": {
        "formatTool": "goimports"
      }
    }
  }
}

Probably relevant config sections:

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s).
  autocmd FileType go,typescript,json setl formatexpr=CocAction('formatSelected')
  " Update signature help on jump placeholder.
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

using

❯ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 01 2022 09:16:32)
Included patches: 1-2269, 3612, 3625, 3669, 3741
3
  • 1
    Are you sure the formatter supports the formatting of a section of the code? Mar 16, 2022 at 19:05
  • boooah, mind blown. I don't know! And probably not! goimports resp. gofmt are usually applied to whole files... Mar 16, 2022 at 19:29
  • 1
    I'm using the :Format command to reformat the entire file Mar 16, 2022 at 21:00

0

This site is temporarily in read-only mode and not accepting new answers.

Browse other questions tagged .