scalameta / coc-metals

Deprecated in favor of scalameta/nvim-metals
http://scalameta.org/metals/
Apache License 2.0
167 stars 24 forks source link

Perpetually downloading scalafix #436

Closed agdt3 closed 2 years ago

agdt3 commented 2 years ago

Describe the bug

After indexing and compiling my scala 3 project in neovim, the command bar always says: [coc.nvim] Downloading scalafix⠇. The loading boxes do not move, the notification never goes away. metals doctor doesn't show any obvious issues. Its also worth noting that the build.sbt file does not have scalafix as a dependency, nor is there a .scalafix.conf file in the root.

To Reproduce

Steps to reproduce the behavior:

For me, its just opening any scala file in neovim v0.5.1 with coc.nvim and coc-metals installed as per the guide.

Expected behavior

Scalafix is presumably required by metals, so it should finish installing eventually.

Screenshots

Screen Shot 2021-10-26 at 9 04 56 AM

Installation:

Additional context

Search terms

scalafix, neovim

ckipp01 commented 2 years ago

Thanks for the report @agdt3. I want to guess that if everything else is working as expected Scalafix has downloaded fine, but there might just be an issue with clearing the message. In a file can you test the organize imports command to see if it works?

Also do you have metals.statusBarEnabled?

agdt3 commented 2 years ago

Running :CocCommand editor.action.organizeImport does in fact re-organize my imports. So I guess its correct to say that Scalafix is installed, but just hasn't cleared the message. This is without metals.statusBarEnabled.

For reference, with metals.statusBarEnabled, the status bar just says Metals after a while (no reference to Scalafix).

Screen Shot 2021-10-27 at 7 45 14 AM

With airline:

Screen Shot 2021-10-27 at 7 41 11 AM

At this point it seems to be stuck compiling forever, evidenced by the fact that I can't seem to access the treeview.

agdt3 commented 2 years ago

On an somewhat related question (to my install of metals), how do I debug hover functionality? It doesn't appear to be working for me and I'm not exactly sure if there's something I need to do to toggle it in neovim/iterm2. Is it even supported?

ckipp01 commented 2 years ago

For reference, with metals.statusBarEnabled, the status bar just says Metals after a while (no reference to Scalafix).

Ok, this is expected. If there are no new statuses after it's cleared it will just say "Metals" to let you know that it's attatched. I'd highly highly recommend using coc-metals with statusBarEnabled. Without it I've found the messages to be spotty, they don't always clear like you're seeing etc. Everything is better with using status. So it shouldn't be "compiling forever", but rather done. Is everything else working at that point?

On an somewhat related question (to my install of metals), how do I debug hover functionality? It doesn't appear to be working for me and I'm not exactly sure if there's something I need to do to toggle it in neovim/iterm2. Is it even supported?

What does your mapping for hover look like?

agdt3 commented 2 years ago

Thanks for the tip about statusBarEnabled!

For hover, I have set up the normal command nmap <Leader>ws <Plug>(coc-metals-expand-decoration) and also tested it with nmap <space>w <Plug>(coc-metals-expand-decoration). Neither seem to do anything.

My config file is (but I've tried a more minimal version too):

{
  "coc.preferences.formatOnSaveFiletypes": ["scala"],
  "metals.statusBarEnabled": true,
  "metals.superMethodLensesEnabled": true,
  "metals.showInferredType": true,
  "metals.showImplicitArguments": true,
  "codeLens.enable": true
}

I think however that there might be something wrong with my install. When I try to open the tree view protocol on a completely new project (created with sbt new scala/scala3.g8), I end up with this (both root and root-test are empty):

Screen Shot 2021-10-28 at 8 35 34 AM

My full nvim init.vim config for reference (mostly taken from metals and coc-metals):

call plug#begin('~/.local/share/nvim/plugged')

Plug 'neoclide/coc.nvim', {'branch': 'release'}

Plug 'vim-airline/vim-airline'
" theme
Plug 'marko-cerovac/material.nvim'

call plug#end()

set tabstop=2               " number of columns occupied by a tab
set softtabstop=2           " see multiple spaces as tabstops so <BS> does the right thing
set expandtab               " converts tabs to white space
set shiftwidth=2            " width for autoindents
set autoindent              " indent a new line the same amount as the line just typed
set number                  " add line numbers

set colorcolumn=79          " set an 80 column border for good coding style

" theme
colorscheme material
let g:material_style = 'oceanic'

" Remap jj to Esc
imap jj <Esc>

" Disable Arrow keys in Escape mode
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>

" Disable Arrow keys in Insert mode
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>

" Scala
" Help Vim recognize *.sbt and *.sc as Scala files
au BufRead,BufNewFile *.sbt,*.sc set filetype=scala

" Used to expand decorations in worksheets
nmap <Leader>ws <Plug>(coc-metals-expand-decoration)
nmap <space>w <Plug>(coc-metals-expand-decoration)

" Toggle panel with Tree Views
nnoremap <silent> <space>t :<C-u>CocCommand metals.tvp<CR>
" Toggle Tree View 'metalsPackages'
nnoremap <silent> <space>tp :<C-u>CocCommand metals.tvp metalsPackages<CR>
" Toggle Tree View 'metalsCompile'
nnoremap <silent> <space>tc :<C-u>CocCommand metals.tvp metalsCompile<CR>
" Toggle Tree View 'metalsBuild'
nnoremap <silent> <space>tb :<C-u>CocCommand metals.tvp metalsBuild<CR>
" Reveal current current class (trait or object) in Tree View 'metalsPackages'
nnoremap <silent> <space>tf :<C-u>CocCommand metals.revealInTreeView metalsPackages<CR>

" TextEdit might fail if hidden is not set.
set hidden

" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup

" Give more space for displaying messages.
set cmdheight=2

" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300

" Don't pass messages to |ins-completion-menu|.
set shortmess+=c

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")
  " Recently vim can merge signcolumn and number column into one
  set signcolumn=number
else
  set signcolumn=yes
endif

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  elseif (coc#rpc#ready())
    call CocActionAsync('doHover')
  else
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code.
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s).
  autocmd FileType 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)

" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac  <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf  <Plug>(coc-fix-current)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
  nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif

" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')

" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>
ckipp01 commented 2 years ago

For hover, I have set up the normal command nmap ws (coc-metals-expand-decoration) and also tested it with nmap w (coc-metals-expand-decoration). Neither seem to do anything.

That mapping is only to expand the metals decorations found in worksheets. The generic hover you want to use is this one:

https://github.com/scalameta/coc-metals/blob/56b67aa5dd80b357041b8f157cdaba4213d4e78b/coc-mappings.vim#L76

I think however that there might be something wrong with my install. When I try to open the tree view protocol on a completely new project (created with sbt new scala/scala3.g8), I end up with this (both root and root-test are empty):

Actually atm, this is expected. The Tree View Protocol isn't yet supported in Scala 3

agdt3 commented 2 years ago

Ah, K does work to display hover test and TVP isn't supposed to work. Thank you for clearing that up!