diagnostic-nvim icon indicating copy to clipboard operation
diagnostic-nvim copied to clipboard

No Warnings

Open jacksonludwig opened this issue 5 years ago • 3 comments

Using nvim lsp + completion + diagnostics, things seem to work fine expect for warnings from diagnostics. For example, when using rust-analyzer and importing something I don't use, I get no warning. I can't seem to find the issue. I'm using ubuntu with most recent neovim nightly and plugins.

Lua settings:

local nvim_lsp = require('nvim_lsp')

function preview_location(location, context, before_context)
  -- location may be LocationLink or Location (more useful for the former)
  context = context or 10
  before_context = before_context or 5
  local uri = location.targetUri or location.uri
  if uri == nil then
    return
  end
  local bufnr = vim.uri_to_bufnr(uri)
  if not vim.api.nvim_buf_is_loaded(bufnr) then
    vim.fn.bufload(bufnr)
  end
  local range = location.targetRange or location.range
  local contents =
    vim.api.nvim_buf_get_lines(bufnr, range.start.line - before_context, range["end"].line + 1 + context, false)
  local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
  return vim.lsp.util.open_floating_preview(contents, filetype)
end

function preview_location_callback(_, method, result)
  local context = 10
  if result == nil or vim.tbl_isempty(result) then
    print("No location found: " .. method)
    return nil
  end
  if vim.tbl_islist(result) then
    floating_buf, floating_win = preview_location(result[1], context)
  else
    floating_buf, floating_win = preview_location(result, context)
  end
end

function peek_definition()
  if vim.tbl_contains(vim.api.nvim_list_wins(), floating_win) then
    vim.api.nvim_set_current_win(floating_win)
  else
    local params = vim.lsp.util.make_position_params()
    return vim.lsp.buf_request(0, "textDocument/definition", params, preview_location_callback)
  end
end

local on_attach = function(_, bufnr)
  vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
  require'diagnostic'.on_attach()
  require'completion'.on_attach()

  local opts = { noremap=true, silent=true }
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K',  '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.util.show_line_diagnostics()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'g0', '<cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gW', '<cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>de', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pd', '<cmd>lua peek_definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', ':PrevDiagnostic<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', ':NextDiagnostic<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '[D', ':PrevDiagnosticCycle<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', ']D', ':NextDiagnosticCycle<CR>', opts)
end

nvim_lsp.rust_analyzer.setup{ on_attach = on_attach }

Init vim settings:

call plug#begin('~/.config/nvim/plugged')
Plug 'mhinz/vim-startify'
Plug 'https://github.com/joshdick/onedark.vim.git'
Plug 'itchyny/lightline.vim'

Plug 'nvim-lua/completion-nvim'
Plug 'neovim/nvim-lsp'
Plug 'nvim-lua/diagnostic-nvim'
call plug#end()

" SWAP AND UNDOFILE SETUP
set noswapfile
set nobackup
set nowritebackup
set undodir=~/.config/nvim/undodir
set undofile

" CORE CHANGES
set hidden
set tabstop=8
set softtabstop=4
set shiftwidth=4
set expandtab
set nowrap
set number relativenumber
set autoindent
set termguicolors
set mouse=a

" Make sure clipboard works
set clipboard=unnamedplus

" Hide netrw banner
let g:netrw_banner=0

" REMAPPING
let mapleader = " "
nnoremap <leader>y "*y
vnoremap <leader>y "*y
nnoremap <leader>p "*p
vnoremap <leader>p "*p
nnoremap <leader>P "*P

" Remove highlight when esc is pressed
nmap <silent><ESC> :noh<CR>

" LSP CONFIG
lua require 'lsp'
set signcolumn=yes
set completeopt-=menu
set completeopt-=longest    " Don't insert the longest common text
set completeopt-=preview    " Hide the documentation preview window
set completeopt+=menuone    " Show the completions UI even with only 1 item
set completeopt+=noinsert   " Don't insert text automatically
set completeopt+=noselect   " Do not select a match in the menu

" Lightline config
let g:lightline = {
            \ 'colorscheme': 'onedark',
            \ 'active': {
            \   'left': [ [ 'mode', 'paste' ],
            \             [ 'readonly', 'filename', 'modified' ] ]
            \ },
            \ }

" Startify config
let g:startify_custom_header = [
\ '  __     ___            ',
\ '  \ \   / (_)_ __ ___   ',
\ '   \ \ / /| | ''_ ` _ \ ',
\ '    \ V / | | | | | | | ',
\ '     \_/  |_|_| |_| |_| ',
\ '',
\ '',
\ ]

" COLORS, SYNTAX, AND LATE CHANGES
"let g:onedark_terminal_italics=1
let g:onedark_hide_endofbuffer=1
colorscheme onedark

jacksonludwig avatar Jul 22 '20 01:07 jacksonludwig

Try disabling diagnostic-nvim and try again. If it remains the same, it's not an issue in here. Maybe the issue is with rust-analyzer.

haorenW1025 avatar Jul 22 '20 03:07 haorenW1025

Removing diagnostic-nvim from the on-attach did indeed allow visual text errors to appear, but not warnings. I know rust-analyzer supplies these features but maybe it's doing something weird.

jacksonludwig avatar Jul 22 '20 04:07 jacksonludwig

Is it only rust-analyzer? Can you try another LSP to see if it is still broken?

Iron-E avatar Jul 25 '20 21:07 Iron-E