Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commonly Asked Questions

Chris Kipp edited this page Apr 6, 2020 · 1 revision

My aim is for this space to be a place where common questions can be logged specifically related to coc-metals. If you're a vim user, you know that at times configurations may clash and small issues can drive one mad. Here is a list of things that I've come across that might save you a headache, give you an idea, or help you solve a problem you're experiencing.

How do I fix the odd highlighting in floating windows when using Neovim

Odd highlighting in floating windows

Thanks to the wisdom of @joshdick, here is an example of how to fix this. You'll need to change it a bit for your desired theme, but you can get an idea from this and read the context here.

" onedark.vim override: Don't set a background color when running in a terminal;
" just use the terminal's background color
if (has("autocmd") && !has("gui_running"))
  augroup colors
    autocmd!
    let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16": "7"}
    autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) "No `bg` setting
  augroup END
endif

If you can't figure out how to make it work and it's driving you mad, you can set the following setting in :CocConfig

  "coc.preferences.enableFloatHighlight": false

This setting will turn off all highlighting in your floating window which makes the odd highlighting no longer an issue. Still not ideal, but better for your sanity if you can't stand the odd highlighting.

I can't get the correct workspace set

Take a look at the Using workspaceFolders section of the coc.nvim wiki. It may be that you need to change the following configuration value. (Note that if you're using a recent version of coc-metals, this shouldn't be an issue as we set this for you.)

This is the default:

"coc.preferences.rootPatterns" settings, which default to [".vim", ".git", ".hg", ".projections.json"]

But you'll ideally want something like this:

"coc.preferences.rootPatterns" settings, which default to ["build.sbt", "build.sc", "pom.xml", "build.gradle", ".git"]

I don't like the way airline displays the coc status.

In the current coc integration of airline, the coc status is shown in the middle of your statusline, but it's bolded, and looks just like the display of your file name. I personally don't like this as I'd rather it be a bit more subtle, and blend better with the theme. Here is what the default looks like:

Default Statusline

However, I personally use the following to give me a more subtle status.

  function! CocMinimalStatus() abort
    return get(g:, 'coc_status', '')
  endfunction
  let g:airline_section_c = '%t %#LineNr#%{CocMinimalStatus()}'

This will result in the following:

Subtle Statusline

How do I get all the workspace diagnostics like <leader> a gives me instead of just the local buffer?

If you'd like a report of all the diagnostics that Metals is reporting, which is the same thing that <leader> a gives you, then you'll want to do something like the following. Feel free to improve this as it's probably not the best vimscript.

function! FullDiagnostics() abort
    let diagnostics = CocAction('diagnosticList')
    if type(diagnostics) == v:t_list
      let errors = []
      let warnings = []
      for diagnostic in diagnostics
        if diagnostic['severity'] == 'Error'
          call add(errors, diagnostic)
        endif
        if diagnostic['severity'] == 'Warning'
          call add(warnings, diagnostic)
        endif
      endfor
      return " E " . string(len(errors)) . " W " . string(len(warnings))
    endif
  endfunction

Then just add %{FullDiagnostics()} to your statusline.